Understanding HTML structure helps explain what gets extracted when converting to plain text. Different elements are treated differently during extraction.
Content vs Non-Content Elements
Content elements that become text include paragraphs (p), headings (h1-h6), lists (ul, ol, li), tables, divs and spans with text, link text (a), and emphasis (strong, em). Elements removed entirely include script, style, noscript, template, and HTML comments. Navigation, footer, and aside elements are typically removed as boilerplate.
Block vs Inline Elements
Block elements (p, div, h1-h6, ul, ol, table, blockquote) start new lines in the output. Inline elements (span, a, strong, em, code) continue on the same line. This distinction affects how text flows in the extracted output.
HTML Entities
Special characters are encoded in HTML as entities: for non-breaking space, & for ampersand, < for less-than, > for greater-than, " for quotes, © for copyright. Good text extraction decodes these to actual characters automatically.
Common HTML Patterns
Web articles typically use article tags containing headings and paragraphs. HTML emails often use nested tables for layout. Both require stripping the structural elements while preserving the readable content. Different patterns may need different extraction strategies.