diff_match_patch:生成并排视图
我在 Java 中使用 google-diff-match-patch应用程序来创建差异。我使用 diff_prettyHtml 方法来生成 diff 的 HTML 输出。
但是,我希望有两个不同的输出,因此我可以将它们并排放置,以使用户更容易看到差异。 (例如,像 Eclipse 那样。)
该库中有什么可以用来实现此目的吗? 你会怎么做? (如果可能的话,我不会使用不同的库。)
I'm using google-diff-match-patch with my Java app to create a diff. I use the method diff_prettyHtml for generating HTML output of the diff.
However, I would like to have two different outputs, so I can put them side-by-side to make it a bit more easy for the user to see the differences. (For example, like Eclipse does.)
Is there anything in that library I can use to achieve this? How would you do that? (I would not use a different library, if possible.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您不尝试比较 HTML,在这种情况下我建议使用 DaisyDiff,您可能想要对 diff-match-patch 执行的操作是行差异,在项目 wiki 页面上进行了描述。基本上,它涉及生成一个哈希码数组,左右各行一个,并跟踪与映射中的行相关的这些哈希码,然后通过比较算法运行这些数组。然后,您可以将 diff 输出与贴图结合使用,以适当地补充左右突出显示。
Assuming you're not attempting to diff HTML, in which case I'd suggest using DaisyDiff, what you probably want to do with diff-match-patch is line differencing, which is described on a project wiki page. Basically it involves generating an array of hash codes, one for each line of the left and right, and keeping track of those hash codes relative to the lines in a map, and then running those arrays through the diffing algorithm. Then you use the diff output in conjunction with the map to rehydrate left and right highlighting as appropriate.
我尝试在Python中实现不同的方法:
http ://code.activestate.com/recipes/577784-line-based-side-by-side-diff/
欢迎失败的测试用例。
I have tried to implement a different approach in Python:
http://code.activestate.com/recipes/577784-line-based-side-by-side-diff/
Failing test cases are welcome.