Class HtmlDocumentParser
java.lang.Object
dev.jcputney.mjml.css.HtmlDocumentParser
Lightweight HTML tokenizer that builds an
HtmlElement tree from HTML text.
This is NOT a full HTML5 parser. It handles the well-structured HTML output from the MJML renderer, including:
- Opening tags with attributes
- Self-closing tags
- Closing tags
- HTML comments (including MSO conditionals)
- DOCTYPE declarations
It tracks tag positions in the source string to enable in-place style modification.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of extracting CSS from HTML, containing the cleaned HTML and collected CSS text. -
Method Summary
Modifier and TypeMethodDescriptionextractStyles(String html) Extracts all CSS from <style> blocks in the HTML and returns the HTML with those blocks removed.static HtmlElementParses HTML into an element tree rooted at a virtual document element.
-
Method Details
-
parse
Parses HTML into an element tree rooted at a virtual document element.- Parameters:
html- the HTML string- Returns:
- the root element containing the document tree
-
extractStyles
Extracts all CSS from <style> blocks in the HTML and returns the HTML with those blocks removed.- Parameters:
html- the HTML string to extract styles from- Returns:
- a
HtmlDocumentParser.StyleExtractionResultcontaining the cleaned HTML and extracted CSS
-