Repository navigation
Conversation
…m does An end tag in svg or math is now matched to an open element by its exact name, as in Chromium: in svg it first takes svg's spelling (</foreignObject>, </clipPath>, </linearGradient>), in math it keeps its own. One that meets an HTML element first is read by the HTML rules, where a name svg respelled matches nothing (after the body it still returns to the body's rules). The standard (and parse5) compares names lowercased, so </foreignObject> in an svg closed an HTML <foreignobject> or math's around it, and what followed left the svg or math: in <p>a<lineargradient><svg></lineargradient>b</p> the "b" is in the svg, which shows no text, so the Markdown is "a", not "ab". Two more places where parse5 also took an svg or math element for an HTML one now read HTML elements only, as the standard and Chromium do: "any other end tag" in the body's rules (a </desc> or </mi> written in HTML inside svg or math closed the element around it), and resetting the insertion mode (an svg <tfoot> made the rest be read as a row group's). Random pages of table, template, svg and math tags now match Chromium in every case (36 to 50 of 5,001 per run differed before); the 120 captured pages give the same output. EXTRACTOR_VERSION is now extract-tf/17. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: 77777R7 <lunhoward306@gmail.com>
This was referenced Oct 3, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #150 (
claude/parse5-head-col); it retargets as the stack merges. Fixes the Known gap in #137 about Chromium's</foreignObject>past an HTML<foreignObject>. It also fixes two related namespace bugs that the same oracle turned up.Problem
1. Foreign end tags compared by lowercased name.
</foreignObject>,</clipPath>,</linearGradient>,</textPath>, …). In math it keeps the tag's own spelling.</foreignObject>in an svg closed an HTML<foreignobject>(or<clippath>, or math's<clippath>) around the svg, and what followed left the svg. In<p>a<lineargradient><svg></lineargradient>b</p>, Chromium keepsbinside the svg, which displays no text, so the Markdown isa, notab.2. "Any other end tag" ignored namespaces. parse5's
genericEndTagInBodymatched by tag ID alone. A</desc>or</mi>written in HTML inside svg or math therefore closed the svg<desc>or math<mi>around it.3. Resetting the insertion mode ignored namespaces. parse5 treated an svg
<tfoot>as a row group, so a second<table>in a<foreignObject>under it was dropped.The standard and Chromium read HTML elements only in both 2 and 3.
Change
packages/extract-tf/src/dom.ts, inStandardParser:onEndTaghandles end tags in foreign content, except</p>and</br>, which stay with parse5. When the current node is svg, the name is respelled byforeignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP. The stack is then walked comparing exact names; element names are read through the budgeted adapter.endTagAsAnyOthermatches HTML elements only. It is used for every end tag that parse5's body and table handlers do not handle by a rule of their own (OWN_END_RULES). It also covers formatting end tags with no entry in the list of active formatting elements, and end tags after the body._resetInsertionModeis reimplemented to skip svg and math elements, including in its walk over a<select>'s ancestors.MODEtable. They are parse5 8.0.1's, which is pinned.Because the Markdown changes,
EXTRACTOR_VERSIONis nowextract-tf/17. The version test's digest is unchanged.Tests
New test in
packages/extract-tf/test/tables.test.ts; every expected value is Chromium's. 8 of its assertions fail on fix(extract-tf): read a <title> or <base> at a template's top level as Chromium does #150's code:aMarkdown;</desc>and</mi>in HTML;<table>.Two guards pass on both versions: an svg element of the tag's name still closes, and a comment after
</body>stays in the body.npm run typecheck: exit 0.npm test: 145 files, 1841 tests passed.Chromium oracle
Random inputs of table, template, svg and math tags, with
foreignObject,clipPathandlinearGradientwritten in either case; #150's code compared with this PR's:<body>…</body>.parsereads that as a selection on purpose.Review
The fresh-context reviewer found two blocking problems. Both are fixed and the reviewer re-checked them:
</body>, a respelled end tag was dropped without switching back to the body's rules, so a later comment went under<html>. This is fixed, with a test.The reviewer also checked:
OWN_END_RULESagainst parse5 8.0.1's six handlers;BODY_RULE_MODES;Known gaps
<select>parsing. The standard dropped the "in select" modes. This is being worked on next.namespaceURIdoes not. This was the same before.</html>. Chromium puts them on the Document; our copy keeps only<html>. This was the same before.🤖 Generated with Claude Code