I'm taking html content out of my database and displaying it on a page.
Unfortunately these pages often have unclosed html tags and cause problems later when the page is rendered.
I was wondering if there is a JavaScript implementation of something like tidy or htmlpurifier.
Basically some software which can preferably close html tags in a string.
Edit: I'm not in a browser environment (node.js)
I'm taking html content out of my database and displaying it on a page.
Unfortunately these pages often have unclosed html tags and cause problems later when the page is rendered.
I was wondering if there is a JavaScript implementation of something like tidy or htmlpurifier.
Basically some software which can preferably close html tags in a string.
Edit: I'm not in a browser environment (node.js)
Share Improve this question asked Jan 19, 2012 at 21:18 AaronAaron 1,58311 silver badges10 bronze badges3 Answers
Reset to default 4As you tagged your question with node.js:
npm install tidy
Something like this could work:
function tidy(htmldata) {
var d = document.createElement('div');
d.innerHTML = htmldata;
return d.innerHTML;
}
http://code.google./p/google-caja/wiki/JsHtmlSanitizer balances tags.