all2md.diff.renderers.html

HTML diff renderer with full-document visualization.

The renderer highlights additions, deletions, and unchanged context across the entire document. When provided with a DiffResult it produces a rich HTML page with summary statistics, collapsible context blocks, and line numbers. It falls back to the legacy inline-view when called with raw unified diff lines.

class all2md.diff.renderers.html.HtmlDiffRenderer

Bases: object

Render document diffs as visual HTML.

When supplied with a DiffResult, the renderer emits a full-document view that preserves ordering, adds line numbers, and highlights additions/deletions with GitHub-style colors. Unchanged sections can optionally be collapsed when show_context is False. Passing an iterator of unified diff lines is still supported for compatibility, using the legacy inline view.

Parameters:
  • show_context (bool, default = True) – If True, show unchanged sections; when False they are collapsible

  • inline_styles (bool, default = True) – If True, include CSS styles in the output

Examples

Render diff as HTML:
>>> from all2md.diff import compare_files
>>> from all2md.diff.renderers import HtmlDiffRenderer
>>> diff_result = compare_files("old.docx", "new.docx")
>>> renderer = HtmlDiffRenderer()
>>> html = renderer.render(diff_result)
>>> with open("diff.html", "w") as f:
...     f.write(html)

Initialize the HTML diff renderer.

__init__(show_context: bool = True, inline_styles: bool = True)

Initialize the HTML diff renderer.

render(diff: DiffResult | Iterator[str]) str

Render diff output to HTML string.

Parameters:

diff (DiffResult or iterator of str) – Structured diff result or unified diff lines

Returns:

HTML-formatted diff output

Return type:

str

all2md.diff.renderers.html.render_to_file(diff: DiffResult | Iterator[str], output_path: str, **kwargs: Any) None

Render unified diff to an HTML file.

Parameters:
  • diff (DiffResult or iterator of str) – Diff payload to render (structured result or raw unified diff lines).

  • output_path (str) – Destination path for the generated HTML file.

  • **kwargs – Additional keyword arguments forwarded to HtmlDiffRenderer.