text-visual-diff
    Preparing search index...

    Function diffText

    • Compare HTML source against plain text and highlight the differences.

      Strips tags from sourceHtml to extract the visible text, performs a word-level diff against targetText, and returns highlighted HTML for both sides along with structured segment data.

      Parameters

      • sourceHtml: string

        HTML string whose visible text is compared.

      • targetText: string

        Plain text to compare against.

      • Optionaloptions: HighlightOptions

        Optional configuration for highlight tags and CSS classes.

      Returns DiffTextResult

      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)