Fix cell/outline breakage after single-line display math with attributes#1063
Open
max-nothacker wants to merge 1 commit into
Open
Fix cell/outline breakage after single-line display math with attributes#1063max-nothacker wants to merge 1 commit into
max-nothacker wants to merge 1 commit into
Conversation
The single-line close check in math_block() only recognized lines ending
in "$$", so "$$1+1$$ {#eq-spec0}" fell through to the multi-line scan,
which never finds a closing line and consumes the remainder of the
document into one math token. Everything after the equation (headings,
code cells) was no longer tokenized: no outline entries, no LaTeX
preview, and "Editor selection is not within an executable cell" when
running later cells.
Recognize an optional trailing attribute block in the single-line case,
mirroring the multi-line close regex, and store it in token.info the
same way. Adds unit tests for the single-line labeled, single-line
unlabeled, and multi-line labeled cases.
Fixes quarto-dev#976
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> in the session with id 6b8b182e
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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 #976
Problem
A single-line display math expression with a cross-reference label, e.g.
breaks the extension for the rest of the document: headings disappear from the Outline, LaTeX preview buttons vanish, and later code cells lose their Run Cell button ("Editor selection is not within an executable cell").
Root cause
In
math_block()(packages/core/src/markdownit/math.ts), the single-line close check waswhich fails when an attribute block trails the closing
$$. The rule then falls through to the multi-line scan looking for/^\$\$\s*(\{.*\})?\s*$/on a later line — which never matches — so the loop runs to the end of the document and the math token swallows everything after the equation. Nothing downstream (headings, fences) is tokenized again. Full analysis in #976 (comment).Fix
Recognize an optional trailing attribute block in the single-line case, mirroring the multi-line close regex, and store it in
token.infothe same way the multi-line path does (so single-line labeled equations also pick up the math preview decoration):Unlabeled single-line math (
$$1+1$$) takes the same path it did before ((.*)is greedy, so interior$$behave as with the previousslice(-2)check), and the multi-line branch is untouched.Tests
Added
packages/core/test/markdownit-math.test.ts(same harness as the existingmarkdownit-divs.test.ts):{python}fence → onemath_blockwithinfo === "{#eq-spec0}", fence still tokenized (the Quarto extension display math edge cases stops extension functionality for rest of document #976 symptom)yarn testinpackages/corepasses (5/5), andtsc --noEmitis clean.🤖 Generated with Claude Code in the session with id 6b8b182e