Plain text to treat as the source (unmatched words are highlighted).
Plain text to treat as the target (added words are highlighted).
Optionaloptions: HighlightOptionsOptional configuration for highlight tags and CSS classes.
A DiffTextResult with highlighted HTML, segments, and similarity.
import { diffPlainText } from "text-visual-diff";
const result = diffPlainText(
"The quick brown fox",
"The quick red fox",
);
// result.highlightedSource – "The quick <mark class="diff-unmatched">brown</mark> fox"
// result.highlightedTarget – "The quick <mark class="diff-added">red</mark> fox"
// result.similarity – 0.78 (14/18 chars match)
Compare two plain-text strings and highlight the differences.
Performs a word-level diff between
sourceTextandtargetText, returning highlighted HTML for both sides along with structured segment data. Unlike diffText, no HTML tags are stripped — both inputs are treated as plain text.