text-visual-diff

Compare HTML source against plain text and highlight the differences. Extract visible text from HTML, diff it word-by-word against a target, and get back ready-to-render highlighted markup.

$ npm install text-visual-diff

Exact match

When the extracted text matches the target exactly, everything is highlighted as matched.

Removed content

Words present in the HTML source but missing from the target are marked as unmatched (red).

Added content

Words in the target that don't appear in the source are marked as added (blue).

Mixed edits with nested HTML

Tags are never wrapped inside highlights — they split and reopen across structural elements.

Custom tags and classes

Use custom HTML tags and CSS classes instead of the default <mark> elements.

Structured segments

The segments array gives you machine-readable offset data for building custom UIs.

Try it yourself

Edit the HTML source and target text, then press Compare to see the highlighted diff.

Matched Unmatched Added
Source (HTML)
Target (Text)
Highlighted Source
Highlighted Target