添加 的简单内联 diff 算法<删除>与 PHP 和 HTML 一起使用的标签?

发布于 2024-11-13 01:44:12 字数 332 浏览 1 评论 0原文

我之前尝试过 Paul 的简单 Diff 算法,但效果非常糟糕。它甚至无法显示在字符串末尾仅添加了几个字符,而没有标记据称该字符串的某些内容已被删除。

我需要这样的东西:

string end
begin strngs
<ins>begin </ins>str<del>i</del>ng<ins>s</ins><del> end</del>

I've tried Paul's Simple Diff Algorithm before but it works terribly. It even can't show that only few characters were added at the end of the string without marking that allegedly some of this string was deleted.

I need something like this:

string end
begin strngs
<ins>begin </ins>str<del>i</del>ng<ins>s</ins><del> end</del>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

演多会厌 2024-11-20 01:44:12

我认为一个好的 diff 算法很大程度上基于启发式方法。这取决于您有什么样的变化以及您希望如何表示它们。

例如:

The cat jumped over the fence
The panther jumped over the fence

您可以将其 diff 为:

The <del>c</del><ins>p</ins>a<ins>n</ins>t<ins>her</ins> jumped over the fence

或:

The <del>cat</del><ins>panther</ins> jumped over the fence

两者都是准确的(忽略我的任何错误)。

I would argue that a good diff algorithm is largely based on heuristics. It depends on what kind of changes you have and how you would like to represent them.

For instance:

The cat jumped over the fence
The panther jumped over the fence

You could diff as:

The <del>c</del><ins>p</ins>a<ins>n</ins>t<ins>her</ins> jumped over the fence

or:

The <del>cat</del><ins>panther</ins> jumped over the fence

Both are accurate (omiting any mistakes on my part).

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