Skip to content

Commit fb6d7d4

Browse files
committed
fix: add expected newline
1 parent 360f86a commit fb6d7d4

File tree

4 files changed

+105
-19
lines changed

4 files changed

+105
-19
lines changed

mdformat_mkdocs/plugin.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,29 @@ def _render_cross_reference(node: RenderTreeNode, context: RenderContext) -> str
122122
return _render_with_default_renderer(node, context, "link")
123123

124124

125+
def add_extra_admon_newline(node: RenderTreeNode, context: RenderContext) -> str:
126+
"""Return admonition with additional newline after the title.
127+
128+
See: https://github.com/KyleKing/mdformat-admon/pull/22
129+
130+
"""
131+
result = ADMON_RENDERS["admonition"](node, context)
132+
if "\n" not in result:
133+
return result
134+
title, *content = result.split("\n", maxsplit=1)
135+
return f"{title}\n\n{''.join(content)}"
136+
137+
125138
# A mapping from syntax tree node type to a function that renders it.
126139
# This can be used to overwrite renderer functions of existing syntax
127140
# or add support for new syntax.
128141
RENDERERS: Mapping[str, Render] = {
129-
"admonition_mkdocs": ADMON_RENDERS["admonition"],
142+
# TODO: address conflict with mdformat-admon because mkdocs needs to override
143+
"admonition": add_extra_admon_newline,
144+
"admonition_title": ADMON_RENDERS["admonition_title"],
145+
"admonition_mkdocs": add_extra_admon_newline,
130146
"admonition_mkdocs_title": ADMON_RENDERS["admonition_title"],
131-
"content_tab_mkdocs": ADMON_RENDERS["admonition"],
147+
"content_tab_mkdocs": add_extra_admon_newline,
132148
"content_tab_mkdocs_title": ADMON_RENDERS["admonition_title"],
133149
MKDOCSTRINGS_AUTOREFS_PREFIX: _render_meta_content,
134150
MKDOCSTRINGS_HEADING_AUTOREFS_PREFIX: _render_heading_autoref,

tests/format/fixtures/material_content_tabs.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Do not modify multi-line code from: https://github.com/KyleKing/mdformat-mkdocs/
2020
```
2121
.
2222
=== "duty"
23+
2324
```python title="duties.py"
2425
@duty(silent=True)
2526
def coverage(ctx):

0 commit comments

Comments
 (0)