Skip to content
Advertisement

Python difflib: highlighting differences inline?

When comparing similar lines, I want to highlight the differences on the same line:

JavaScript

While difflib.HtmlDiff appears to do this sort of inline highlighting, it produces very verbose markup.

Unfortunately, I have not been able to find another class/method which does not operate on a line-by-line basis.

Am I missing anything? Any pointers would be appreciated!

Advertisement

Answer

For your simple example:

JavaScript

This works with strings. You should decide what to do with “replace” opcodes.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement