HTML string whose visible text is compared.
Plain text to compare against.
Optionaloptions: HighlightOptionsOptional configuration for highlight tags and CSS classes.
A DiffTextResult with highlighted HTML, extracted text, segments, and similarity.
import { diffText } from "text-visual-diff";
const result = diffText(
"<p>Hello <b>world</b></p>",
"Hello earth",
);
// result.highlightedSource – source HTML with <mark> tags
// result.highlightedTarget – target text with <mark> tags
// result.extractedText – "Hello world"
// result.segments – structured diff info
// result.similarity – 0.55 (6/11 chars match)
Compare HTML source against plain text and highlight the differences.
Strips tags from
sourceHtmlto extract the visible text, performs a word-level diff againsttargetText, and returns highlighted HTML for both sides along with structured segment data.