File tree Expand file tree Collapse file tree 3 files changed +37
-13
lines changed Expand file tree Collapse file tree 3 files changed +37
-13
lines changed Original file line number Diff line number Diff line change 1- __version__ = "1.1.6 "
1+ __version__ = "1.1.7 "
Original file line number Diff line number Diff line change @@ -34,20 +34,27 @@ def fix_equations(self, content: str) -> str:
3434 """Fix mathematical equations in markdown content."""
3535 try :
3636 # 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 ,
37+ # Allow optional blank/whitespace-only lines after [ and before ]
38+ # and preserve inner content trimmed of leading/trailing blank lines.
39+ bracket_block_pattern = re .compile (
40+ r"(?ms)^[\t ]*\[[\t ]*\r?\n(.*?)(?:\r?\n)^[\t ]*\][\t ]*(?:\r?\n|$)" ,
4941 )
5042
43+ def _replace_bracket_block (match : re .Match ) -> str :
44+ inner = match .group (1 )
45+ # Trim leading/trailing blank lines in the captured block
46+ lines = inner .splitlines ()
47+ start = 0
48+ end = len (lines )
49+ while start < end and lines [start ].strip () == "" :
50+ start += 1
51+ while end > start and lines [end - 1 ].strip () == "" :
52+ end -= 1
53+ inner_trimmed = "\n " .join (lines [start :end ])
54+ return f"$$\n { inner_trimmed } \n $$\n "
55+
56+ content = bracket_block_pattern .sub (_replace_bracket_block , content )
57+
5158 # Pattern to match block equations: \[ ... \]
5259 # The re.DOTALL flag allows the match to span multiple lines.
5360 content = re .sub (
Original file line number Diff line number Diff line change @@ -49,6 +49,23 @@ def test_fix_bracket_line_block(fixer):
4949 assert fixer .fix_equations (input_text ) == expected
5050
5151
52+ def test_fix_bracket_block_with_blank_lines_and_indent (fixer ):
53+ """Blocks with extra blank lines and indentation should be converted."""
54+ input_text = (
55+ "\n [\n \n Z₁ = XW₁ + b₁\n \n ]\n \n " # first block
56+ "[\n A₁ = ReLU(Z₁)\n ]\n \n " # second block
57+ "[\n Z₂ = A₁W₂ + b₂\n ]\n \n " # third block
58+ "[\n \\ hat{y} = Z₂\n ]\n \n " # fourth block
59+ "[\n L = \\ frac{1}{2m} \\ sum (y - \\ hat{y})^2\n ]\n " # fifth block
60+ )
61+ output = fixer .fix_equations (input_text )
62+ # Ensure each becomes a $$ block and inner content preserved sans surrounding blanks
63+ assert "$$\n Z₁ = XW₁ + b₁\n $$" in output
64+ assert "$$\n A₁ = ReLU(Z₁)\n $$" in output
65+ assert "$$\n Z₂ = A₁W₂ + b₂\n $$" in output
66+ assert "$$\n \\ hat{y} = Z₂\n $$" in output
67+ assert "$$\n L = \\ frac{1}{2m} \\ sum (y - \\ hat{y})^2\n $$" in output
68+
5269def test_validate_paths_recursive (temp_dir ):
5370 """Test recursive path validation."""
5471 paths = [temp_dir ]
You can’t perform that action at this time.
0 commit comments