Repository navigation
Citation scanner respects inline code-span boundaries - #53
Merged
Merged
Conversation
The bracket branch of the citation rule regex-scans the raw text between [ and ] before the tokenizer ever reaches enclosed backticks, so an @-token inside a code span became a broken cite node that swallowed the bracket text and code formatting. Compute CommonMark code-span ranges within the bracket and back off when a matched @ falls inside one; legitimate keys elsewhere in the bracket still cite, and the in-text @ rule is unaffected (positions inside code spans are never rule starts). Fixes #46 Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Updates markdown-it-myst’s bracket citation auto-detector to respect CommonMark inline code-span boundaries, preventing @key-like tokens inside backticks from being mis-parsed as citations (fixes #46).
Changes:
- Add a code-span range scanner for bracket contents and abort bracket-citation parsing when the matched
@is inside a code span. - Expand citation token tests to cover inline-code
@tokens, double-backtick spans, escaped backticks, and mixed cite/code cases. - Add a patch changeset describing the behavioral fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/markdown-it-myst/src/citations.ts | Adds codeSpanRanges() and uses it to guard bracket citation parsing against @ inside inline code spans. |
| packages/markdown-it-myst/tests/citations.yml | Adds regression tests covering code-span-contained @ tokens and mixed citation/code scenarios. |
| .changeset/cite-code-span.md | Records a patch release note for the citation parsing fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 12, 2026
mmcky
added a commit
to QuantEcon/claude-latex-to-myst
that referenced
this pull request
Jun 12, 2026
The warning was fixed upstream in the publisher: the qe mystmd fork's citation scanner now respects inline code-span boundaries (QuantEcon/mystmd#53, merged 2026-06-12), so the `@tf.function` inside a code span in ch02_deqns no longer parses as a broken cite node. The warning's disappearance during the #144-#147 close-out was initially read as build flakiness on byte-identical input — it was actually the local myst binary picking up the fix. Re-baselining locks the improvement: a reappearance now fails the render gate. Co-authored-by: Claude Fable 5 <[email protected]>
mmcky
added a commit
that referenced
this pull request
Jun 12, 2026
* Track PR #53 (cite-code-span) in VERSION.yml and UPSTREAM-PRS.yml Records squash commit 00740bc as merged feature 9 (tag pending) and adds a standalone upstream candidate carrying the upstream-context notes from #54 (escaping cannot cover code spans; precedent in jupyter-book#2684 and jupyter-book#2891). Co-Authored-By: Claude Fable 5 <[email protected]> * Reword "un-escapable" in cite-code-span candidate notes Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
This was referenced Jun 12, 2026
mmcky
added a commit
to QuantEcon/claude-latex-to-myst
that referenced
this pull request
Jun 13, 2026
#151) (#153) * ci: render gate — run build_smoke.py per book in Job 2 on a pinned mystmd fork (#151) CI gated on the unit suite, both golden tiers, the differential gate, and the per-book count diff — but never ran `myst build`, so output passing every structural check could still fail as a product (lesson 046: structural parity is not render parity). Job 2 (fixture-counts, label-gated, non-blocking) now runs the existing render gate per book after the count check: build_smoke.py overlays regen onto the worked-on mystmd/, runs `myst build --html`, and multiset-diffs normalized warnings against tests/baselines/build-<book>.txt (dp1's empty baseline is the zero-warning contract; any NEW warning line fails). The build uses a pinned QuantEcon/mystmd FORK ref (MYSTMD_REF = d1a942ca, v1.10.1 qe-v8) — not upstream npm mystmd: the committed baselines assume fork behavior (qe-v5 book-mode numbering, fancy lists from QuantEcon/mystmd#50, the cite-scanner fix from QuantEcon/mystmd#53). The qe-v8 *tag* builds v1.9.1, so the pin is the exact main SHA the baselines were validated against. The fork CLI bundles to one self-contained dist/myst.cjs, cached keyed on the ref so repeat runs skip the clone + bun + turbo build. init+fetch (not clone --branch) so the ref can be a tag or a bare SHA. Verified locally with the exact CI recipe: fetch d1a942ca, bun install --frozen-lockfile, bun run build -> myst.cjs reports "v1.10.1 (qe-v8)"; build_smoke --check passes all three books (dp1 0 / dp2 3 / deep-learning 18 baseline lines, exact match). Deferred from the issue (recorded there): the always-on Job-1 mini-project smoke and the pdftotext numbering comparison. Closes #151. Co-Authored-By: Claude Fable 5 <[email protected]> * ci: trigger Job 2 with fixture-check label applied Co-Authored-By: Claude Fable 5 <[email protected]> * ci: install bun via pinned oven-sh/setup-bun, not curl|bash Copilot review: the job pins pandoc and MYSTMD_REF but installed bun unpinned from bun.sh — runner drift could pull a different bun. Pin bun-version to 1.3.10, the fork's own packageManager declaration. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #46
What
The citation auto-detector's bracket branch regex-scans the raw text between
[…]for pandoc@keytokens. Because thecitationinline rule intercepts[before the tokenizer ever reaches the backticks inside, a fully code-span-enclosed@-token likebecame a broken
citenode (label: tf.function, backtick swallowed into the prefix text), destroying the bracket text and code formatting — plus an unresolved-citation warning.How
In
markdown-it-myst's citation rule, compute the CommonMark inline code-span ranges within the bracket content (backtick-run matching: a span opened by N backticks closes only at the next run of exactly N; escaped backticks don't open spans) and back off the bracket-citation parse when a matched@falls inside one.Notes on scope:
@branch needs no guard: the tokenizer never visits positions inside a code span, so`@tf.function`outside brackets was already safe (confirmed by the issue's control line).[@real; `@code`]the bracket parse is rejected but@realstill cites via the in-text rule and the code span survives.[see @smith2021 and `@tf.function`]) still citessmith2021— the matched@is outside any span, and the suffix'sparseInlinetokenizes the code span correctly.Relation to upstream
jupyter-book#1618 tracks the overzealous-
@class for the[@handle](url)link shape (already guarded here by thecharAfter != 0x28check and the fork'sisLinkContext/isUrlContextguards). This PR addresses the inline-code shape with a code-span-boundary guard rather than the link-label heuristic — a separate, complementary fix and an upstream candidate.Testing
packages/markdown-it-myst/tests/citations.yml: the issue repro, citation-with-code-span-suffix, the degraded[@real;@code]case, double-backtick spans, and escaped backticks (which must not suppress citation).**\[NEW: …escaping workaround becomes unnecessary once this lands.🤖 Generated with Claude Code