How to highlight more than two characters per line in difflibs html output

孤街醉人 提交于 2019-12-03 20:52:07

difflib's algorithm does not claim to yield minimal edit sequences. Although that statement comes from the docs for SequenceMatcher, I suspect it applies to difflib in general, and HTMLDiff in particular.

While googling around for "python alternative difflib minimal edit" I found google-diff-match-patch. If you try out their demo for Diff with your example strings, it yields

Although the output is not exactly what you requested, it does show that it found the minimal edits.

The API docs state

diff_prettyHtml(diffs) => html

Takes a diff array and returns a pretty HTML sequence. This function is mainly intended as an example from which to write ones own display functions.

which suggests looking at the source code for diff_prettyHtml might be a good starting point from which to build the HTML table you are looking for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!