Skip to content

Commit 1845122

Browse files
author
Evan Smith
committed
🐛 FIX: Overwrite blockquote renderer
1 parent aad737f commit 1845122

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

mdformat_myst/plugin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ def _math_block_label_renderer(node: RenderTreeNode, context: RenderContext) ->
8585
return f"$${node.content}$$ ({node.info})"
8686

8787

88+
def _math_block_safe_blockquote_renderer(
89+
node: RenderTreeNode, context: RenderContext
90+
) -> str:
91+
marker = "> "
92+
with context.indented(len(marker)):
93+
lines = []
94+
for i, child in enumerate(node.children):
95+
if child.type in ("math_block", "math_block_label"):
96+
lines.append(child.render(context))
97+
else:
98+
lines.extend(child.render(context).splitlines())
99+
if i < (len(node.children) - 1):
100+
lines.append("")
101+
if not lines:
102+
return ">"
103+
quoted_lines = (f"{marker}{line}" if line else ">" for line in lines)
104+
quoted_str = "\n".join(quoted_lines)
105+
return quoted_str
106+
107+
88108
def _render_children(node: RenderTreeNode, context: RenderContext) -> str:
89109
return "\n\n".join(child.render(context) for child in node.children)
90110

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

122142

123143
RENDERERS = {
144+
"blockquote": _math_block_safe_blockquote_renderer,
124145
"myst_role": _role_renderer,
125146
"myst_line_comment": _comment_renderer,
126147
"myst_block_break": _blockbreak_renderer,

tests/data/fixtures.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,74 @@ a=1
192192
$$ (eq1)
193193
.
194194
195+
Blockquote with dollarmath block
196+
.
197+
> $$
198+
a=1
199+
$$
200+
.
201+
> $$
202+
a=1
203+
$$
204+
.
205+
206+
Long blockquote with dollarmath block
207+
.
208+
> Some words
209+
>
210+
> Block math:
211+
>
212+
> $$
213+
a=1
214+
$$
215+
>
216+
> Some more words
217+
.
218+
> Some words
219+
>
220+
> Block math:
221+
>
222+
> $$
223+
a=1
224+
$$
225+
>
226+
> Some more words
227+
.
228+
229+
Blockquote with dollarmath block labeled
230+
.
231+
> $$
232+
a=1
233+
$$ (eq1)
234+
.
235+
> $$
236+
a=1
237+
$$ (eq1)
238+
.
239+
240+
Long blockquote with dollarmath block labeled
241+
.
242+
> Some words
243+
>
244+
> Block math:
245+
>
246+
> $$
247+
a=1
248+
$$ (eq1)
249+
>
250+
> Some more words
251+
.
252+
> Some words
253+
>
254+
> Block math:
255+
>
256+
> $$
257+
a=1
258+
$$ (eq1)
259+
>
260+
> Some more words
261+
.
262+
195263
Frontmatter
196264
.
197265
---

0 commit comments

Comments
 (0)