Go Back

Convert HTML text to plain text node Js

9/3/2022
All Articles

HTML text to plain text #node js #question

Convert HTML text to plain text node Js

Convert Html into plan text using node js

There is serveral method to convert HTML into plan text here we can use replace function of node js. This function took two parameters in argument. 
First argument is source value of string. 
Second value is destination value or new value. 

 

var myHTML= "<div><h1>Shubham mishra</h1>\n<p>That's what she said regarding</p></div>";

var strippedHtml = myHTML.replace(/<[^>]+>/g, '');

// Jimbo.

// That's what she said

console.log(stripedHtml);

 

Conclusion

This is simple way to convert html to plan text. Hope you understand the concept of replace function.Some time we need to used a text inside html code for example in JSON LD is schema base xml and to fill attribute in schema we need text data from HTML.
We have many use case for that  and  if you  have any good implementation then share to us .
For any suggestions please feel free to contact

Article