Skip to content

Commit 58e1523

Browse files
committed
fix(#17): resolve corner case with subsequent marked sections
1 parent a7228c2 commit 58e1523

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed

mdformat_mkdocs/plugin.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,19 @@ def __init__(self) -> None:
128128
self._lookup: dict[str, int] = {}
129129

130130
def _get_block_indent(self, indent: str, content: str) -> str:
131+
if (
132+
self._block_type == "marked"
133+
and content
134+
and len(indent) <= len(self._block_indent)
135+
):
136+
# Remove tracked indent on end of a marked (content tab or admonition) block
137+
# `Which could be the start of a new block, so this must be first
138+
self._block_type = None
139+
self._block_indent = ""
140+
131141
if self._block_type is None:
132142
# Identify block type
133-
markers = CONTENT_TAB_MARKERS + MKDOCS_ADMON_MARKERS
143+
markers = CONTENT_TAB_MARKERS.union(MKDOCS_ADMON_MARKERS)
134144
if content.startswith("```"):
135145
self._block_type = "code"
136146
elif any(content.startswith(f"{marker} ") for marker in markers):
@@ -142,14 +152,6 @@ def _get_block_indent(self, indent: str, content: str) -> str:
142152
# Remove tracked indent on end of code block
143153
self._block_type = None
144154
self._block_indent = ""
145-
elif (
146-
self._block_type == "marked"
147-
and content
148-
and len(indent) <= len(self._block_indent)
149-
):
150-
# Remove tracked indent on end of a marked (content tab or admonition) block
151-
self._block_type = None
152-
self._block_indent = ""
153155

154156
return self._block_indent
155157

tests/format/fixtures.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,3 +1269,73 @@ Example with '===+' (active) from <https://facelessuser.github.io/pymdown-extens
12691269
=== "Not Me Either"
12701270
Another Tab
12711271
.
1272+
1273+
1274+
More complex example to validate formatting when nested
1275+
.
1276+
1. List Outer
1277+
1278+
???+ Note
1279+
1280+
=== "First"
1281+
1282+
Markdown **content**.
1283+
1284+
Multiple paragraphs.
1285+
1286+
??? "Second"
1287+
1288+
Markdown **content**.
1289+
1290+
Multiple paragraphs.
1291+
1292+
===+ "Third"
1293+
1294+
- List Item
1295+
1296+
- Another Item
1297+
1298+
=== "Fourth"
1299+
1300+
- List Item
1301+
1302+
- Another Item
1303+
1304+
===! "Lastly a new item"
1305+
1306+
Markdown **content** for last item.
1307+
1308+
Very last indented paragraph.
1309+
1310+
2. Next
1311+
.
1312+
1. List Outer
1313+
1314+
???+ Note
1315+
=== "First"
1316+
Markdown **content**.
1317+
1318+
Multiple paragraphs.
1319+
1320+
??? "Second"
1321+
Markdown **content**.
1322+
1323+
Multiple paragraphs.
1324+
1325+
===+ "Third"
1326+
- List Item
1327+
1328+
- Another Item
1329+
1330+
=== "Fourth"
1331+
- List Item
1332+
1333+
- Another Item
1334+
1335+
===! "Lastly a new item"
1336+
Markdown **content** for last item.
1337+
1338+
Very last indented paragraph.
1339+
1340+
1. Next
1341+
.

0 commit comments

Comments
 (0)