Repository navigation
Conversation
…s Chromium does In a template's own mode, Chromium reads only <link>, <meta>, <script>, <style> and <template> by the head's rules; every other start tag, <title>, <base>, <basefont>, <bgsound> and <noframes> included, switches the template to the body's rules. The standard (and parse5) reads those five by the head's rules too, which left the template's mode as it was, so rows, cells and columns after them were kept where Chromium drops them and keeps their text. StandardParser now switches the template to the body's rules first. A fragment is read as a template's content, so its Markdown changes when its top level has such a tag before rows: <title>Rows</title><tr><td>a</td> <td>b</td></tr> is "ab", not "a" and "b" as paragraphs. Random fragments and pages of table, template and head tags now match Chromium in every case (788 to 850 of 5,000 fragments and 236 to 303 of 5,001 pages per run differed before); the 120 captured pages give the same output. EXTRACTOR_VERSION is now extract-tf/16. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: 77777R7 <lunhoward306@gmail.com>
This was referenced Oct 3, 2026
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 #148 (
claude/parse5-fragment-text); it retargets as the stack merges. Fixes the Known gap in #148: Chromium drops the<col>itself in a fragment that starts with a<title>.Problem
The gap was wider than
<col>. In a template's own mode, Chromium sends only five tags to the head's rules:<link>,<meta>,<script>,<style>and<template>. Every other start tag switches the template to the body's rules, including<title>,<base>,<basefont>,<bgsound>and<noframes>.The standard (and parse5) sends those five to the head's rules as well. That leaves the template's mode as it was, so rows, cells and columns after them were kept. Chromium drops those tags and keeps their text.
template.innerHTML<title>t</title><tr><td>x</td></tr><title>t</title>x<title>t</title><tr><td>x</td></tr><base><col><base><base><col><noframes></noframes><caption>x<noframes></noframes>x<style>x</style><tr><td>y</td></tr>Whole pages behave the same inside a
<template>.Change
In
packages/extract-tf/src/dom.ts,StandardParser._startTagOutsideForeignContenthandles these five tags in IN_TEMPLATE. It first sets the current template mode and the insertion mode to IN_BODY, as parse5's "any other start tag" in a template does. The body's rules then insert the tag by the head's rules, so the tag itself is created as before.Output changes. A fragment such as the main content or a selection is read as a template's content. Its Markdown therefore changes when its top level has such a tag before rows:
<title>Rows</title><tr><td>a</td><td>b</td></tr>givesab, nota\n\nb.EXTRACTOR_VERSIONis nowextract-tf/16. The version test's digest is unchanged, because its fixed pages have no such fragment.Tests
packages/extract-tf/test/tables.test.ts. Every expected value is Chromium's.ab.<style>and row assertions are controls.npm run typecheck: exit 0.npm test: 145 files, 1840 tests passed.Chromium oracle
Random fragments (
template.innerHTML) and pages built from table and template tags plus<title>,<base>,<noframes>,<meta>,<link>and<style>. Old means #148's code, new means this PR; seeds 1–3:</foreignObject>and<select>cases, which differed before too.Review
A fresh-context reviewer found nothing blocking.
tmplInsertionModeStack[0]is the current template's mode. Every start tag, including re-processed ones and those breaking out of svg or math, goes through the override.<noscript>,<head>,<body>,<html>,<frameset>,<frame>and<hr>also switch to the body's rules, and parse5 already did that.<title>after a row or column set the mode, a<title>in svg or math, and templates in<head>or tables.Known gaps (unchanged)
</foreignObject>past an HTML<foreignObject>, and its newer<select>parsing, as listed in feat(extract-tf): build the page tree with parse5, the HTML standard's tree construction #137.<basefont>,<bgsound>and<frame>with end tags in thehtmlformat. The trees match Chromium; only the serialized text differs.🤖 Generated with Claude Code