Skip to content

fix(html): use one definition of raw text for link extraction and markdown - #232

Closed
tobocop2 wants to merge 3 commits into
fix/markdown-raw-text-base-graphicfrom
fix/one-raw-text-definition
Closed

tobocop2 wants to merge 3 commits into
fix/markdown-raw-text-base-graphicfrom
fix/one-raw-text-definition

Conversation

@tobocop2

Copy link
Copy Markdown
Member

Stacked on #123. Merge that first, then retarget this to main.

One definition of raw text

Link extraction and the markdown pre-pass decided differently what counts as raw text. Link extraction used a hand-written scanner that knew script, style, title and textarea; the markdown path used an html5ever scan. Both now use one masking pass built on the html5ever tree builder, so they read a page the way a browser does.

What link extraction now leaves alone

Links inside xmp, iframe, noembed, noframes and plaintext; the content after <script/>; a script inside SVG foreignObject. A quote inside an unquoted attribute value no longer opens a quote, and a <!-- inside any raw-text element no longer hides the links after it. noscript content counts as markup for link extraction (a crawler does not run script) and as text for markdown, which matches the converter.

Base address

The first real <base href> now comes from the same scan, for both link extraction and markdown, so a <base> written inside raw text no longer redirects every link.

Cost

The masked text keeps its byte length and is byte-identical to before on four real pages. On a dense 1 MB page the masking takes about 17 ms against 1.5 ms before; on a typical 1 MB page 3.3 ms against 1.6 ms.

Closes #201

…kdown

Link extraction masked raw text with a hand-written scanner that knew four
elements, while the markdown path used an html5ever-based scan. They disagreed:
link extraction read links inside xmp, iframe, noembed, noframes and plaintext,
treated <script/> as closed, read script inside svg foreignObject as markup, let
a quote inside an unquoted attribute value open a quote, and a "<!--" inside the
newly covered elements hid every later link.

The masking is now built on the html5ever tree builder, with scripting off for
link extraction (noscript content is markup) and on for markdown. The masked
text keeps its byte length, so every caller's offsets hold. The first real
<base href> now comes from the same scan for both paths.

On a dense 1 MB page the masking takes about 17 ms, against 1.5 ms for the old
scanner; on a typical 1 MB page 3.3 ms against 1.6 ms.
Nothing checked that </titles> does not close a <title>; a test now covers <title> and <style>. The changelog also names every foreign-content exception the masking follows: svg foreignObject, desc and title, and the MathML text integration points and annotation-xml.
@Goldziher
Goldziher force-pushed the fix/one-raw-text-definition branch from 8c4ab0c to 12370cc Compare September 27, 2026 08:53
@tobocop2

Copy link
Copy Markdown
Member Author

Closing: the link-extraction half of this change landed in integration/0927 with #501 (one html5ever read of the page). The markdown half moves with #405 into the html-to-markdown release.

@tobocop2 tobocop2 closed this Sep 29, 2026
@Goldziher
Goldziher deleted the fix/one-raw-text-definition branch October 10, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(html): link extraction and markdown disagree on what counts as raw text

1 participant