Skip to content

Commit

Permalink
Fix for empty literal blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Jan 15, 2023
1 parent baebf4a commit 9c1674f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions blacken_docs.py
Expand Up @@ -128,6 +128,8 @@ def _rst_match(match: Match[str]) -> str:
return f'{match["before"]}{code.rstrip()}{trailing_ws}'

def _rst_literal_blocks_match(match: Match[str]) -> str:
if not match['code'].strip():
return match[0]
min_indent = min(INDENT_RE.findall(match['code']))
trailing_ws_match = TRAILING_NL_RE.search(match['code'])
assert trailing_ws_match
Expand Down
17 changes: 17 additions & 0 deletions tests/blacken_docs_test.py
Expand Up @@ -234,6 +234,23 @@ def test_format_src_rst_literal_blocks_nested():
assert errors == []


def test_format_src_rst_literal_blocks_empty():
before = dedent(
'''
Example::
.. warning::
There was no example.
''',
)
after, errors = blacken_docs.format_str(
before, BLACK_MODE, rst_literal_blocks=True,
)
assert after == before
assert errors == []


def test_format_src_rst_sphinx_doctest():
before = (
'.. testsetup:: group1\n'
Expand Down

0 comments on commit 9c1674f

Please sign in to comment.