Skip to content

fix: parse links generated by inline tokenizers - #4204

Merged
UziTech merged 1 commit into
markedjs:masterfrom
jaredrainsha:fix/nested-extension-generated-links
Nov 16, 2026
Merged

UziTech merged 1 commit into
markedjs:masterfrom
jaredrainsha:fix/nested-extension-generated-links

Conversation

@jaredrainsha

Copy link
Copy Markdown

Marked version: 7bfa1f70e8756c6ee3e47c235a34556edbf48b49 (18.1.3)

Markdown flavor: n/a (extension API)

Description

An inline tokenizer can pass generated text to this.lexer.inlineTokens(). If the original inline input has no ), the nested tokenizer inherits the outer link fast-fail flag even when the generated text contains a link. For example:

import { Marked } from 'marked';

const marked = new Marked({
  extensions: [{
    name: 'mention',
    level: 'inline',
    tokenizer(src) {
      if (src.startsWith('@alice')) {
        return {
          type: 'mention',
          raw: '@alice',
          tokens: this.lexer.inlineTokens('[alice](/users/alice)'),
        };
      }
    },
    renderer(token) {
      return this.parser.parseInline(token.tokens);
    },
  }],
});

marked.parseInline('@alice');
// Before: '[alice](/users/alice)'
// After:  '<a href="/users/alice">alice</a>'

Each inline run now checks its own input once and restores the outer flag on return. The existing fast-fail for unterminated links remains in place. Marked demo for the generated Markdown shows the expected rendering; the extension itself cannot be represented in the demo URL.

Verification

  • Seven new regression cases: 5 failed and 2 passed on the unmodified baseline; all 7 pass with the fix.
  • npm test on Node 25.9.0 and Node 26.12.0: 1,989 spec tests and 249 unit tests passed, along with build, UMD/CJS, types, and lint. Tests ran from a path without spaces because the existing CLI tests construct unquoted shell commands.
  • Node 20.20.2: npm run build, npm run test:unit, npm run test:specs, and npm run test:cjs passed.
  • Existing large reference-link and unterminated-link performance cases produced identical output and similar timings before and after the change.

OpenAI Codex assisted with investigation, implementation, and validation.

Contributor

  • Tests exist to ensure functionality and minimize regression.
  • If submitting a new feature, it has been documented in the appropriate places.

Committer

  • CI is green (no forced merge required).
  • Squash and merge following conventional commit guidelines.

@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown

@jaredrainsha is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
marked-website Ready Ready Preview Nov 9, 2026 5:52am UTC

Request Review

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! 💯

@UziTech
UziTech merged commit 0460f98 into markedjs:master Nov 16, 2026
11 of 13 checks passed

This branch was successfully deployed

1 active deployment
Preview — fe04d164 Deployed Nov 9, 2026 by vercel[bot]
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.

2 participants