0015. Note Markdown is tokenized by markdown-it, not by our own parser

Status: Accepted (2026-10-01). Amends 0011.

Context

0011 replaced “markdown-it renders HTML, sanitize-html filters it, the page injects it” with a token tree that the page draws as elements and text nodes. It also dropped markdown-it, so Deckard had to read the Markdown itself. Step 1.9 of the webviews plan did that with a hand-written port of markdown-it’s rules: seven modules and 2,098 lines in src/domain/markdown/. To match what the pages showed, it ported emphasis pairing, link destinations, a 257-name entity table, and the block rules one for one.

The port matched every card and title in the comparison corpora. But it was Deckard’s to maintain, and every markdown-it quirk it copied had to be copied again whenever markdown-it changed. A fuzz comparison found places where it did not match at all: code spans after an unclosed [, and whitespace at the end of an unclosed fence. Link reference definitions, HTML5 entity names, and non-ASCII hosts were left out on purpose (Q8 of the plan).

The tree is safe because of how the page draws it. A page draws a token as a text node or an element, and a link token holds only an http, https, or mailto URL. Which parser produced the tokens does not change that. markdown-it is also the engine VS Code’s own Markdown preview uses.

Decision

Consequences

Alternatives considered