Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/blacken_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
PYGMENTS_PY_LANGS = frozenset(("python", "py", "sage", "python3", "py3", "numpy"))
PYGMENTS_PY_LANGS_RE_FRAGMENT = f"({'|'.join(PYGMENTS_PY_LANGS)})"
MD_RE = re.compile(
r"(?P<before>^(?P<indent> *)```\s*" + PYGMENTS_PY_LANGS_RE_FRAGMENT + r"( .*?)?\n)"
r"(?P<before>^(?P<indent> *)```\s*(\{?\s*)?(\.?)?"
+ PYGMENTS_PY_LANGS_RE_FRAGMENT
+ r"( .*?)?\n)"
r"(?P<code>.*?)"
r"(?P<after>^(?P=indent)```\s*$)",
re.DOTALL | re.MULTILINE,
Expand Down
54 changes: 54 additions & 0 deletions tests/test_blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,57 @@ def test_format_src_rst_pycon_comment_before_promopt():
" # Comment about next line\n"
" >>> pass\n"
)


def test_format_src_markdown_pymdown_1():
before = dedent(
"""\
```{.python title='example.py'}
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == dedent(
"""\
```{.python title='example.py'}
f(1, 2, 3)
```
"""
)


def test_format_src_markdown_pymdown_2():
before = dedent(
"""\
``` {.py title='example.py'}
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == dedent(
"""\
``` {.py title='example.py'}
f(1, 2, 3)
```
"""
)


def test_format_src_markdown_pymdown_3():
before = dedent(
"""\
```{ .py .python .extra-class #id linenums="1" title="example.py"}
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == dedent(
"""\
```{ .py .python .extra-class #id linenums="1" title="example.py"}
f(1, 2, 3)
```
"""
)