Repository navigation
Bump markdown-it to 15.0.1 - #639
Conversation
Restores the patch-package tooling (prebuild script and devDependency) so the allowIndentation patch can be regenerated against the new version in a follow-up commit. Committed-By-Agent: claude
markdown-it 15 ships bundled dist/markdown-it.cjs.js and .mjs files instead of the old per-rule lib/*.js files, so the patch now targets the same 16 indentation guards in both bundled files rather than the individual rule modules. Committed-By-Agent: claude
markdown-it 15 ships its own TypeScript types and no longer exposes markdown-it/lib/token as an augmentable module path, so the global.d.ts declaration merging no longer works. Define Markdoc's own loose Token shape in src/types.ts instead; consuming files are updated to use it in the next commit. Committed-By-Agent: claude
Switch these files from importing Token off markdown-it/lib/token to the local Token type, and add optional chaining/fallbacks for fields (tag, attrs, info, nesting) that the new type marks as optional. Committed-By-Agent: claude
markdown-it 15 drops the /lib subpath exports (markdown-it/lib, markdown-it/lib/rules_block/state_block, etc.) in favor of named exports off the main markdown-it module, and MarkdownIt.Options was renamed to MarkdownItOptions. Update the tokenizer and its plugins (annotations, comments, frontmatter, link) accordingly. Committed-By-Agent: claude
maxblank-stripe
left a comment
There was a problem hiding this comment.
Are the optional token properties coming from updated markdown-it library or because we defined them as optional in src/types.ts? My main concerns is using non-null assertion operator for those optional properties.
| const start = token.info.indexOf(OPEN); | ||
| const end = findTagEnd(token.info, start); | ||
| const content = token.info.slice(start + OPEN.length, end); | ||
| if (token.info!.includes(OPEN)) { |
There was a problem hiding this comment.
is token.info optional here? should we have a check above to prevent "Cannot read property includes of undefined"?
There was a problem hiding this comment.
Yeah, this is in part an issue due to how we were previously typing this information through global module augmentation. I've updated this code so typing information is easier to understand.
| continue; | ||
|
|
||
| token.children = parseTags(token.content, token.map[0]); | ||
| token.children = parseTags(token.content!, token.map![0]); |
There was a problem hiding this comment.
same for token.content and token.map, how come they're optional now?
There was a problem hiding this comment.
#639 (comment) helps explain this a bit, I believe this is also an issue caused by removal of global.d.ts module augmentation. So we have to do a bit more type checking on our end :)
| switch (type) { | ||
| case 'heading': | ||
| return { level: Number(token.tag.replace('h', '')) }; | ||
| return { level: Number((token.tag ?? '').replace('h', '')) }; |
There was a problem hiding this comment.
if token.tag is undefined, level would be 0, which is invalid heading.
There was a problem hiding this comment.
Changed it to token.tag!.
| let align; | ||
| if (attrs.style) { | ||
| if (attrs.style.includes('left')) { | ||
| const style = String(attrs.style); |
There was a problem hiding this comment.
just curious, what's the TS type of attrs.style?
Review feedback pointed out that the non-null assertions added for markdown-it 15 were masking real distinctions: some fields (info, content, tag) are always set on real markdown-it tokens and never needed loosening, while map is genuinely nullable and deserved a guard instead of a silent assertion. The heading/fence `?? ''` fallbacks were also risky since they could produce a bogus level 0 heading instead of surfacing a real problem. Committed-By-Agent: claude
CI's lint step flagged it — the FenceToken type ended up using Pick<Token, 'errors'> instead of referencing ValidationError directly. Committed-By-Agent: claude
An `as FenceToken[]` cast on the whole tokens array hid that no unsafe narrowing was actually needed: FenceToken only adds optional fields on top of markdown-it's real Token, so the compiler can verify the widening on its own via a plain variable declaration. Committed-By-Agent: claude
Committed-By-Agent: claude
Reviewers asked why this type exists rather than just using markdown-it's Token directly; note the prior module-augmentation approach for context on why this local type is needed instead. Committed-By-Agent: claude


Summary
Upgrades markdown-it from 12.3.2 to 15.0.1 and updates Markdoc's tokenizer/type layer to match its new API and shipped types.
markdown-it/lib/*subpath imports, soTokenizerand the plugins (annotations,comments,frontmatter,link) now import types off the mainmarkdown-itmodule (MarkdownIt.StateBlock,MarkdownIt.MarkdownItOptions, etc.).markdown-it/lib/tokenmodule path we were augmenting inglobal.d.ts. Replaced that global augmentation with a localTokentype insrc/types.tsthat covers both real markdown-it tokens and Markdoc's own lightweight pseudo-tokens, and added the null-safety (token.tag ?? ...,token.attrs ?? [], etc.) the new optional fields require.allowIndentationpatch, regenerated for 15.0.1. markdown-it 15 ships bundleddist/markdown-it.cjs.js/.mjsinstead of per-rulelib/*.jsfiles, so the patch now guards the same 16 call sites in both bundled files instead of across nine small modules. Restoredpatch-packageas a devDependency and theprebuildscript that applies it.Why the patch is still needed
We looked at dropping the patch instead of porting it, since patches on bundled files are more brittle across upgrades. Without it,
marktestfails: markdown-it treats 4+ spaces of leading indentation as a code block, which conflicts with content Markdoc needs to parse as regular blocks. Re-applying the patch unblocks this upgrade; longer-term we should look at upstreaming a proper option for this instead of patching bundled internals every version bump.Test plan
npm run build(patch applies cleanly viaprebuild)npm test— 267 specs, 0 failuresnpm run marktest— passes with the patch applied