Skip to content

Commit 99dfc8d

Browse files
authored
Preserve leading whitespace lines in rST (#271)
1 parent 94465e8 commit 99dfc8d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Changelog
88

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

11+
* Preserve leading blank lines with whitespace in reStructuredText code blocks.
12+
13+
Thanks to Julianus Pfeuffer for the report in `Issue #217 <https://github.com/adamchainz/blacken-docs/issues/217>`__.
14+
1115
* Remove ``language_version`` from ``.pre-commit-hooks.yaml``.
1216
This change allows ``default_language_version`` in ``.pre-commit-config.yaml` to take precedence.
1317

src/blacken_docs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
rf"{DOCTEST_TYPES}::.*"
3838
rf")\n"
3939
rf"((?P=indent) +:.*\n)*"
40-
rf"\n*"
40+
rf"( *\n)*"
4141
rf")"
4242
rf"(?P<code>(^((?P=indent) +.*)?\n)+)",
4343
re.MULTILINE,

tests/test_blacken_docs.py

+18
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ def test_format_src_rst_indented():
381381
)
382382

383383

384+
def test_format_src_rst_code_block_indent():
385+
before = "\n".join(
386+
[
387+
".. code-block:: python",
388+
" ",
389+
" f(1,2,3)\n",
390+
]
391+
)
392+
after, _ = blacken_docs.format_str(before, BLACK_MODE)
393+
assert after == "\n".join(
394+
[
395+
".. code-block:: python",
396+
" ",
397+
" f(1, 2, 3)\n",
398+
]
399+
)
400+
401+
384402
def test_format_src_rst_with_highlight_directives():
385403
before = (
386404
".. code-block:: python\n"

0 commit comments

Comments
 (0)