Skip to content
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
21 changes: 21 additions & 0 deletions mdformat_myst/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ def _math_block_label_renderer(node: RenderTreeNode, context: RenderContext) ->
return f"$${node.content}$$ ({node.info})"


def _math_block_safe_blockquote_renderer(
node: RenderTreeNode, context: RenderContext
) -> str:
marker = "> "
with context.indented(len(marker)):
lines = []
for i, child in enumerate(node.children):
if child.type in ("math_block", "math_block_label"):
lines.append(child.render(context))
else:
lines.extend(child.render(context).splitlines())
if i < (len(node.children) - 1):
lines.append("")
if not lines:
return ">"
quoted_lines = (f"{marker}{line}" if line else ">" for line in lines)
quoted_str = "\n".join(quoted_lines)
return quoted_str


def _render_children(node: RenderTreeNode, context: RenderContext) -> str:
return "\n\n".join(child.render(context) for child in node.children)

Expand Down Expand Up @@ -121,6 +141,7 @@ def _escape_text(text: str, node: RenderTreeNode, context: RenderContext) -> str


RENDERERS = {
"blockquote": _math_block_safe_blockquote_renderer,
"myst_role": _role_renderer,
"myst_line_comment": _comment_renderer,
"myst_block_break": _blockbreak_renderer,
Expand Down
68 changes: 68 additions & 0 deletions tests/data/fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,74 @@ a=1
$$ (eq1)
.

Blockquote with dollarmath block
.
> $$
a=1
$$
.
> $$
a=1
$$
.

Long blockquote with dollarmath block
.
> Some words
>
> Block math:
>
> $$
a=1
$$
>
> Some more words
.
> Some words
>
> Block math:
>
> $$
a=1
$$
>
> Some more words
.

Blockquote with dollarmath block labeled
.
> $$
a=1
$$ (eq1)
.
> $$
a=1
$$ (eq1)
.

Long blockquote with dollarmath block labeled
.
> Some words
>
> Block math:
>
> $$
a=1
$$ (eq1)
>
> Some more words
.
> Some words
>
> Block math:
>
> $$
a=1
$$ (eq1)
>
> Some more words
.

Frontmatter
.
---
Expand Down
Loading