Skip to content

Commit 03c7dc5

Browse files
e13hEvan Smith
andauthored
🐛 FIX: Dedent math block if nonzero indent_width found in context (#40)
Co-authored-by: Evan Smith <[email protected]>
1 parent adbcedb commit 03c7dc5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

mdformat_myst/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import re
4+
import textwrap
45

56
from markdown_it import MarkdownIt
67
import mdformat.plugins
@@ -78,11 +79,14 @@ def _math_inline_renderer(node: RenderTreeNode, context: RenderContext) -> str:
7879

7980

8081
def _math_block_renderer(node: RenderTreeNode, context: RenderContext) -> str:
82+
indent_width = context.env.get("indent_width", 0)
83+
if indent_width > 0:
84+
return f"$${textwrap.dedent(node.content)}$$"
8185
return f"$${node.content}$$"
8286

8387

8488
def _math_block_label_renderer(node: RenderTreeNode, context: RenderContext) -> str:
85-
return f"$${node.content}$$ ({node.info})"
89+
return f"{_math_block_renderer(node, context)} ({node.info})"
8690

8791

8892
def _math_block_safe_blockquote_renderer(

tests/data/fixtures.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,36 @@ $$ (eq1)
260260
> Some more words
261261
.
262262
263+
Indented dollarmath block
264+
.
265+
1. Indented math block
266+
267+
$$
268+
a=1
269+
$$
270+
.
271+
1. Indented math block
272+
273+
$$
274+
a=1
275+
$$
276+
.
277+
278+
Indented dollarmath block labeled
279+
.
280+
1. Indented labeled math block
281+
282+
$$
283+
a=1
284+
$$ (eq1)
285+
.
286+
1. Indented labeled math block
287+
288+
$$
289+
a=1
290+
$$ (eq1)
291+
.
292+
263293
Frontmatter
264294
.
265295
---

0 commit comments

Comments
 (0)