简体   繁体   中英

Extract text from HTML String Node.js

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM