Skip to content

Commit 2614618

Browse files
authored
fix(#56): narrowly scope escape_deflist (#57)
1 parent bc580d5 commit 2614618

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

mdformat_mkdocs/mdit_plugins/_material_deflist.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
ut eros sed sapien ullamcorper consequat. Nunc ligula ante.
1818
1919
Duis mollis est eget nibh volutpat, fermentum aliquet dui mollis.
20-
Nam vulputate tincidunt fringilla.
20+
Vulputate tincidunt fringilla.
2121
Nullam dignissim ultrices urna non auctor.
2222
```
2323
@@ -28,6 +28,7 @@
2828

2929
from __future__ import annotations
3030

31+
import re
3132
from typing import TYPE_CHECKING
3233

3334
from markdown_it import MarkdownIt
@@ -106,6 +107,7 @@ def escape_deflist(
106107
context: RenderContext, # noqa: ARG001
107108
) -> str:
108109
"""Escape line starting ":" which would otherwise be parsed as a definition list."""
110+
pattern = re.compile(r"^[:~] ")
109111
return "\n".join(
110-
"\\" + line if line.startswith(":") else line for line in text.split("\n")
112+
"\\" + line if pattern.match(line) else line for line in text.split("\n")
111113
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Prevent regression with non-deflists: https://github.com/KyleKing/mdformat-mkdocs/issues/56
2+
.
3+
::: my_lib.core
4+
.
5+
::: my_lib.core
6+
.

tests/format/test_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def flatten(nested_list: list[list[T]]) -> list[T]:
2727
"pymd_abbreviations.md",
2828
"pymd_snippet.md",
2929
"python_markdown_attr_list.md",
30+
"regression.md",
3031
"text.md",
3132
)
3233
],

0 commit comments

Comments
 (0)