Skip to content

fix(lint): close display math on more than a bare $$ line - #1149

Open
ChrisJr404 wants to merge 1 commit into
vale-cli:v3from
ChrisJr404:fix/display-math-closing
Open

fix(lint): close display math on more than a bare $$ line#1149
ChrisJr404 wants to merge 1 commit into
vale-cli:v3from
ChrisJr404:fix/display-math-closing

Conversation

@ChrisJr404

Copy link
Copy Markdown

Recognize every place Pandoc closes a $$…$$ display-math block, so an equation no longer leaves the block open and hides the rest of the file from linting.

Since v3.15.2 (#878) display math is parsed by goldmark-mathjax's block parser, which only closes the block on a line that contains nothing but $$. That misses the ordinary Pandoc shapes reported in #1148:

  • $$x=1$$ — opener and closer on one line
  • $$\begin{aligned} … \end{aligned}$$ — the closing $$ ends a content line
  • $$ … $$ {#eq-foo} — a Pandoc/Quarto cross-reference label after the close

In each case the block stays open, and an open block consumes everything to the end of the document, so all the prose past the equation goes unchecked.

Rather than patch around the third-party parser, this replaces it with an in-tree block parser — the same move already made for inline math, and for the reason the file's comment already gives. The new parser produces the same mathjax.MathBlock node the renderer knows how to skip, keeps a bare $$ line as markup exactly as before, and additionally closes on an opener that also closes, on a content line ending in $$, and after an optional trailing {…} label.

Testing

internal/lint/math_test.go gains TestMathBlock, which runs each shape above (plus the existing bare-$$ block, to pin that it still behaves) through the Quarto renderer and asserts both that the equation renders as skipped pre and that the paragraph after it survives as prose. go test ./internal/lint/ and golangci-lint run ./internal/lint/ both pass.

Closes #1148.

goldmark-mathjax's block parser only ever closed `$$…$$` display math on a
line that held nothing but `$$`. Every other Pandoc shape -- an opener that
also closes (`$$x=1$$`), a content line ending in `$$` (`\end{aligned}$$`),
and a `$$ … $$ {#eq-foo}` label -- left the block open, and an unclosed block
consumes the rest of the file, so everything after the equation went unlinted.

Replace it with an in-tree block parser, as was already done for inline math,
that recognizes each of those closes while still keeping the bare-`$$` line as
markup. Closes vale-cli#1148.
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.

Markdown: display math only closes on a bare $$ line, so many $$…$$ forms silently swallow the rest of the file

1 participant