text-visual-diff
    Preparing search index...

    Function diffPlainText

    • Compare two plain-text strings and highlight the differences.

      Performs a word-level diff between sourceText and targetText, 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.

      Parameters

      • sourceText: string

        Plain text to treat as the source (unmatched words are highlighted).

      • targetText: string

        Plain text to treat as the target (added words are highlighted).

      • Optionaloptions: HighlightOptions

        Optional configuration for highlight tags and CSS classes.

      Returns DiffTextResult

      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)