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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Bugs fixed
does not match the language name, such as Chinese (which reuses the
English stemmer) and Dutch (which uses the Dutch Porter stemmer).
Patch by Hugo van Kemenade
* #12871: gettext: Extract indented doctest blocks when ``doctest-block`` is
enabled in :confval:`gettext_additional_targets`.
Patch by Jared Dillard


Release 9.1.0 (released Dec 31, 2025)
Expand Down
9 changes: 6 additions & 3 deletions sphinx/util/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ def apply_source_workaround(node: Element) -> None:
)
node.source, node.line = node.parent.source, node.parent.line

# workaround: literal_block under bullet list
# See: https://github.com/sphinx-doc/sphinx/issues/4913
if isinstance(node, nodes.literal_block) and node.source is None:
# Work around Docutils not setting ``source`` on:
# - literal blocks under bullet lists (#4913)
# - doctest blocks under block quotes (#12871)
if isinstance(node, (nodes.literal_block, nodes.doctest_block)) and (
node.source is None
):
with contextlib.suppress(ValueError):
node.source = get_node_source(node)

Expand Down
1 change: 1 addition & 0 deletions tests/roots/test-gettext-doctest-block/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project = 'test-gettext-doctest-block'
5 changes: 5 additions & 0 deletions tests/roots/test-gettext-doctest-block/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Indented doctest block
======================

>>> 2 + 2
4
16 changes: 16 additions & 0 deletions tests/test_builders/test_build_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,22 @@ def test_gettext_literalblock_additional(app: SphinxTestApp) -> None:
]


@pytest.mark.sphinx(
'gettext',
testroot='gettext-doctest-block',
confoverrides={'gettext_additional_targets': ['doctest-block']},
)
def test_gettext_indented_doctest_block(app: SphinxTestApp) -> None:
app.build(force_all=True)

pot = (app.outdir / 'index.pot').read_text(encoding='utf8')

assert get_msgids(pot) == [
'Indented doctest block',
'>>> 2 + 2\\n4',
]


@pytest.mark.sphinx('gettext', testroot='intl', srcdir='gettext')
def test_gettext_trailing_backslashes(app: SphinxTestApp) -> None:
app.build(force_all=True)
Expand Down
Loading