Magpie HTML - v0.1.3
    Preparing search index...

    Function htmlToText

    • Convert an HTML string to plain text.

      Parameters

      • html: string

        HTML string (fragment or full document)

      • options: HtmlToTextOptions = {}

        Conversion options

      Returns string

      Plain text string

      This function uses a streaming tokenizer to parse HTML and extract text content. It handles block elements, whitespace preservation, HTML entities, tables, and more.

      Features:

      • Preserves document structure with appropriate line breaks
      • Handles HTML entities (numeric and common named entities)
      • Configurable link and image handling
      • Table rendering with configurable cell separators
      • Whitespace preservation for code/pre blocks
      • Optional hard-wrapping at column width

      If html is not a string

      const html = '<div><h1>Hello</h1><p>World!</p></div>';
      const text = htmlToText(html);
      console.log(text); // "Hello\n\nWorld!"
      const html = '<a href="https://example.com">Visit</a>';
      const text = htmlToText(html, { links: 'inline' });
      console.log(text); // "Visit (https://example.com)"