使用 JavaScript 整洁的 HTML 输出
我有一大块 HTML。为了使其适合特定容器,我将 HTML(不仅仅是文本)裁剪为 200 个字符。显然,在这种情况下,某些标签将保持未关闭状态。除了自己编写清理器之外,有没有办法在不涉及服务器的情况下清理此类裁剪后的代码片段?
我可以通过 JavaScript 使用带有公共 API 的在线服务。
I have a large chunk of HTML. In order for it to fit a certain container, I crop the HTML (not just the text) at, let’s say, 200 characters. Obviously, some of the tags will remain unclosed in this case. Is there a way, except writing the cleaner myself, to clean such cropped snippet without the server being involved?
Online services with public APIs that I can use from JavaScript are acceptable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试 cutter.js 库。它很新,所以我没有听说过太多,但就裁剪而言,它似乎是您正在寻找的东西。
看看我的小提琴,测试一下: http://jsfiddle.net/JKirchartz/jwL8v/
You can try the cutter.js library. It's pretty new, so I haven't heard much about it, but it seems like what you're looking for as far as cropping goes.
Check out my fiddle, testing it out: http://jsfiddle.net/JKirchartz/jwL8v/
Google Closure 库有一个 HTML Pretty Printer 模块。您应该能够分叉它:
Closure Library
另外,如果您使用 jQuery,请尝试 http://www.davidpirek.com/blog/html-beautifier-jquery-plugin。
The Google Closure library has an HTML Pretty Printer module. You should be able to fork off it:
Closure Library
Also, if you are using jQuery, try http://www.davidpirek.com/blog/html-beautifier-jquery-plugin.