diff options
author | shimizukawa <shimizukawa@gmail.com> | 2013-11-12 15:17:09 +0000 |
---|---|---|
committer | shimizukawa <shimizukawa@gmail.com> | 2013-11-12 15:17:09 +0000 |
commit | ecdf03ae3a131c3de5d4e407a62b7433e594d192 (patch) | |
tree | bb1dc3b5629f4cd076bebc2fbcf156d897094c20 /sphinx/util | |
parent | aa4f7e224d21bfc5328afde206e49811db29a3f8 (diff) | |
download | sphinx-ecdf03ae3a131c3de5d4e407a62b7433e594d192.tar.gz |
Add tests and code refine for pull request #190.
Diffstat (limited to 'sphinx/util')
-rw-r--r-- | sphinx/util/nodes.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 9d303188..da9b4be6 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -41,23 +41,6 @@ IGNORED_NODES = ( nodes.doctest_block, #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): """Extract translatable messages from a document tree.""" for node in doctree.traverse(nodes.TextElement): @@ -94,6 +77,18 @@ def extract_messages(doctree): yield node, msg +def find_source_node(node): + for pnode in traverse_parent(node): + if pnode.source: + return pnode.source + + +def traverse_parent(node): + while node: + yield node + node = node.parent + + def traverse_translatable_index(doctree): """Traverse translatable index node from a document tree.""" def is_block_index(node): |