From b008bd0589095763bca2c35d69095ac12bbf925e Mon Sep 17 00:00:00 2001 From: Evan Smith Date: Fri, 15 Aug 2025 14:24:12 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Dedent=20math=20block=20i?= =?UTF-8?q?f=20nonzero=20indent=5Fwidth=20found=20in=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdformat_myst/plugin.py | 6 +++++- tests/data/fixtures.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mdformat_myst/plugin.py b/mdformat_myst/plugin.py index 19391e0..077ce15 100644 --- a/mdformat_myst/plugin.py +++ b/mdformat_myst/plugin.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +import textwrap from markdown_it import MarkdownIt import mdformat.plugins @@ -78,11 +79,14 @@ def _math_inline_renderer(node: RenderTreeNode, context: RenderContext) -> str: def _math_block_renderer(node: RenderTreeNode, context: RenderContext) -> str: + indent_width = context.env.get("indent_width", 0) + if indent_width > 0: + return f"$${textwrap.dedent(node.content)}$$" return f"$${node.content}$$" def _math_block_label_renderer(node: RenderTreeNode, context: RenderContext) -> str: - return f"$${node.content}$$ ({node.info})" + return f"{_math_block_renderer(node, context)} ({node.info})" def _math_block_safe_blockquote_renderer( diff --git a/tests/data/fixtures.md b/tests/data/fixtures.md index f5899de..0b70e44 100644 --- a/tests/data/fixtures.md +++ b/tests/data/fixtures.md @@ -260,6 +260,36 @@ $$ (eq1) > Some more words . +Indented dollarmath block +. +1. Indented math block + + $$ + a=1 + $$ +. +1. Indented math block + + $$ + a=1 + $$ +. + +Indented dollarmath block labeled +. +1. Indented labeled math block + + $$ + a=1 + $$ (eq1) +. +1. Indented labeled math block + + $$ + a=1 + $$ (eq1) +. + Frontmatter . ---