Skip to content

Commit 285f9c0

Browse files
committed
Add test for fixing standalone bracket line blocks in test.py; enhance regex in EquationFixer to handle new block format
1 parent 300768d commit 285f9c0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/markdown_equations_fixer/cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ def __init__(self, dry_run: bool = False, verbose: bool = False):
3333
def fix_equations(self, content: str) -> str:
3434
"""Fix mathematical equations in markdown content."""
3535
try:
36+
# Pattern to match block equations delimited by standalone lines with [ and ]
37+
# Example:
38+
# [\n
39+
# equation content\n
40+
# ]
41+
# This converts to:
42+
# $$\n
43+
# equation content\n
44+
# $$
45+
content = re.sub(
46+
r"(?ms)^\[\s*$\n(.*?)\n^\]\s*$",
47+
r"$$\n\1\n$$",
48+
content,
49+
)
50+
3651
# Pattern to match block equations: \[ ... \]
3752
# The re.DOTALL flag allows the match to span multiple lines.
3853
content = re.sub(

src/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def test_fix_inline_equations(fixer):
4242
)
4343

4444

45+
def test_fix_bracket_line_block(fixer):
46+
"""Test fixing blocks where [ and ] are on their own lines."""
47+
input_text = "[\nE=mc^2\n]"
48+
expected = "$$\nE=mc^2\n$$"
49+
assert fixer.fix_equations(input_text) == expected
50+
51+
4552
def test_validate_paths_recursive(temp_dir):
4653
"""Test recursive path validation."""
4754
paths = [temp_dir]

0 commit comments

Comments
 (0)