all2md.diff.renderers.unified

Unified diff renderer with optional ANSI colors.

This renderer adds ANSI color codes to unified diff output for terminal display, compatible with standard diff tools.

class all2md.diff.renderers.unified.UnifiedDiffRenderer

Bases: object

Render unified diff with optional ANSI colors.

This renderer adds color codes to standard unified diff output: - Red for deletions (lines starting with -) - Green for additions (lines starting with +) - Cyan for hunk headers (lines starting with @@) - Bold for file headers (lines starting with — or +++)

Parameters:
  • use_color (bool, default = True) – If True, add ANSI color codes to output

  • context_lines (int, default = 3) – Number of context lines (informational, not used by renderer)

Examples

Colorize diff output:
>>> from all2md.diff import compare_files
>>> from all2md.diff.renderers import UnifiedDiffRenderer
>>> diff_lines = compare_files("old.docx", "new.docx")
>>> renderer = UnifiedDiffRenderer()
>>> for line in renderer.render(diff_lines):
...     print(line)

Initialize the unified diff renderer.

__init__(use_color: bool = True, context_lines: int = 3)

Initialize the unified diff renderer.

render(diff_lines: Iterator[str]) Iterator[str]

Render unified diff with optional colors.

Parameters:

diff_lines (Iterator[str]) – Lines of unified diff output

Yields:

str – Colorized diff lines (or original lines if color disabled)

all2md.diff.renderers.unified.colorize_diff(diff_lines: Iterator[str], use_color: bool = True) Iterator[str]

Colorize unified diff output.

Parameters:
  • diff_lines (Iterator[str]) – Lines of unified diff output

  • use_color (bool, default = True) – If True, add ANSI color codes

Yields:

str – Colorized diff lines