Is there an easy way to take a string of html in JavaScript and strip out the html?
If you want to keep the links and the structure of the content (h1, h2, etc) then you should check out TextVersionJS You can use it with any HTML, although it was created to convert an HTML email to plain text.
The usage is very simple. For example in node.js:
var createTextVersion = require("textversionjs");
var yourHtml = "Your HTML
- goes
- here.
";
var textVersion = createTextVersion(yourHtml);
Or in the browser with pure js:
It also works with require.js:
define(["textversionjs"], function(createTextVersion) {
var yourHtml = "Your HTML
- goes
- here.
";
var textVersion = createTextVersion(yourHtml);
});