Skip to content

Fix bracket escapes inside code spans in link text being stripped - #4205

Merged
UziTech merged 3 commits into
markedjs:masterfrom
hakarrr:fix-4176-link-text-codespan-escape
Nov 13, 2026
Merged

UziTech merged 3 commits into
markedjs:masterfrom
hakarrr:fix-4176-link-text-codespan-escape

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Fixes the first of the two symptoms in #4176 (see "What remains" below - this does not close the issue).

Problem

The link label matcher consumes backslash-escaped brackets when finding the end of a link's text, and outputLink then removes those escapes with a blanket cap[1].replace(rules.other.outputLinkReplace, '$1') over the whole label. That also strips \[ / \] escapes inside code spans, even though code span content is literal:

[`\]`](u)

rendered <code>]</code> instead of <code>\]</code> (the backslash is dropped).

Fix

outputLink now unescapes brackets through a small scanner (unescapeLinkLabel) that copies code spans through verbatim (matched at the current position with the existing rules.inline.code) and only unescapes \[ / \] outside of them. Behavior outside code spans is unchanged.

[`\]`](u)   -> <p><a href="u"><code>\]</code></a></p>
[`\[`](u)   -> <p><a href="u"><code>\[</code></a></p>
![`\]`a](u) -> <p><img src="u" alt="\]a"></p>

Labels that already worked ([`a]b`](u), [a\]b](u), [ ` ](u) ) render identically to before.

What remains (out of scope here)

The other symptom in #4176, [`c`]`](u) not linkifying at all (a backtick-quoted label containing `), is a separate label-matching issue and is intentionally not addressed by this PR.

Tests

New test/specs/new/link_text_codespan_backslash.md / .html pair covering both link-text cases and the image alt-text case; they fail on current master and pass with the fix. Full npm test suite passes.

hakarrr and others added 3 commits November 9, 2026 11:14
The link label matcher consumes backslash-escaped brackets, and outputLink then removes those escapes from the label text. It did so over the whole label, so a backslash-escaped bracket inside a code span also lost its backslash even though code span content is literal: [`\]`] rendered <code>]</code> instead of <code>\]</code>.

Scan the label and copy code spans through verbatim, unescaping brackets only outside of them.

Refs markedjs#4176

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Refs markedjs#4176

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Refs markedjs#4176

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown

@hakarrr 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 10, 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 10, 2026 3: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.

Thanks! 💯

@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the approval. Is there anything else needed from me before this can move forward, or any maintainer-side step it is waiting on?

@UziTech
UziTech merged commit 9a26ae9 into markedjs:master Nov 13, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 16, 2026
## [18.2.1](v18.2.0...v18.2.1) (2026-11-16)

### Bug Fixes

* allow tabs between the tag name and attributes of an html block ([#4207](#4207)) ([738ebeb](738ebeb))
* **cli:** wait for stdout before exiting ([#4197](#4197)) ([b535046](b535046))
* continue a block quote paragraph with a lazy line that starts an html tag ([#4202](#4202)) ([8a578e4](8a578e4))
* end a block quote at a lazy line after an empty list item ([#4178](#4178)) ([e2f77b4](e2f77b4))
* end a list item before a lazy line after an empty or non-paragraph nested block ([#4183](#4183)) ([ac2256e](ac2256e))
* Fix bracket escapes inside code spans in link text being stripped ([#4205](#4205)) ([9a26ae9](9a26ae9)), closes [#4176](#4176) [#4176](#4176) [#4176](#4176)
* keep a tab after the block quote marker's space literal ([#4208](#4208)) ([2d3b47f](2d3b47f))
* keep rejected table candidates in the preceding paragraph ([#4218](#4218)) ([1c5969e](1c5969e))
* keep tabs that are code content under a block quote ([#4217](#4217)) ([d2c6f73](d2c6f73)), closes [#4184](#4184)
* let a mid-run opener close against a delimiter that can also open ([#4203](#4203)) ([06e1d10](06e1d10))
* let an autolink or inline html line start or continue a setext heading ([#4191](#4191)) ([72d0fec](72d0fec))
* parse links generated by inline tokenizers ([#4204](#4204)) ([0460f98](0460f98))
* preserve trailing blank lines in fenced code ([#4200](#4200)) ([7499eb3](7499eb3))
* reject a link destination in angle brackets with an unescaped < or > ([#4206](#4206)) ([de71210](de71210))
* remove a task item's checkbox marker from its own text ([#4215](#4215)) ([5902442](5902442))
* **types:** preserve custom output types in tokenizer overrides ([#4214](#4214)) ([5e35708](5e35708))

### Performance Improvements

* check the first character before inline tokenizer regexes ([#4193](#4193)) ([95ccf6c](95ccf6c))
* close residual O(n²) parse time on unmatched emphasis/strikethrough delimiter runs (follow-up to [#4099](#4099) / [#4103](#4103)) ([#4196](#4196)) ([0b8b3b3](0b8b3b3))
* skip the emphasis closer scan for inline runs without a delimiter ([#4195](#4195)) ([ffa06d5](ffa06d5))

This branch was successfully deployed

1 active deployment
Preview — 25c167a7 Deployed Nov 10, 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.

3 participants