Skip to content

perf(md): convert a page to markdown in about half the time - #23

Merged
ejkorol merged 74 commits into
mainfrom
ejkorol/md-faster-conversion
Nov 17, 2026
Merged

ejkorol merged 74 commits into
mainfrom
ejkorol/md-faster-conversion

Conversation

@ejkorol

@ejkorol ejkorol commented Nov 11, 2026

Copy link
Copy Markdown
Member

The markdown is unchanged; only where the time goes is.

  • Parse with parse5 and hast-util-from-parse5 directly, without source positions. Nothing read them, and computing them dominated some pages.
  • Skip toMdast's structured clone and whitespace pass: it is handed an empty root whose handler converts our own cheap copy, minified by a port of hast-util-minify-whitespace that tests tag names against sets.
  • Find chrome and shown tab panels by walking properties instead of css selectors over the whole page; resolveStreamed walks directly too.

hast-util-from-html stays as a devDependency for one test.

The markdown is unchanged; only where the time goes is.

- Parse with parse5 and hast-util-from-parse5 directly, without source
  positions. Nothing read them, and computing them dominated some pages.
- Skip toMdast's structured clone and whitespace pass: it is handed an
  empty root whose handler converts our own cheap copy, minified by a
  port of hast-util-minify-whitespace that tests tag names against sets.
- Find chrome and shown tab panels by walking properties instead of css
  selectors over the whole page; resolveStreamed walks directly too.

hast-util-from-html stays as a devDependency for one test.

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
affordances Ready Ready Preview Nov 17, 2026 3:23pm UTC

Request Review

ejkorol and others added 28 commits November 13, 2026 17:18
A private workspace for a converter that aims to produce @affordances/md's
markdown at a fraction of the cost: a skip-scanning, spec-accurate parser
that builds only what can be content, and an emitter that writes markdown
straight from that tree.

- parse.ts matches a parse5-based oracle on the corpus and under fuzz.
- emit.ts matches @affordances/md byte for byte on 7 of 10 benchmark
  pages; markers, the form summary, shown tabs and streamed boundaries
  are not built yet.
- bench/ times it against mdream, turndown, node-html-markdown and
  @affordances/md, and reports output parity.

First end-to-end number: 130 ms for the 10-page corpus, against 35 ms
for mdream and about 1500 ms for @affordances/md.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hJ9SEkCX16tDcRNj1QfjV
…r reads only through it

The emitter scanned attribute source by hand and matched names
case-sensitively, so a table written with React's colSpan lost its span.
Presence now comes from Element.flags, set as the parser reads each tag,
values from attr(), and the main landmark from Document.mains. Every
emitter case is re-run in five attribute spellings through the real
parser.

Parity is 8 of 10 benchmark pages byte for byte; the two synthetic pages
differ only by the form summary. Speed is unchanged in total: 128 ms
against mdream's 35 ms.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hJ9SEkCX16tDcRNj1QfjV
… on fresh trees

- emit owns the Document it is given and prunes it in place: the per-emit
  side tables and copied child lists are gone, and the separate tidy pass
  is folded into first use.
- attr() reads the first two attributes asked of an element straight from
  the tag's source and builds a map only on the third.
- The parser gives every element the emitter's fields from the start, so
  elements keep one shape.
- The benchmark gives each timed emit a freshly parsed tree; it used to
  re-emit one tree with warm caches, which read about 25% low.
- Fix: a later <html role=main> in a frameset document is now a main.

120 ms for the 10-page corpus against mdream's 37 ms; parity unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hJ9SEkCX16tDcRNj1QfjV
…emitter as fallback

Top-level paragraphs and headings of plain inline content (text, strong,
em, code, links, breaks, spans) are written as soon as they are
converted, without building their children. Anything else declines
before a byte is written and goes through the existing emitter, which
stays the definition of correct: output with the fast path on must equal
output with it off, across every case, the corpus, the fixtures and a
fuzz of the accepted shapes and their near misses.

Also: one-pass escape scan, an emphasis shortcut when markers pair as
written, and the hidden-style check remembered per attribute string.

109 ms for the 10-page corpus against mdream's 37.5 ms; parity unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hJ9SEkCX16tDcRNj1QfjV
…otal without synthetic/200

--budget defaults to 1000 ms, and a last line gives md-core's and mdream's
totals without synthetic/200, which is nearly half of md-core's time. No
source change. Baseline on it: md-core 107 ms (parse 34.2, emit 70.8),
mdream 37.4; without synthetic/200, 59.1 and 25.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n as it's read

A list at the top of a flow whose items are runs of inline content and the
lists between them (99% of the corpus's items) is read in one walk into a
small DList, each run written as its paragraph closes, and written as list(),
listItem(), containerFlow() and between() would: spread items, the line
endings in and between items, ordered starts, and the bullet rules (the other
bullet after a list, the empty-first-item chain three lists deep). Only the
top bullet is left to the serializer, which knows the list before it. Anything
else declines before a byte is kept, and the full emitter stays the oracle.

The gate's fuzz now generates nested, ordered and empty-item lists, clean or
noisy as a whole (1885 direct lists in 20k pages, 0 mismatches; 2x100k pages
clean), so its 3000-page test gets a 60 s timeout.

337 of the corpus's 364 lists. Bench: 107 -> 103 ms (emit 70.8 -> 66.0),
mdream 37.1; quick A/B over 8 alternations -2 to -3 ms. Parity unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
md-core's src is now packages/md/src/convert/core and its converter tests
packages/md/test/convert/core: one copy of the source, in md, which nothing
in md calls yet. Only paths and imports change, but for one thing: the
corpus parse test is skipped as a whole describe when the corpus isn't
fetched, since md's vitest fails a file with an empty suite. packages/md-core
keeps the bench, parity and eval tools, importing the converter by relative
path, and loses its package export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
readPage and readStreamed strip the flight data first, as before, then
hand the page to md-core unless the call has handlers or a function
extract, which need the tree. A page md-core can't write yet (markers,
flight data, streamed boundaries) is declined before anything is written,
counted by why, and the tree pipeline takes it; 'strict' throws instead,
for tests. The switch is a module-level setter in convert/path.ts, never
an option or env var, and the default stays the tree for now.

On core, each markdown() call parses the page again: md-core's emit
prunes the tree it's given in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
md-core's parser now keeps every script element's own text, in any
namespace (svg and math too, where it keeps nothing else), leaving out a
template's content and a body a frameset removed: what the tree pipeline
reads in parse5's tree. untrusted() takes those texts, so both paths run
the same check: readStreamed throws FlightDataError, and readPage re-reads
the page as sent with an error of its own, on md-core.

Keeping the scripts' text costs parse about 1.9 ms over the bench corpus
(32.5 to 34.4 ms). A test holds the script texts to parse5's over the
fixtures, the corpus, cases and 6000 generated pages; another reads every
fixture and push attack on both paths and compares rows, redirect,
fallback and throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On an element that isn't an <affordances-md> marker, md reads
data-affordances-md as skip or show only. md-core took any value, so a
hidden element (or chrome on a page without a main) carrying
data-affordances-md="only" was written. md-core's converter now reads the
attribute as md does. Nothing reached this through md yet: marked pages
decline to the tree pipeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
md-core now writes what md's markers ask for, so a marked page no longer
declines:
- <AgentText md> is its markdown, verbatim: inline or block, said even when
  hidden, never naming anything with what's inside it. As md does once a
  page is converted, its links are relinked with md's own rewrite (passed
  in, so the converter doesn't import md), it keeps to one line in a table
  cell, and a block of it is lifted out of its paragraph or heading.
- <AgentMain>: the outermost kept ones are the page.
- A shown tab panel is headed by its tab, and a tablist whose tab labels
  one goes.

md finds AgentMains and shown panels on a tree it prunes in place, so
where prune changes what's around one first (inside a link, a table, a
label host, a tablist, an AgentText, or a shown panel under something
hidden), md-core declines the page up front. Slots are still declined.

It costs md-core about 0.7 ms over the bench corpus (-0.2 to +1.6 in
three interleaved runs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
readPage on md-core lists the <AgentSlot> names that reach the markdown,
unique and duplicate in page order, as md finds them on its pruned and
extracted tree: never hidden, skipped, in an AgentText, outside the
AgentMain or main, in stripped chrome, or inside another slot. A fill for
a unique name is block marker markdown in the slot's place, relinked and
lifted like an AgentText's; prune still reads the slot's children (a link
or table around it is judged by them), conversion never does.

Where prune could take a slot out and md-core can't tell from the parsed
tree (in a link, with nothing to read; in a table that may be a skeleton;
in a tablist a shown panel's tab labels), the page declines up front.

Each markdown() call converts again with its own fills; a test holds a
second call with other fills to the tree pipeline's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A form on md-core's path is converted by the tree pipeline's code, as an
island: md-core hands over the form as parse5 would have made it (the
elements prune left, as conversion reads them, attributes as written,
with md's own prune edits: no page-set data-affordances-md-text, no hidden
on what's shown), the content's elements by id, and its filled slots. md
turns that into hast with hast-util-from-parse5, minifies its whitespace
and converts it with toMdast and its handlers, so the field summary, the
names, which values show and the secret filters are md's own. md-core maps
the mdast to its nodes and resolves their links as md does afterwards.
The form is minified in the whitespace it's in (a <nobr> doesn't wrap, a
<pre> keeps it), as md's pass over the whole page has it.

Without the hook (md-core on its own, as the bench runs it) a form still
says what it says without its fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
md asks options.link once for each link it writes, in tree order. md-core
asked again when the fast path declined a block after resolving its
links, and when a block was converted again to be read (the description
check), so a callback saw some links twice. Each link element's url is now
resolved once per conversion. md's own behaviour doesn't change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These go to the tree pipeline, counted, before md-core writes anything.
md-core's parser reads each exactly, in place of a regex over the html:

- 'streamed': react's Suspense boundaries move into place
  (resolveStreamed), which md-core doesn't do. That takes a <template id>
  and an instruction (a script whose text has $RC, $RR or $RS, or a
  template with data-bid or data-pid). A test holds every fixture, corpus
  and generated page resolveStreamed changes to being one md-core declines.
- 'selector tag name': an element named with a # or a ., which
  hast-util-from-parse5 builds with hastscript's h() and so reads as a
  selector (<a#x> is a link with id x, <script#x> a script, and the
  flight check counts it). Declining leaves the check to the tree
  pipeline, which fails closed.
- 'main inside what prune changes' and 'chrome inside what prune changes':
  md finds landmarks, and strips chrome, on a page it pruned in place
  first (an empty <main> in a link is an empty block there), md-core on
  the page as parsed.
- 'strikethrough and list': a strikethrough holding a list, or in one with
  no list item between, is written outside a paragraph, where what's
  escaped isn't what md-core escapes.

Each of review's minimized shapes is a regression case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In svg or math a <template> is an element like any other, with children
and no content, but hast-util-from-parse5 reads every template's content
and threw on one without, so htmlToMarkdown and readPage threw on such a
page (any page the tree pipeline converts). md now converts one under
another name and names it template again after, its children where parse5
put them: prune drops it as it drops any template, which is what md-core
writes, and the flight check still finds a script in it, as md-core's does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shapes

Found by review's tree-construction generator, each fixed where md-core
read the page differently from md's own pipeline, with a regression case:
- an <html> in svg or math is a foreign element, so its lang isn't the
  page's (md reads the root's);
- a <nobr> in a <pre> doesn't wrap, so its whitespace collapses there too,
  as md's whitespace pass has it;
- an h1 or h2 is written setext style when any value in it holds a line
  ending, a code block's too, as mdast-util-to-markdown decides.
md-core's test oracle reads the head's lang as md does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
htmlToMarkdown and readPage now convert with md-core unless the call has
custom handlers or a function extract, which keep the tree pipeline, as
does any page md-core declines (counted, before anything is written).
Over the bench corpus md's htmlToMarkdown goes from 1312 to 236 ms
(5.6x), with all 10 pages byte-identical (bench/parity.ts now compares
md's default against its tree pipeline); 1 corpus page and 4 of 37
fixtures decline, all streamed.

md's suite runs twice: as the default does, with any decline but a
streamed page's failing the test, and on the tree pipeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A differential in md's suite, so CI runs it, each page converted on both
paths:
- md's fixtures, with the default options and with frontmatter, json-ld
  and extraction off;
- the bench's two synthetic pages;
- 300 of the emit fuzz's pages, on three fixed seeds;
- 4000 pages heavy on html's tree-construction recovery mixed with what md
  reads (tree-fuzz.ts, modelled on review's generator), on four fixed
  seeds, through htmlToMarkdown and readPage with a fill.
Any page where they write differently fails, and so does any decline but
those md-core leaves to the tree pipeline by design. It adds about 11 s to
md's suite (the recovery pages about 3.5 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It asserted 15,000 links in under 8 s, which a loaded machine (or md's
suite running as two vitest projects at once) could miss with nothing
wrong. It now times the same fill at 1,000 and 8,000 links in one run,
the best of three each, and bounds the ratio below 24: about 8x when the
rewrite is linear (7.1 measured), about 64x when each link copies the
whole fill (59.6, with that mutant). The last link's output is checked as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A swapped Flight push leaves a nonce as its script's text, for the flight
check. A JSON-LD script, or a script in a MathML <title>, is read as text,
so the nonce was written as a json block or as the page's title, on both
paths. Once its text is recorded for the check, a script whose own text is
the nonce now reads empty: in strippedTree on the tree path, and in
md-core's parse (a nonce argument, cleared before the head is read). The
page reads as it does without its flight data. The stripper's output and
the check are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stripper gave back each tag, comment and text run as its own slice and
joined them per chunk: a third of its time went to that join and the
garbage it left. What it reads is given back as it is, so the output is now
the chunk between its scripts, sliced only where a script starts or ends and
where the chunk does; a script's text is held and swapped or given back
whole, as before. The output and Swapped are byte-identical (3,047 pages,
fixtures, the corpus and fuzzed pages with pushes, at five chunkings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per tag, the stripper ran a regex to tell a letter, another to find an
upper-case one, a third to tell svg and math apart, and built arrays to
assign its state: about a fifth of its time. Letters and case are now read
by char code (ascii only, as the tokenizer reads them), svg and math by
name, and state is assigned directly. The output and Swapped are
byte-identical, case variants (SCRIPT, Svg/, ſcript, scrİpt) included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… data

A push is a script whose text, as written, starts with CALL, and CALL is
now made of NEXT_F (self.__next_f), so a page that never says NEXT_F has
nothing for the stripper to swap: it would give the page back as it is.
readPage, which has the whole page in hand, now skips the stripper there;
readStreamed can't know up front and is unchanged. The flight check still
runs on the parsed scripts, so an entity-decoded push in svg still marks
the page errored.

Tests: CALL is pinned and mutation-fuzzed (whatever still reads as a push
says NEXT_F); near-miss spellings in every context are the stripper's own
output, with nothing swapped; NEXT_F split across chunks is still read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ine does

A streamed Suspense boundary ($RC/$RR/$RS, or the external runtime's
data-rci/rri/rsi templates) no longer sends the page to the tree pipeline:
md-core's parser keeps react's boundary comments where parse5 puts them
and, before it reads the head, makes resolveStreamed's moves on its own
tree (core/streamed.ts): the last element with an id wins, instructions
from the scripts' text in tree order and then the templates, templates in
page order, each fallback to its closing <!--/$-->. What a move takes out
of the tree is out of it for what reads the page after.

It declines only what it can't see, since it keeps nothing inside svg: an
instruction template there (in any spelling, self-closed too), a template
with an id there, a segment found there, or a segment it keeps no text in.
The pre-check sends react's own spelling of the svg shapes to the tree
pipeline before md-core parses, by a scan that's linear in the page (its
svg stretches never overlap; segment ids are matched by a Set); any other
spelling declines after the parse. And a form in a link or strikethrough,
which the tree pipeline splits in the same pass that converts the form,
declines too.

No move ever puts an element inside itself: a segment that holds the
template it moves into (above the template's parent, at any depth, by any
instruction) declines the page, which the tree pipeline reads as before.
A generator of nested segments and templates checks every way a move
could make a loop, by steps, in the suite.

On the corpus and the fixtures nothing declines now (it was 1 and 4,
all streamed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…what prune changes, and hidden shown panels

Prune's judgment of a link's blocks (kept with something to read, dropped without) is made on the page as parsed,
so md-core reads a slot or AgentMain in a link as the tree pipeline does, the links above an AgentMain included.
It declines where it can't tell: a link holding tabs prune may take out first, a link that says nothing but values
(it reads as its label, or is gone with what it holds), and an AgentMain whose link takes values or empty blocks out
of it. Chrome is stripped once a page is pruned, as the tree pipeline strips it, so the 'chrome inside what prune
changes' decline is gone. A shown panel under something hidden or changed only declines where its tabs alone would
decide a tablist, and a shown panel is headed only by a tab in a tablist beside it: the tree pipeline finds the
page's ids once, partway through pruning, so a tab anywhere else may already be gone. The changeset names what
still declines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ast-util-to-markdown does

containerPhrasing replaces a line ending before html (an <AgentText> right after a <br>) with a space, so the html
can't start an html block; md-core wrote the line ending. A hard break before an AgentText now reads as the tree
pipeline writes it (a backslash and a space, not a backslash and a new line), in emphasis too. The marker generator
no longer leaves those pages out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cut past 512, and the route fails closed

Both paths recursed over the page (hast-util-from-parse5, hast-util-to-mdast, md-core's emitter) and threw a
RangeError from about 2,000 nested elements; parse5 and mdast-util-to-markdown also take time that grows with the
square of the nesting. Now:
- anything nested more than 128 elements deep is read as its plain text, through attribute-less structure only
  (nothing hidden, no control, no marker), on both paths: md-core flattens its tree and the tree pipeline the parse5
  document, right after parsing (src/convert/depth.ts);
- a page nesting more than 512 open elements is cut at the tag that opens one more: md-core's linear parser finds it,
  and both paths read the same page up to there (the tree pipeline takes the cut from md-core's parse of the page it
  just declined, or counts parse5's open elements as it parses, through the tree adapter's hooks, and asks md-core's
  parser only once that passes 512: only a parser can tell how deep a page nests). readPage says
  cut: true, and the route marks it partial, with a note, as it does when the flatten leaves anything out;
- the streamed walks no longer recurse;
- the route answers 502, private, no-store for any error converting a page, as it does for unreadable Flight data,
  instead of letting it out as the framework's 500.
100,000 nested div, span, svg or unclosed b converts in under 200 ms on either path, the same on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ejkorol and others added 7 commits November 14, 2026 20:01
… pass does

That pass joins each text to the one before by splicing the list and reading the joined text again: ~11s for 64000 texts between comments, ~31s between spans, on every tree-pipeline call. Joining them first, in one pass, leaves it nothing to join; what it then does to each text is what it did to the joined one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… paths

Each move found its template's place and spliced the parent's whole list, and md-core then searched each moved element's parent for it: n boundaries in one parent, or nested each in the one before, were quadratic (~2.4s at 16000 on md-core, ~1.9s on the tree pipeline). While the moves are made, the parents they splice are linked lists, written back once they're done; the moves themselves are the same.

The growth tests' timed cases get a 60s timeout, so a loaded machine slows them without failing them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every feature of review's probe (markers, slots, tables, lists, links, forms, the parser's shapes, react's streaming), and the growth findings' own shapes, read at n and 4n through htmlToMarkdown or readPage with fills, on md-core as md runs it and on the tree pipeline. A read's cost may grow no more than 2.5 times as fast as the page does: timed best of three, the sizes in turn, and measured again while a sample looks too fast. Each finding's shape fails on 8203c48. The file takes ~8s alone, under 1s on md's suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mit, and say what they measured

A 2000-boundary resolve takes ~5 ms, so one busy moment under load could push its 8x ratio past 24. Each 8x case now
takes each size's best of three, in turn, up to three times while it's over the limit, as the probe's growthOf does: a
real quadratic is over every time. The probe's failures print the growth they measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… one linear walk

hast-util-select's selectAll checks each match against every match before it, so a form of 64000 labelled fields
took ~3.5s. md's own walk (elementsIn) replaces the simple-selector calls: a form's fields and labels, a select's
options, a tablist's tabs and a link's described images. It returns what selectAll did: the root and what's under it,
in document order, each node once, matching attributes as a selector reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An ordered list's item found its number with the list's indexOf, once per item, which is quadratic: 64000 items holding
blocks took 1.3s on md-core. containerFlow already holds the index of what it's writing, so the item uses that, and
only looks itself up when that isn't it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s another number

md-core reads rowspan and colspan as html does (parseInt: "1e3" is 1, "0x10" is 0), while hast reads a number
first where the value is one (Number: 1000 and 16), so those tables came out another shape on each path. md-core
declines only where the two readings differ, tagged PARITY: every other span, odd or not, stays on md-core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@socket-security

socket-security Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednext@​16.4.662100909970
Addedturndown-plugin-gfm@​1.0.21001008575100
Added@​affordances/​md@​0.0.0761009388100
Addednode-html-markdown@​2.0.010010010081100
Addedturndown@​7.2.510010010089100
Addedmdream@​2.1.09510010096100

View full report

ejkorol and others added 15 commits November 16, 2026 16:25
…two texts, as the tree pipeline does

md-core's parser joined the text either side of a comment it never builds, and
either side of a script, svg or other element it drops. The tree pipeline keeps
them as separate text nodes, and its side-by-side spacing reads each text's own
word: so beside an element with a display class (block, flex), md-core spaced
S<!-- -->5<span class=block>pa</span> as "S5 pa" where the tree writes "S5pa".
React writes <!-- --> between adjacent texts, so docs pages hit it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… does

The tree pipeline takes the head's first link whose rel tokens join to
"canonical", so rel=" canonical" counts, and the first one is the canonical
even without an href (the url option then stands). md-core compared the raw
rel and read on past a link with no href to a later one's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new generator writes what real docs pages hold and the other
generators never did: texts split by react's empty comments and by
empty icons beside elements made boxes, head links with odd rel and
href values and several canonicals, and the parts around them (nav,
heading anchors, highlighted code, figures, copy buttons). The
differential runs 3000 of its pages under four option sets. As a
script it minimizes each page the two paths write differently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A page md-core's parser read whole was parsed whole on the tree pipeline, with
no depth guard of its own: had the two parsers ever disagreed on how deep a page
nests, hast-util-from-parse5 would have recursed past the stack. The tree
pipeline now checks parse5's own count there too and cuts where parse5 nests
past CUT. A differential of 10,400 deep malformed pages found no disagreement,
so no page reads differently today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
htmlToMarkdown read a page nested past what md reads up to there, or past 128
deep as plain text, and said nothing of it. Its Result now has cut?: true, the
same as Page.cut, which the converter docs now describe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
attr's cache of the element it was last asked about kept that element, and so
its page's tree, until the next page asked for an attribute. It's cleared once
md-core has parsed a page and once it has written one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds the page as md-core did

When md-core's markdown() threw, the tree pipeline wrote the page, but the page
handed out kept md-core's slots, cut, redirect and fallback, which the caller
may already have acted on. The two are held equal by the differential, but the
fallback runs exactly where md-core has met a page it got wrong: so the tree
pipeline's markdown is used only where its read says the same, and otherwise
the first error is thrown (the route answers 502, private, no-store).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ls uses it

A hast tree has each node under one parent, so the walk meets each once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… table can't undo the one before it

The split a comment leaves was one slot for the whole page: a later comment in a
table, row or caption took it over, and text fostered out of that table joined
onto the text before the parent's own comment. Each parent now keeps its own.
Found by review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in a map

A Map.set per comment cost about 5% on a page of React's <!-- --> separators.
Each element now carries the count of its children where its last comment sat,
which goes with the tree, so there's nothing to clear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d records what it measured

A row for @affordances/md 0.5.0 from npm, the tree pipeline main ships, with the
same call as the current one: the before for md's own users. It's a devDependency
by its registry tarball, since an npm: alias of the same name and version links
the workspace instead. The json also records the commit (--commit, for an export
with no git), the load as the run starts, and each tool's installed version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One quiet run of packages/md-core's bench (run.ts --json) on 616f0a5's export,
started at load 0.92: 20 runs after 3 warm-ups, gc before each tool on each page,
on the 8 fetched pages and the 2 synthetic ones. The page reads every number from
this file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and node-html-markdown

Every figure on it is computed from the recorded bench run in
src/data/md-performance.json: the headline ratios, the totals and
per-page tables, the throughput chart and the method. The run lives in
src/data because fumadocs reads every json under content/ as a meta
file. The page says plainly where md is slower (mdream) and why the
tools' Markdown differs, with a feature table checked by probes.
Listed after the converter page, which links to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from an install

md keeps aria-hidden="false" and an empty aria-hidden, as ARIA reads
them, and drops visibility: collapse, which the conversion page didn't
list. The Performance page's steps now start where a fresh clone does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejkorol
ejkorol marked this pull request as ready for review November 16, 2026 22:07
ejkorol and others added 4 commits November 16, 2026 23:59
…o the twin

Next streams notFound() after the shell as a 200 of its not-found page,
which literalPage passed through as found, with a Link to a twin of a
page that doesn't exist. A 200 html answer is now read, up to maxBytes
and under the timeout, and its flight data checked as the convert path
checks it: a trusted 404 digest falls to the twin, a 403 or 401 answers
its status, private, as the markdown request does. Anything else is
answered with the page's own bytes, status and headers, plus its Link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16.4.3's build stops with Next's security upgrade notice. Every app and
package moves to 16.4.6 together, so each build runs on one Next; the
lockfile changes only next, @next/env and @next/swc-*. Peer ranges stay
at >=16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
md parses with scripting off, so a script in a <noscript> or in MathML
was a script to it, though a browser never runs one there: a Flight
push or a streamed boundary's instruction in one was trusted as Next's.
Such a script is now never an instruction, and a push or instruction in
one makes the page's Flight data untrusted: readPage reads the page
without it, and the route answers 502, private, no-store. Scripts a
browser runs (svg, MathML's text integration points, an html
annotation-xml) are read as before; Next writes its own at the body's
top level, and no fixture or corpus page has one where it doesn't run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejkorol
ejkorol merged commit 29a4853 into main Nov 17, 2026
8 checks passed
@ejkorol
ejkorol deleted the ejkorol/md-faster-conversion branch November 17, 2026 15:36
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.

1 participant