Skip to content

fix: preserve code spans adjacent to tildes - #4012

Merged
UziTech merged 3 commits into
markedjs:masterfrom
Hona:fix-tilde-codespan
Jul 14, 2026
Merged

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

Conversation

@Hona

@HonaHona commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Marked version: master / 18.0.5

Markdown flavor: GitHub Flavored Markdown

Description

  • FixesInline 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.

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

vercelBot 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.

CopilotAI 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.

FileDescription
test/specs/new/codespan_adjacent_tilde.mdAdds markdown fixtures reproducing the adjacency cases that previously broke codespan pairing.
test/specs/new/codespan_adjacent_tilde.htmlAdds expected HTML output for the new adjacency fixtures to prevent regressions.
src/rules.tsUpdates 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

vercelBot commented Jul 8, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
marked-websiteReadyReadyPreview, CommentJul 8, 2026 2:06pm

Request Review

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

Nice catch! Thanks 💯

@UziTech

Copy link
Copy Markdown
Member

I think we should merge this. @styfle any objections?

@Hona

Hona commented Jul 14, 2026

Copy link
Copy Markdown
ContributorAuthor

Oops - yeah that workaround PR was not meant to close this PR

@UziTech
UziTech merged commit 0de7188 into markedjs:masterJul 14, 2026
13 checks passed
github-actionsBot pushed a commit that referenced this pull request Jul 21, 2026
## [18.0.7](v18.0.6...v18.0.7) (2026-07-21)
### Bug Fixes
* Avoid O(n^2) backtracking in HTML block close and tilde interrupt regexes ([#4014](#4014)) ([f945fc5](f945fc5)), closes [#3991](#3991)
* Avoid O(n^2) masked source rebuild in inline tokenizer ([#4017](#4017)) ([9154f8f](9154f8f))
* keep empty list after blockquote as a sibling block ([#4004](#4004)) ([3f144a0](3f144a0))
* preserve code spans adjacent to tildes ([#4012](#4012)) ([0de7188](0de7188))
* Recognize setext headings whose first line starts with # ([#4015](#4015)) ([f056437](f056437)), closes [#1](#1)
* treat a line of only tabs as a blank line between paragraphs ([#4007](#4007)) ([bc2f121](bc2f121))
Sign up for freeto 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

4 participants

@Hona@UziTech@styfle