Skip to content

馃悰 FIX: Preserve code spans after unclosed labels (#438) - #439

Open
SparkUiX wants to merge 1 commit into
executablebooks:masterfrom
SparkUiX:codex/fix-backtick-lookahead-438
Open

SparkUiX wants to merge 1 commit into
executablebooks:masterfrom
SparkUiX:codex/fix-backtick-lookahead-438

Conversation

@SparkUiX

Copy link
Copy Markdown

Fixes #438.

An unclosed link or image label runs inline parsing in a lookahead. The old incremental backtick cache could then claim there was no closer for a code span when the line was parsed for real, leaving valid code spans as literal backticks.

Build the last position of each backtick run length once from the whole source, independently of the parser's traversal. As in upstream markdown-it commit 5e9b1cc830, measure complete runs when a lookahead narrows posMax, so a run crossing the boundary cannot become a false closer. The existing Python code-span whitespace behavior is retained.

Regression fixtures cover unclosed link and image labels, a run crossing the link-label boundary, and code-span precedence over links. The changelog records the fix.

Validation on Windows / Python 3.12.2:

  • Before the change, the two unclosed-label fixtures failed (2 failed, 5 passed among the selected cases).
  • After the change, python -m pytest tests -q --maxfail=1 --tb=short passed: 1036 tests.
  • ruff check, ruff format --check, and mypy markdown_it/rules_inline/backticks.py passed.

The test commands used PYTHONUTF8=1 because the Windows default GBK encoding cannot read the project's CommonMark test data. The repository-root test command also collects benchmark tests that require an optional benchmark plugin; the project tests/ suite is green. CI remains to be verified.

Ported with OpenAI Codex assistance from the upstream markdown-it fix.

@SparkUiX
SparkUiX marked this pull request as ready for review September 25, 2026 06:11
Copilot AI lite review requested due to automatic review settings September 25, 2026 06:11

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.

Copilot review overview

馃煛 Changes recommended

Two moderate regression-coverage gaps remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes code-span parsing after unclosed link or image labels by making backtick-run lookup independent of parser traversal.

Changes:

  • Reworks backtick caching and boundary handling.
  • Updates inline state documentation.
  • Adds regression fixtures and a changelog entry.
File Summary
tests/鈥媡est_port/鈥媐ixtures/鈥媍ommonmark_extras.md Adds regression coverage for issue #438.
markdown_it/鈥媟ules_inline/鈥媠tate_inline.py Documents revised cache semantics.
markdown_it/鈥媟ules_inline/鈥媌ackticks.py Builds a parser-independent backtick-run cache.
CHANGELOG.md Records the fix.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +783 to +787
A longer backtick run outside a link label must not close a shorter opener.
.
[`](``)
.
<p><a href="%60%60">`</a></p>

This branch has not been deployed

No deployments
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.

An unclosed link or image label makes a later code span render as literal text (upstream markdown-it#1201, fixed in markdown-it 15.0.1)

2 participants