Skip to content

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

Merged
chrisjsewell merged 6 commits into
executablebooks:masterfrom
acaprino:fix-texmath-blockquote-loop
Nov 9, 2026
Merged

chrisjsewell merged 6 commits into
executablebooks:masterfrom
acaprino:fix-texmath-blockquote-loop

Conversation

@acaprino

Copy link
Copy Markdown
Contributor

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

acaprino and others added 6 commits September 27, 2026 12:19
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
Rename the list-item fixture to say what it covers (a blockquote inside a list item),
and add a true nested-blockquote case, which hung before the fix.
@chrisjsewell
chrisjsewell merged commit f117453 into executablebooks:master Nov 9, 2026
11 checks passed
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

2 participants