Create a side-by-side HTML word diff between two Git revisions (generated with gpt-6-luna)
A developer published a Python script that generates a side-by-side HTML word diff between two Git revisions, parsing git's word-diff markers to render deletions and additions in separate columns. The tool wraps diff output in a dark-themed, sticky-header HTML table with per-file and per-hunk headings, and is run as a self-contained uv script with argparse-based pathspec filtering.
| | /usr/bin/env -S uv run --script | | | """Create a side-by-side HTML word diff between two Git revisions.""" | | | import argparse | | | from html import escape | | | from pathlib import Path | | | import re | | | import subprocess | | | import sys | | | MARKER = re.compile r" \ -. ?-\ \|\{\+. ?\+\} " | | | def parse paths value: str \| None - list str : | | | """Parse a comma-separated list of paths for the Git pathspec.""" | | | if value is None: | | | return | | | paths = path.strip for path in value.split "," | | | if any not path for path in paths : | | | raise argparse.ArgumentTypeError "file lists must not contain empty entries" | | | return paths | | | def render side line: str, side: str - tuple str, str : | | | """Render one diff line for the original or new side.""" | | | rendered: list str = | | | has deletion = has addition = has context = False | | | for part in MARKER.split line : | | | if not part: | | | continue | | | if part.startswith " -" and part.endswith "- " : | | | has deletion = True | | | if side == "old": | | | rendered.append f'