Skip to content

Commit

Permalink
Fix Markdown pycon formatting remainder (#347)
Browse files Browse the repository at this point in the history
Applying the same edit from #283.
  • Loading branch information
adamchainz authored Jun 30, 2024
1 parent 4602a39 commit 12b7b98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Changelog
=========

* Fix Markdown ``pycon`` formatting to allow formatting the rest of the file.

1.17.0 (2024-06-29)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion src/blacken_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
MD_PYCON_RE = re.compile(
r"(?P<before>^(?P<indent> *)```[^\S\r\n]*pycon( .*?)?\n)"
r"(?P<code>.*?)"
r"(?P<after>^(?P=indent)```.*$)",
r"(?P<after>^(?P=indent)```[^\S\r\n]*$)",
re.DOTALL | re.MULTILINE,
)
BLOCK_TYPES = "(code|code-block|sourcecode|ipython)"
Expand Down
26 changes: 26 additions & 0 deletions tests/test_blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,32 @@ def test_format_src_markdown_pycon_options():
)


def test_format_src_markdown_pycon_twice():
before = (
"```pycon\n"
">>> f(1,2,3)\n"
"output\n"
"```\n"
"example 2\n"
"```pycon\n"
">>> f(1,2,3)\n"
"output\n"
"```\n"
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == (
"```pycon\n"
">>> f(1, 2, 3)\n"
"output\n"
"```\n"
"example 2\n"
"```pycon\n"
">>> f(1, 2, 3)\n"
"output\n"
"```\n"
)


def test_format_src_latex_minted():
before = (
"hello\n" "\\begin{minted}{python}\n" "f(1,2,3)\n" "\\end{minted}\n" "world!"
Expand Down

0 comments on commit 12b7b98

Please sign in to comment.