Ruby 1.9 中的 HTML 整理/清理
我目前正在使用 RubyTidy Ruby 绑定来进行 HTML 整洁,以确保我收到的 HTML 格式良好。目前,这个库是唯一阻碍我在 Ruby 1.9 上获取 Rails 应用程序的因素。是否有其他库可以整理 Ruby 1.9 上的 HTML 块?
I'm currently using the RubyTidy Ruby bindings for HTML tidy to make sure HTML I receive is well-formed. Currently this library is the only thing holding me back from getting a Rails application on Ruby 1.9. Are there any alternative libraries out there that will tidy up chunks of HTML on Ruby 1.9?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://github.com/libc/tidy_ffi/blob/master/README.rdoc 适用于 ruby 1.9(最新版本)
如果您在 Windows 上工作,则需要设置library_path 例如
(它使用与 tidy 相同的 dll) 上面的链接为您提供了更多用法示例。
http://github.com/libc/tidy_ffi/blob/master/README.rdoc works with ruby 1.9 (latest version)
If you are working on windows, you need to set the library_path eg
(It uses the same dll as tidy) The above links gives you more example of the usage.
我正在使用 Nokogiri 来修复无效的 html:
I am using Nokogiri to fix invalid html:
下面是一个很好的例子,说明如何使用 tidy 让你的 html 看起来更好:
有关更多 tidy 选项,请查看 手册页。
Here is a nice example of how to make your html look better using tidy:
For more tidy options, check out the man page.
请注意,Ruby Tidy 绑定存在一些严重的内存泄漏问题。目前它在长时间运行的进程中不可用。 (郑重声明,我正在使用 http://github.com/ak47/tidy
)只需将其从生产 Rails 2.3 应用程序中删除,因为它的泄漏速度约为 1MB/分钟。
Watch out, the Ruby Tidy bindings have some nasty memory leaks. It's currently unusable in long running processes. (for the record, I'm using http://github.com/ak47/tidy)
I just had to remove it from a production Rails 2.3 application because it was leaking about 1MB/min.