File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,7 +86,11 @@ def close_open_markdown(text: str) -> str:
8686 in_code_fence = True
8787 fence_char = char
8888 fence_len = len (matched_group )
89- elif char == fence_char and len (matched_group ) >= fence_len :
89+ elif (
90+ char == fence_char
91+ and len (matched_group ) >= fence_len
92+ and line [fence_match .end () :].strip (" \t " ) == ""
93+ ):
9094 in_code_fence = False
9195 fence_char = ""
9296 fence_len = 0
Original file line number Diff line number Diff line change @@ -60,6 +60,18 @@ def test_shorter_fence_inside_longer_fence_not_closer(self) -> None:
6060 result = close_open_markdown (text )
6161 assert result == "\n ````"
6262
63+ def test_fence_with_trailing_text_not_closer (self ) -> None :
64+ """A fence marker with trailing non-whitespace inside a fence is content."""
65+ text = "```python\n print('x')\n ```not a closer"
66+ result = close_open_markdown (text )
67+ assert result == "\n ```"
68+
69+ def test_fence_with_trailing_whitespace_is_closer (self ) -> None :
70+ """A fence marker with only trailing whitespace is a valid closer."""
71+ text = "```python\n print('x')\n ``` "
72+ result = close_open_markdown (text )
73+ assert result == ""
74+
6375
6476class TestCloseOpenMarkdownHtmlTags :
6577 """Tests for closing unclosed HTML block tags."""
You can’t perform that action at this time.
0 commit comments