Skip to content

Conversation

@DarkMatter-999
Copy link
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
Copy link

vercel bot commented Oct 4, 2025

@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
Copy link

vercel bot commented Oct 4, 2025

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

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

Thanks 💯

Copy link
Contributor

@calculuschild calculuschild left a comment

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))
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