Skip to content

fix: Fix backtick and code rendering in links - #3783

Merged
UziTech merged 5 commits into
markedjs:masterfrom
basilaiman:fix/backtick-in-links
Oct 7, 2025
Merged

fix: Fix backtick and code rendering in links#3783
UziTech merged 5 commits into
markedjs:masterfrom
basilaiman:fix/backtick-in-links

Conversation

@basilaiman

Copy link
Copy Markdown
Contributor

Marked version: 16.3.0

Markdown flavor: CommonMark

Description

Fixes rendering of code spans with backticks inside link text.

When a link contains a code span with backticks inside. The code span was being tokenized separately from the link, resulting in malformed HTML output.

Example

[`` this is a backtick ` and it breaks stuff ``](https://example.com)

Expectation

<p><a href="https://example.com"><code>this is a backtick ` and it breaks stuff</code></a></p>

Result

<p>[<code>this is a backtick ` and it breaks stuff</code>](<a href="https://example.com">https://example.com</a>)</p>

What was attempted

Updated the _inlineLabel pattern to match the proper code span syntax that handles multiple backticks as delimiters:

`+[^`]*?`+(?!`)

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel

vercel Bot commented Oct 3, 2025

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @basilaiman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical parsing bug in Markdown rendering where code spans containing backticks within link text were not correctly processed, resulting in invalid HTML. By refining the regular expression responsible for identifying inline labels, the change ensures that these complex Markdown structures are accurately interpreted and rendered, significantly improving the robustness and correctness of the Markdown parser. The inclusion of new test cases, particularly for ReDoS vulnerabilities, further strengthens the stability of the parsing logic.

Highlights

  • Fix Rendering of Code Spans in Links: This pull request resolves an issue where code spans containing backticks within link text were incorrectly parsed, leading to malformed HTML output. The fix ensures proper rendering of such Markdown constructs.
  • Updated _inlineLabel Regular Expression: The core of the fix involves modifying the _inlineLabel regular expression in src/rules.ts. The updated regex now correctly handles code spans that use multiple backticks as delimiters, ensuring they are properly recognized within link labels.
  • Added Comprehensive Test Cases: New test files have been introduced to validate the fix and prevent regressions. These include specific tests for links with internal backticks (backticks_in_links.md/.html) and several ReDoS (Regular Expression Denial of Service) test cases (backticks_alternating_in_link.md/.html, backticks_in_link_label.md/.html) to ensure the updated regex is performant and secure.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request aims to fix an issue with rendering code spans that contain backticks within link labels. While the intention is correct and new tests have been added to cover this scenario, the regular expression change in src/rules.ts appears to be flawed. It does not correctly handle code spans with backticks inside them, which contradicts the goal of this PR. I've left a specific comment detailing the issue with the regex.

Comment thread src/rules.ts

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

@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 5:21am

@UziTech
UziTech merged commit 302ee59 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))
@basilaiman
basilaiman deleted the fix/backtick-in-links branch October 7, 2025 07:52
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.

A backtick in code in a link parses incorrectly

4 participants