Skip to content

Commit

Permalink
Fix sphinx-doc#9947: i18n: topic directive having a bullet list can't…
Browse files Browse the repository at this point in the history
… be translatable

It seems docutils does not fill the topic node with the source info when
a topic directive has a bullet list.  As a workaround, This fills the
source info of them.
  • Loading branch information
tk0miya committed Dec 9, 2021
1 parent 5851344 commit f2f91ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -33,6 +33,7 @@ Bugs fixed
* #9883: autodoc: doccomment for the alias to mocked object was ignored
* #9908: autodoc: debug message is shown on building document using NewTypes
with Python 3.10
* #9947: i18n: topic directive having a bullet list can't be translatable
* #9878: mathjax: MathJax configuration is placed after loading MathJax itself
* #9857: Generated RFC links use outdated base url
* #9909: HTML, prevent line-wrapping in literal text.
Expand Down
2 changes: 1 addition & 1 deletion sphinx/transforms/__init__.py
Expand Up @@ -208,7 +208,7 @@ class ApplySourceWorkaround(SphinxTransform):

def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(): # type: Node
if isinstance(node, (nodes.TextElement, nodes.image)):
if isinstance(node, (nodes.TextElement, nodes.image, nodes.topic)):
apply_source_workaround(node)


Expand Down
5 changes: 5 additions & 0 deletions sphinx/util/nodes.py
Expand Up @@ -150,6 +150,11 @@ def apply_source_workaround(node: Element) -> None:
for classifier in reversed(list(node.parent.traverse(nodes.classifier))):
node.rawsource = re.sub(r'\s*:\s*%s' % re.escape(classifier.astext()),
'', node.rawsource)
if isinstance(node, nodes.topic) and node.source is None:
# docutils-0.18 does not fill the source attribute of topic
logger.debug('[i18n] PATCH: %r to have source, line: %s',
get_full_module_name(node), repr_domxml(node))
node.source, node.line = node.parent.source, node.parent.line

# workaround: literal_block under bullet list (#4913)
if isinstance(node, nodes.literal_block) and node.source is None:
Expand Down

0 comments on commit f2f91ff

Please sign in to comment.