Markup conversion guides

Read the Ordered HTML Tree in a YAML Export

·

Start with the parser tree when you need to extract or compare an HTML document’s structure. A parsed tree represents the elements the HTML rules create, including some elements missing from the original text.

HTML to YAML Converter

Check child order and attribute types in the print notes

Load example and convert in the body fragment context. In the saved file, the article has data-edition 007 and data-draft false as strings. Find the paragraph children in order: text ending in a space, a strong element containing two, and text starting with a space.

Find the table body marked implied. Open the template children and look for the span containing Spare card. The output preserves where those nodes belong.

WHATWG HTML parsing and fragment contextYAML 1.2.2 representation and scalars

Compare a table fragment under two contexts

Paste <tr><td>North bench</td></tr> as a fragment. Convert first with body and then with tbody. The tbody context keeps the tr and td as elements. Use tr when the pasted fragment is a cell.

WHATWG HTML parsing and fragment context

Review comments and whitespace before exporting

Return to the example and turn off Keep HTML comments. The Press note comment disappears. Turn on Omit indentation-only lines to drop whitespace-only text nodes with a line break, while preserving mixed text and whitespace in preformatted elements.

For a saved page with a doctype and head metadata, choose Full document. Check the entire tree in the YAML reader that will consume it.

WHATWG HTML parsing and fragment contextYAML 1.2.2 representation and scalars

Common questions

Does the YAML record the original HTML source bytes?

It records the parsed tree. Entity spellings, element case adjustments and implied elements follow the HTML parser.

Will a script run while I inspect the YAML?

Script and style contents are exported as strings. The workspace shows the result as text.

Sources

Put it into practice.

Related guides