mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Find node.source recursively. In some cases (.. figure nested inside other blocks or lists), the node.parent.source is None too, so the old logic fails. Just traverse up, until we get a valid node.source or have no parent at all.
This commit is contained in:
parent
89d2a53ccc
commit
6e3e439399
@ -41,6 +41,23 @@ IGNORED_NODES = (
|
|||||||
nodes.doctest_block,
|
nodes.doctest_block,
|
||||||
#XXX there are probably more
|
#XXX there are probably more
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def find_source_node(node):
|
||||||
|
if node.source:
|
||||||
|
return node.source
|
||||||
|
|
||||||
|
current = node
|
||||||
|
while 1:
|
||||||
|
parent = current.parent
|
||||||
|
if parent.source:
|
||||||
|
return parent.source
|
||||||
|
else:
|
||||||
|
current = parent
|
||||||
|
|
||||||
|
if not current:
|
||||||
|
break
|
||||||
|
return None
|
||||||
|
|
||||||
def extract_messages(doctree):
|
def extract_messages(doctree):
|
||||||
"""Extract translatable messages from a document tree."""
|
"""Extract translatable messages from a document tree."""
|
||||||
for node in doctree.traverse(nodes.TextElement):
|
for node in doctree.traverse(nodes.TextElement):
|
||||||
@ -59,7 +76,7 @@ def extract_messages(doctree):
|
|||||||
# sf.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032
|
# sf.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032
|
||||||
# sourceforge.net/p/docutils/patches/108/
|
# sourceforge.net/p/docutils/patches/108/
|
||||||
if isinstance(node, (nodes.caption, nodes.title, nodes.rubric)) and not node.source:
|
if isinstance(node, (nodes.caption, nodes.title, nodes.rubric)) and not node.source:
|
||||||
node.source = node.parent.source
|
node.source = find_source_node(node)
|
||||||
node.line = 0 #need fix docutils to get `node.line`
|
node.line = 0 #need fix docutils to get `node.line`
|
||||||
|
|
||||||
if not node.source:
|
if not node.source:
|
||||||
|
Loading…
Reference in New Issue
Block a user