How to use 'html to text javascript' in JavaScript

Every line of 'html to text javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
159function html2js(text){
160 var split1 = text.split("\n");
161 text = "var text = \"\";\n";
162 for(var i=0;i<split1.length;i++) {
163 var str = split1[i];
164 text += "text += \""+str.replace(/"/g,"\\\"")+"\";\n";
165 }
166 return text;
167}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

19function text2html(text) {
20 return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>');
21}

Related snippets