Skip to content

Commit

Permalink
fix(#17): resolve corner case with subsequent marked sections
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Jan 18, 2024
1 parent a7228c2 commit 58e1523
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 9 deletions.
20 changes: 11 additions & 9 deletions mdformat_mkdocs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,19 @@ def __init__(self) -> None:
self._lookup: dict[str, int] = {}

def _get_block_indent(self, indent: str, content: str) -> str:
if (
self._block_type == "marked"
and content
and len(indent) <= len(self._block_indent)
):
# Remove tracked indent on end of a marked (content tab or admonition) block
# `Which could be the start of a new block, so this must be first
self._block_type = None
self._block_indent = ""

if self._block_type is None:
# Identify block type
markers = CONTENT_TAB_MARKERS + MKDOCS_ADMON_MARKERS
markers = CONTENT_TAB_MARKERS.union(MKDOCS_ADMON_MARKERS)
if content.startswith("```"):
self._block_type = "code"
elif any(content.startswith(f"{marker} ") for marker in markers):
Expand All @@ -142,14 +152,6 @@ def _get_block_indent(self, indent: str, content: str) -> str:
# Remove tracked indent on end of code block
self._block_type = None
self._block_indent = ""
elif (
self._block_type == "marked"
and content
and len(indent) <= len(self._block_indent)
):
# Remove tracked indent on end of a marked (content tab or admonition) block
self._block_type = None
self._block_indent = ""

return self._block_indent

Expand Down
70 changes: 70 additions & 0 deletions tests/format/fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -1269,3 +1269,73 @@ Example with '===+' (active) from <https://facelessuser.github.io/pymdown-extens
=== "Not Me Either"
Another Tab
.
More complex example to validate formatting when nested
.
1. List Outer
???+ Note
=== "First"
Markdown **content**.
Multiple paragraphs.
??? "Second"
Markdown **content**.
Multiple paragraphs.
===+ "Third"
- List Item
- Another Item
=== "Fourth"
- List Item
- Another Item
===! "Lastly a new item"
Markdown **content** for last item.
Very last indented paragraph.
2. Next
.
1. List Outer
???+ Note
=== "First"
Markdown **content**.
Multiple paragraphs.
??? "Second"
Markdown **content**.
Multiple paragraphs.
===+ "Third"
- List Item
- Another Item
=== "Fourth"
- List Item
- Another Item
===! "Lastly a new item"
Markdown **content** for last item.
Very last indented paragraph.
1. Next
.

0 comments on commit 58e1523

Please sign in to comment.