如何确定我的html文档是否在ruby中形成

时间:2022-10-31 17:56:40

Every html document is an xml document. In the current project there are a lot of html tags which are not properly closed. This is a ruby on rails application. I want to put an after filter which will parse the whole html output and will raise an error if the parsing detects that it is not a well-formed document.

每个html文档都是一个xml文档。在当前项目中,有许多html标签未正确关闭。这是一个ruby on rails应用程序。我想设置一个后置过滤器来解析整个html输出,如果解析检测到它不是一个格式正确的文档,则会引发错误。

In this case well-formed means that all the tags are properly closed. What is a good ruby parser to use in this case which is also fast.

在这种情况下,格式良好意味着所有标签都已正确关闭。在这种情况下使用什么是好的ruby解析器也很快。

3 个解决方案

#1


HTMLTidy seems to be the most popular plugin for other languages, and there is a RoR version available too.

HTMLTidy似乎是其他语言最受欢迎的插件,也有一个RoR版本。

http://blog.cosinux.org/pages/rails-tidy

#2


markup_validity provides some (X)HTML validation features. You can also use nokogiri as described here.

markup_validity提供了一些(X)HTML验证功能。您也可以使用此处所述的nokogiri。

#3


Why would you close your tags? It's only going to slow you down!

你为什么要关闭你的标签?这只会减慢你的速度!

http://blog.errorhelp.com/2009/06/27/the-highest-traffic-site-in-the-world-doesnt-close-its-html-tags/

#1


HTMLTidy seems to be the most popular plugin for other languages, and there is a RoR version available too.

HTMLTidy似乎是其他语言最受欢迎的插件,也有一个RoR版本。

http://blog.cosinux.org/pages/rails-tidy

#2


markup_validity provides some (X)HTML validation features. You can also use nokogiri as described here.

markup_validity提供了一些(X)HTML验证功能。您也可以使用此处所述的nokogiri。

#3


Why would you close your tags? It's only going to slow you down!

你为什么要关闭你的标签?这只会减慢你的速度!

http://blog.errorhelp.com/2009/06/27/the-highest-traffic-site-in-the-world-doesnt-close-its-html-tags/