HTML and web publishing guides

Compare a Broken Fragment With Its Parsed Tree

·

When emphasis unexpectedly continues into the next section, the parser may have recovered a tree that differs from what the author intended. Compare the recovered structure before accepting its serialization.

HTML Broken Tag Fixer

Read the repaired trail notice

Load the example and repair it as a Body fragment. The slash in the div on line 4 produces one parser diagnostic. The repaired text closes both list items and places Rest stop inside a div.

Look for </strong></p><strong> near the paragraph. The formatting element was still open when the paragraph ended, so recovery can carry emphasis past that paragraph. If emphasis should end at trail map, add </strong> before </p> in the original and repair it again. The parser can close and reconstruct elements, but it has no way to infer the author’s intended emphasis.

WHATWG HTML parsing and error recoveryWHATWG HTML optional tags

Choose the right parent for a table row

Replace the source with <tr><td>Café<td>Open, keep Fragment, and choose the tbody context. The repaired text is <tr><td>Café</td><td>Open</td></tr>. Switch to Body and run the same text. The table tags are outside their expected parent and the parser leaves the text CaféOpen.

A full HTML page belongs in Complete document mode, which can add implied html, head and body elements. A component fragment depends on the element that will contain it.

WHATWG HTML fragment parsing algorithmWHATWG HTML parsing and error recovery

Reconstruct the download from its change range

Open Compare changed source to inspect the original and replacement text. In the exported JSON diff, startOffset is inclusive and endOffset is exclusive. Replace precisely that range in the original source with after. It should reproduce repaired.html when read as UTF-8.

Compare the tag hierarchy as well as changed characters. Serialization may normalize attributes, characters and optional closing tags. Inspect the downloaded result as text because the original markup may contain scripts or other active elements.

WHATWG serializing HTML fragmentsWHATWG HTML optional tags

Common questions

Does the fixer add missing content inside a broken tag?

The serializer writes elements and text the parser recovered. An unfinished tag that the parser discarded may leave no element to serialize.

Does the repaired download remove scripts or event attributes?

The fixer preserves active markup that survives parsing. It displays all source as text so you can inspect it before use.

Sources

Put it into practice.

Related guides