有没有可以在 HTML 文档之间进行比较的 ruby gem?
事实证明,对两个不同的 html 文档进行比较是一个完全不同的问题,而不仅仅是对纯文本进行比较。例如,如果我在以下之间进行幼稚的 LCS diff:
Google</p>
并且
Google</a></p>
diff 结果不是:
</a>
但
/a></
我已经尝试了大多数声称是 html diff 的 gem,但所有这些似乎都只是实现基于文本的 LCS diff。是否有任何 gem 可以在考虑 html 标签的同时进行比较?
Doing a diff of two different html documents turns out to be an entirely different problem than simply doing a diff of plain text. For example, if I do a naive LCS diff between:
Google</p>
and
Google</a></p>
the diff result is NOT:
</a>
but
/a></
I've tried most gems out there that claim to be html diff but all of them seem to be just implementing text based LCS diff. Is there any gem that does a diff while taking html tags into account?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 Samy diffy 或 rubygems html-diff
Try Samy diffy or rubygems html-diff
经过大量搜索 gem 来为我执行此操作后,我发现我可以简单地在两个已解析的 Nokogiri 文档之间进行字符串比较:
然后您可以简单地将其添加到您的规范中:
最好的部分是内置的 rspec 匹配器将自动为您提供不匹配行的逐行比较结果。
After much searching for a gem to do this for me, I discovered that I can simply do a string compare between two parsed Nokogiri documents:
Then you can simply add this in your spec:
The best part is that the built-in rspec matcher will automatically provide you a line-by-line diff result of the mismatched lines.