1

I'm building a CMS and the content of a post is saved in HTML in the database.

On the page that lists posts, I would like to show the first n words / n characters, for the short version of the post with a "read more" button.

What would be the best way to strip the text from the HTML the right way, without making it look al weird?

CherryNerd
  • 1,258
  • 1
  • 16
  • 38
  • Take a look at http://stackoverflow.com/questions/787932/using-c-sharp-regular-expressions-to-remove-html-tags – Bindrid Dec 15 '16 at 21:18
  • read the html as a string, parse to AST, walk through tree and reduce all text nodes. https://github.com/fb55/htmlparser2 – Daniel Lizik Dec 15 '16 at 21:24

1 Answers1

3

you can try use the library html-to-text (npm install html-to-text). Split all text and show the n array elements.