Skip to content

bug: fix links with square brackets in inline code break wrapping italics - #3785

Merged
UziTech merged 2 commits into
markedjs:masterfrom
DarkMatter-999:fix/em-link-brackets
Oct 7, 2025
Merged

bug: fix links with square brackets in inline code break wrapping italics#3785
UziTech merged 2 commits into
markedjs:masterfrom
DarkMatter-999:fix/em-link-brackets

Conversation

@DarkMatter-999

Copy link
Copy Markdown
Contributor

Marked version: 16.3.0 / master

Markdown flavor: CommonMark

Description

Expectation

The following Markdown:

_[a[b]c](http://example.com/_/path)_

to be parsed into an emphasized link whose text is a codespan. In HTML this should be:

<p><em><a href="http://example.com/_/path"><code>a[b]c</code></a></em></p>

Result

Before the change Marked produced a broken output where the emphasis was split and the link text/URL were parsed separately. The produced HTML looked like:

<p><em>[<code>a[b]c</code>](http://example.com/</em>/path)_</p>

What was attempted

Updated the em/strong masking pattern so link text that contains a codespan is treated as a single block to be skipped by the em/strong tokenizer.

  • Changed the blockSkip regex in marked/src/rules.ts so bracketed link text may include backtick codespans (allowing patterns like [`a[b]c`] inside []) and thus be masked as a unit for em parsing.

  • Added spec tests:

    • test/specs/new/em_link_brackets.md
    • test/specs/new/em_link_brackets.html

With that change, the inline tokenizer no longer sees the _ delimiter split across the link and URL, so the emphasis wrapping the link is preserved and the output matches the expectation.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,

@vercel

vercel Bot commented Oct 4, 2025

Copy link
Copy Markdown

@DarkMatter-999 is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

@DarkMatter-999
DarkMatter-999 marked this pull request as ready for review October 4, 2025 08:14
@vercel

vercel Bot commented Oct 4, 2025

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
marked-website Ready Ready Preview Comment Oct 4, 2025 6:51pm

@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 💯

@calculuschild calculuschild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

@UziTech
UziTech merged commit e3c0d3e into markedjs:master Oct 7, 2025
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2025
# [16.4.0](v16.3.0...v16.4.0) (2025-10-07)

### Bug Fixes

* Fix backtick and code rendering in links ([#3783](#3783)) ([302ee59](302ee59))
* fix links with square brackets in inline code break wrapping italics ([#3785](#3785)) ([e3c0d3e](e3c0d3e))
* Make `www` case-sensitive when detecting link starts ([#3770](#3770)) ([626d961](626d961))

### Features

* Add async provideParser provideLexer ([#3756](#3756)) ([09577e5](09577e5))
vaernion pushed a commit to Arbeidstilsynet/brevgen2 that referenced this pull request Dec 3, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [marked](https://marked.js.org) ([source](https://github.com/markedjs/marked)) | [`16.3.0` -> `16.4.0`](https://renovatebot.com/diffs/npm/marked/16.3.0/16.4.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/marked/16.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/marked/16.3.0/16.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>markedjs/marked (marked)</summary>

### [`v16.4.0`](https://github.com/markedjs/marked/releases/tag/v16.4.0)

[Compare Source](markedjs/marked@v16.3.0...v16.4.0)

##### Bug Fixes

- Fix backtick and code rendering in links ([#&#8203;3783](markedjs/marked#3783)) ([302ee59](markedjs/marked@302ee59))
- fix links with square brackets in inline code break wrapping italics ([#&#8203;3785](markedjs/marked#3785)) ([e3c0d3e](markedjs/marked@e3c0d3e))
- Make `www` case-sensitive when detecting link starts ([#&#8203;3770](markedjs/marked#3770)) ([626d961](markedjs/marked@626d961))

##### Features

- Add async provideParser provideLexer ([#&#8203;3756](markedjs/marked#3756)) ([09577e5](markedjs/marked@09577e5))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or PR is renamed to start with "rebase!".

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Related work items: #30372
Logiclayer1111 pushed a commit to Logiclayer1111/marked that referenced this pull request Apr 20, 2026
# [16.4.0](markedjs/marked@v16.3.0...v16.4.0) (2025-10-07)

### Bug Fixes

* Fix backtick and code rendering in links ([#3783](markedjs/marked#3783)) ([78037b8](markedjs/marked@78037b8))
* fix links with square brackets in inline code break wrapping italics ([#3785](markedjs/marked#3785)) ([dcdebc6](markedjs/marked@dcdebc6))
* Make `www` case-sensitive when detecting link starts ([#3770](markedjs/marked#3770)) ([eedf93b](markedjs/marked@eedf93b))

### Features

* Add async provideParser provideLexer ([#3756](markedjs/marked#3756)) ([e2e276c](markedjs/marked@e2e276c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link with square bracket in inline code can break wrapping italic that uses _

3 participants