diff_match_patch:生成并排视图

发布于 2024-11-12 06:05:18 字数 304 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舞袖。长 2024-11-19 06:05:18

假设您不尝试比较 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.

冷默言语 2024-11-19 06:05:18

我尝试在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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文