Skip to content

fix: preserve code spans adjacent to tildes#4012

Open
Hona wants to merge 3 commits into
markedjs:masterfrom
Hona:fix-tilde-codespan
Open

fix: preserve code spans adjacent to tildes#4012
Hona wants to merge 3 commits into
markedjs:masterfrom
Hona:fix-tilde-codespan

Conversation

@Hona

@Hona Hona commented Jul 8, 2026

Copy link
Copy Markdown

Marked version: master / 18.0.5

Markdown flavor: GitHub Flavored Markdown

Description

  • Fixes Inline code after a tilde is parsed with shifted backticks #4011
  • Keep adjacent tilde and backtick delimiter runs separate so complete code spans remain available to the code-span tokenizer.
  • Keep delimiter handling in the selected GFM text grammar and stop immediately at mixed delimiter boundaries.
  • Cover both delimiter orders, multi-backtick code spans, and code nested in strikethrough.

Contributor

  • Test(s) exist to ensure functionality and minimize regression.
  • No documentation change is required because this restores existing GFM parsing behavior.

Committer

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

  • CI is green (no forced merge required).
  • Squash and Merge PR following conventional commit guidelines.

Copilot AI review requested due to automatic review settings July 8, 2026 01:35
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a GFM inline parsing edge case where a literal ~ immediately adjacent to backtick runs could cause the inline “text” rule to consume part of a code span opener/closer, leading to shifted/incorrect code span pairing (as described in #4011).

Changes:

  • Adjusted the GFM inline text regex to keep adjacent tilde and backtick delimiter runs separate (\+vs~+`), so the codespan tokenizer still sees complete backtick runs.
  • Added a new spec test covering both delimiter orders, multi-backtick code spans, and code nested in strikethrough.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/specs/new/codespan_adjacent_tilde.md Adds markdown fixtures reproducing the adjacency cases that previously broke codespan pairing.
test/specs/new/codespan_adjacent_tilde.html Adds expected HTML output for the new adjacency fixtures to prevent regressions.
src/rules.ts Updates the GFM inline text rule so it no longer collapses mixed `/~ runs into a single token that can hide codespan delimiters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Jul 8, 2026 2:06pm

Request Review

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.

Inline code after a tilde is parsed with shifted backticks

2 participants