Skip to content

Commit

Permalink
Preserve leading whitespace lines in rST (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Aug 16, 2023
1 parent 94465e8 commit 99dfc8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,10 @@ Changelog

* Expand Markdown detection to all Python language names from Pygments: ``py``, ``sage``, ``python3``, ``py3``, and ``numpy``.

* Preserve leading blank lines with whitespace in reStructuredText code blocks.

Thanks to Julianus Pfeuffer for the report in `Issue #217 <https://github.com/adamchainz/blacken-docs/issues/217>`__.

* Remove ``language_version`` from ``.pre-commit-hooks.yaml``.
This change allows ``default_language_version`` in ``.pre-commit-config.yaml` to take precedence.
Expand Down
2 changes: 1 addition & 1 deletion src/blacken_docs/__init__.py
Expand Up @@ -37,7 +37,7 @@
rf"{DOCTEST_TYPES}::.*"
rf")\n"
rf"((?P=indent) +:.*\n)*"
rf"\n*"
rf"( *\n)*"
rf")"
rf"(?P<code>(^((?P=indent) +.*)?\n)+)",
re.MULTILINE,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_blacken_docs.py
Expand Up @@ -381,6 +381,24 @@ def test_format_src_rst_indented():
)


def test_format_src_rst_code_block_indent():
before = "\n".join(
[
".. code-block:: python",
" ",
" f(1,2,3)\n",
]
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == "\n".join(
[
".. code-block:: python",
" ",
" f(1, 2, 3)\n",
]
)


def test_format_src_rst_with_highlight_directives():
before = (
".. code-block:: python\n"
Expand Down

0 comments on commit 99dfc8d

Please sign in to comment.