admin管理员组文章数量:1332352
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.
本文标签: How to close html tags in JavaScriptStack Overflow
版权声明:本文标题:How to close html tags in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742321936a2452963.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论