Skip to content

馃悰 FIX: texmath infinite loop on block math closed outside blockquote - #157

Open
acaprino wants to merge 1 commit into
executablebooks:masterfrom
acaprino:fix-texmath-blockquote-loop
Open

acaprino wants to merge 1 commit into
executablebooks:masterfrom
acaprino:fix-texmath-blockquote-loop

Conversation

@acaprino

Copy link
Copy Markdown

Fixes #156.

make_block_func in texmath/index.py matched each block rule's regex against the rest of the source, so a block opened inside a blockquote could match a closing delimiter placed after it. The rule then pushed a token and returned True without advancing state.line, and the block tokenizer looped forever:

MarkdownIt("commonmark").use(texmath_plugin).parse("> $$ a=1\n\n$$\n")  # never returned

Change

  • The closing line is searched only within [begLine, endLine). If the match ends outside the current block, the rule returns False before pushing any token. It does not auto-close, which is how amsmath behaves since Infinite loop in amsmath extension for a simple input聽#117. The example above now renders $$ a=1 as a paragraph in the blockquote, followed by $$ as a paragraph.
  • When the closing line is inside the block, nothing changes: the same line is found and the token is identical.

Tests

  • Fixtures in texmath_dollar.md and texmath_bracket.md: blockquote, and blockquote inside a list item.
  • test_block_closed_outside_blockquote, one case per delimiter set (brackets, dollars, kramdown, gitlab, julia). Without the fix these tests hit the pytest timeout.
  • Full suite passes locally (519 tests), along with ruff check, ruff format --check and mypy mdit_py_plugins.

The CHANGELOG.md entry opens an Unreleased section, like #148 does, so the two PRs will conflict trivially there.

馃 Generated with Claude Code

https://claude.ai/code/session_01UQqBAyRu8anrLPy829yMmV

The texmath block rules matched their regex against the rest of the source,
so a block opened inside a blockquote could match a closing delimiter placed
after it. The rule then pushed a token and returned True without advancing
`state.line`, and the block tokenizer looped forever.

The closing line is now searched within the current block only; otherwise
the rule does not match, as in `amsmath` (executablebooks#117).

Fixes executablebooks#156

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UQqBAyRu8anrLPy829yMmV
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.

texmath: infinite loop on block math opened in a blockquote and closed after it

1 participant