diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b78b3..170c2fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Change Log +## Unreleased + +- 🐛 FIX: `dollarmath` block rule no longer absorbs following content when a same-line-closed `$$...$$` has non-label trailing text (#147) + + A same-line close followed by trailing content that wasn't a label suffix (e.g. `` $$b$$ trailing ``) wasn't recognized as closed, so the rule fell through to its multi-line scan and silently swallowed every following line, including subsequent list items, up to the next `$$` anywhere later in the document: + + ```markdown + 1. $$a$$ + 1. $$b$$ trailing + 1. $$c$$ + ``` + + This ambiguous case (closing marker present, but not at end of line and not a label) is now rejected outright, letting the line fall through to normal inline parsing instead. + ## 0.7.0 - 2026-07-19 - ✨ NEW: Add section reference plugin (`section_ref`) (#144) diff --git a/mdit_py_plugins/dollarmath/index.py b/mdit_py_plugins/dollarmath/index.py index 57ba590..5c36b24 100644 --- a/mdit_py_plugins/dollarmath/index.py +++ b/mdit_py_plugins/dollarmath/index.py @@ -322,13 +322,21 @@ def _math_block_dollar( if lineText.strip().endswith("$$"): haveEndMarker = True end = end - 2 - (len(lineText) - len(lineText.strip())) - elif allow_labels: - # reverse the line and match - eqnoMatch = DOLLAR_EQNO_REV.match(lineText[::-1]) - if eqnoMatch: - haveEndMarker = True - label = eqnoMatch.group(1)[::-1] - end = end - eqnoMatch.end() + else: + # a closing marker present but not at end of line and not a label + # suffix is ambiguous, so don't greedily scan subsequent lines for it + trailing_close = "$$" in lineText[2:] + if allow_labels: + # reverse the line and match + eqnoMatch = DOLLAR_EQNO_REV.match(lineText[::-1]) + if eqnoMatch: + haveEndMarker = True + label = eqnoMatch.group(1)[::-1] + end = end - eqnoMatch.end() + elif trailing_close: + return False + elif trailing_close: + return False # search for end of block on subsequent line if not haveEndMarker: diff --git a/tests/fixtures/dollar_math.md b/tests/fixtures/dollar_math.md index 08a2e90..95ec2a8 100644 --- a/tests/fixtures/dollar_math.md +++ b/tests/fixtures/dollar_math.md @@ -580,3 +580,38 @@ Indented by 4 spaces, DISABLE-CODEBLOCKS a . + +same-line-closed block with trailing text is not absorbed into +a later math block on a following line. (valid=True) +. +$$a$$ trailing +$$c$$ +. +