Skip to content

Conversation

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

vercel bot commented Oct 3, 2025

@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

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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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.

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

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