From 1845122fdebfc6645f6b5304de12f7e521d50478 Mon Sep 17 00:00:00 2001 From: Evan Smith Date: Thu, 14 Aug 2025 15:51:59 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Overwrite=20blockquote=20?= =?UTF-8?q?renderer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdformat_myst/plugin.py | 21 +++++++++++++ tests/data/fixtures.md | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/mdformat_myst/plugin.py b/mdformat_myst/plugin.py index 13d796e..19391e0 100644 --- a/mdformat_myst/plugin.py +++ b/mdformat_myst/plugin.py @@ -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) @@ -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, diff --git a/tests/data/fixtures.md b/tests/data/fixtures.md index 5a62b17..f5899de 100644 --- a/tests/data/fixtures.md +++ b/tests/data/fixtures.md @@ -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 . ---