Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix whitespace problems and failing tests #4

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions mdformat_admon/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@ def _render_admon(node: RenderTreeNode, context: RenderContext) -> str:
separator = "\n\n" # TODO: Is this configurable?
indent = " " * 4 # FIXME: Is this configurable?
title = node.info.strip()
body = f"{node.markup} {title}{separator}"
title_line = f"!!! {title}"
KyleKing marked this conversation as resolved.
Show resolved Hide resolved
with context.indented(len(indent)): # Modifies context.env['indent_width']
elements = [child.render(context) for child in node.children[1:]]
body += textwrap.indent(separator.join(elements), indent)
return body
elements = [child.render(context) for child in node.children]
content = textwrap.indent(separator.join(e for e in elements if e), indent)
if content:
return title_line + "\n" + content
return title_line


def _render_admon_title(node: RenderTreeNode, context: RenderContext) -> str:
return ""


# A mapping from syntax tree node type to a function that renders it.
# This can be used to overwrite renderer functions of existing syntax
# or add support for new syntax.
RENDERERS: Mapping[str, Render] = {"admonition": _render_admon}
RENDERERS: Mapping[str, Render] = {
"admonition": _render_admon,
"admonition_title": _render_admon_title,
}
47 changes: 27 additions & 20 deletions tests/fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Shows custom title

.
!!! note Custom title

Some text

.
Expand Down Expand Up @@ -62,8 +61,9 @@ Closes block after 2 empty lines
!!! note
Some text


A code block
```
A code block
```
.


Expand All @@ -79,7 +79,9 @@ Nested blocks
!!! note
Some text

code block
```
code block
```
.


Expand All @@ -100,8 +102,8 @@ Marker may be indented up to 3 chars
!!! note
content
.
!!! note
content
!!! note
content
.


Expand All @@ -110,8 +112,10 @@ But that's a code block
!!! note
content
.
!!! note
content
```
!!! note
content
```
.


Expand All @@ -122,10 +126,13 @@ Some more indent checks

code block
.
!!! note
not a code block
!!! note

code block
not a code block

```
code block
```
.


Expand All @@ -135,8 +142,8 @@ Type could be adjacent to marker
xxx

.
!!!note
xxx
!!! note
xxx

.

Expand All @@ -147,8 +154,8 @@ Type could be adjacent to marker and content may be shifted up to 3 chars
xxx

.
!!!note
xxx
!!! note
xxx

.

Expand All @@ -158,8 +165,8 @@ Or several spaces apart
!!! note
xxx
.
!!! note
xxx
!!! note
xxx
.


Expand Down Expand Up @@ -201,9 +208,9 @@ Or in blockquotes
.
> !!! note
> xxx
> > yyy
> zzz
>
> > yyy
> > zzz
.


Expand All @@ -223,5 +230,5 @@ Does not render
content
.
!!!
content
content
.