@@ -12,6 +12,7 @@ import React from 'react';
12
12
import { themr } from 'react-css-super-themr' ;
13
13
import { config } from 'topcoder-react-utils' ;
14
14
import markdown from 'utils/markdown' ;
15
+ import ReactDOMServer from 'react-dom/server' ;
15
16
// SVG assets
16
17
import ThumbUpIcon from 'assets/images/ico-thumb-up.svg' ;
17
18
import CommentIcon from 'assets/images/ico-comment.svg' ;
@@ -21,17 +22,18 @@ import PlayIcon from 'assets/images/ico-play.svg';
21
22
import ReadMoreArrow from 'assets/images/read-more-arrow.svg' ;
22
23
import qs from 'qs' ;
23
24
25
+ const htmlToText = require ( 'html-to-text' ) ;
26
+
24
27
// date/time format to use for the creation date
25
28
const FORMAT = 'MMM DD, YYYY' ;
26
29
// date/time format for 'Forum post' cards is different from others
27
30
const FORUM_POST_FORMAT = 'MMM DD, YYYY [at] h:mm A' ;
28
31
// max length for the title of the 'Article small' cards
29
32
const ART_SMALL_TITLE_MAX_LENGTH = 29 ;
30
- // character length for the content preview
31
- const CONTENT_PREVIEW_LENGTH = 110 ;
32
33
// Article large card 'breakpoint'
33
34
const ARTICLE_LARGE_BREAKPOINT = 473 ;
34
-
35
+ // character length for the content preview
36
+ const CONTENT_PREVIEW_LENGTH = 110 ;
35
37
36
38
class ArticleCard extends React . Component {
37
39
constructor ( props ) {
@@ -132,10 +134,16 @@ class ArticleCard extends React.Component {
132
134
: article . title ;
133
135
134
136
// truncate content for 'Article large' cards
135
- const content = (
136
- ( themeName === 'Article large' || themeName === 'Recommended' )
137
- && article . content . length > CONTENT_PREVIEW_LENGTH )
138
- ? markdown ( `${ article . content . substring ( 0 , CONTENT_PREVIEW_LENGTH ) } ...` )
137
+ const content = themeName === 'Article large' || themeName === 'Recommended'
138
+ ? `${ htmlToText . fromString (
139
+ ReactDOMServer . renderToString ( markdown ( article . content ) ) ,
140
+ {
141
+ ignoreHref : true ,
142
+ ignoreImage : true ,
143
+ singleNewLineParagraphs : true ,
144
+ uppercaseHeadings : false ,
145
+ } ,
146
+ ) . substring ( 0 , CONTENT_PREVIEW_LENGTH ) } ...`
139
147
: undefined ;
140
148
141
149
// set the correct format to apply to the `article.creationDate`
0 commit comments