Is there a version of Text::Diff::HTML that actually works?

Text::Diff often goes into a busy-loop when diffing files that have only a few lines of changes. How's that even possible? Why, it's because instead of running and parsing diff, they reimplemented diff themselves in Perl. Because reasons. Seriously, look at Algorithm::Diff -- it reads like it was literally someone's homework assignment.

I just want to take two text files and get side-by-side HTML/colored output of the differences. Is there something simple that works, or do I have Two Problems?


Update: Because you have all failed me, I wrote this.

Tags: ,

15 Responses:

  1. David M.A. says:

    We had this same problem at work, although we were even worse in that we were looking for a decent PHP version. (Pause for mocking laughter.) As far as I can tell, it's the hardest problem in computer science, and most implementations are garbage.

  2. Michael says:

    In my usage, Text::Diff had terribly bad performance for long lines - anything more than about 200 characters in a line and it took forever. If you can break up long lines of HTML, maybe at tag boundaries, things might improve.

    • jwz says:

      The case I'm seeing it fail on is a large text file with short lines and few differences -- and it doesn't fail on this file all the time, only with some particular sets of differences. So basically it just sucks.

  3. Raleigh says:

    Beyond Compare. Amazingly useful as a standard user program, but also has good command-line scriptability that can produce an HTML difference report.

    • Buddy Casino says:

      Had a similar issue a while ago, couldn't find anything free that could do this so I used a trial version of Beyond Compare. Its good.

    • Manuel says:

      +1 for Beyond Compare.
      Just not sure it fits Jamies problem description.

  4. Pronoiac says:

    wdiff can definitely do colors in the terminal, and I think Mediawiki (optionally) uses this for html diffs, but I can't confirm that.

  5. James says:

    Use Bram Cohen's Patience Diff because it will not drive you insane for the reasons indicated. I don't think it's available in native Perl, but you can get it from git diff --patience --no-index path1 path2

  6. Cheng says:

    I'm using diff_match_patch. Not a perfect fit but works okay.

  7. I use Beyond Compare to compare text files. It works rather well. See http://www.scootersoftware.com/

  8. Matěj Cepl says:

    What's wrong with

    diff -y file_before file_after \
    | pygmentize -l diff -f html -O full -o file_diff.html

    (nice discussion of the issue on http://stackoverflow.com/questions/641055/)