Skip to content

fix: fall back to default checkbox renderer when extension returns false#4023

Merged
UziTech merged 1 commit into
markedjs:masterfrom
sarathfrancis90:fix-checkbox-renderer-extension-fallback
Jul 24, 2026
Merged

fix: fall back to default checkbox renderer when extension returns false#4023
UziTech merged 1 commit into
markedjs:masterfrom
sarathfrancis90:fix-checkbox-renderer-extension-fallback

Conversation

@sarathfrancis90

Copy link
Copy Markdown
Contributor

Markdown flavor: GitHub Flavored Markdown

A renderer extension named after a built-in token can return false to fall back to the default renderer — that's the documented contract in USING_PRO, and it works for code, heading, text and the rest. It doesn't work for checkbox: the checkbox silently disappears instead.

const marked = new Marked({
  extensions: [{
    name: 'checkbox',
    renderer(token) {
      return token.checked ? false : '<span class="todo"></span> ';
    },
  }],
});

marked.parse('- [x] one\n- [ ] two\n');

I expected the checked item to fall back to the default <input checked="" disabled="" type="checkbox">, but it renders as just <li>one</li>. The unchecked item never returns false, and it renders fine, so only the fallback path is broken.

Parser decides whether a false return should fall through to the built-in renderer by testing the token type against a hardcoded list of built-in type names. checkbox was added to both parse switches in #3755 but never to either list, so the fallback branch is unreachable for it and the ret || '' path wins.

Added checkbox to the block and inline lists. Both matter in practice: a tight list puts the checkbox token at block level while a loose list puts it inline, so there's a test for each.

Contributor

  • Tests added (checkbox extension fallback, tight and loose list)
  • No new feature to document

A renderer extension named after a built-in token can return false to
fall back to the default renderer. The Parser decides that from a list
of built-in token type names, and 'checkbox' was never added to either
the block or the inline list when the checkbox token was introduced.

The result is that a `checkbox` renderer extension returning false
emits nothing instead of falling back, so the checkbox silently
disappears from the task item.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

@sarathfrancis90 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 Jul 18, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Jul 18, 2026 2:31pm

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 requested review from calculuschild and styfle July 18, 2026 14:31
@UziTech
UziTech merged commit e1b6139 into markedjs:master Jul 24, 2026
8 checks passed
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