summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakayuki Shimizukawa <shimizukawa@gmail.com>2014-08-26 00:29:29 +0900
committerTakayuki Shimizukawa <shimizukawa@gmail.com>2014-08-26 00:29:29 +0900
commitc4c126edd871f73cd571e95f7fcd0c1620dc51fc (patch)
tree882cb8b7c18ad09aeb1d3848d0e01fbf49af0050
parent0321402c9ebcc2ea238542586c61f54c24bb50f6 (diff)
downloadsphinx-git-c4c126edd871f73cd571e95f7fcd0c1620dc51fc.tar.gz
refactoring
-rw-r--r--sphinx/util/nodes.py50
1 files changed, 32 insertions, 18 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index baedce4d5..dd7fa08e5 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -34,6 +34,37 @@ class WarningStream(object):
explicit_title_re = re.compile(r'^(.+?)\s*(?<!\x00)<(.*?)>$', re.DOTALL)
caption_ref_re = explicit_title_re # b/w compat alias
+
+def apply_source_workaround(node):
+ if node.source:
+ return
+
+ # workaround: nodes.term doesn't have source, line and rawsource
+ # (fixed in Docutils r7495)
+ if isinstance(node, nodes.term):
+ definition_list_item = node.parent
+ if definition_list_item.line is not None:
+ node.source = definition_list_item.source
+ node.line = definition_list_item.line - 1
+ node.rawsource = definition_list_item. \
+ rawsource.split("\n", 2)[0]
+ return
+
+ # workaround: docutils-0.10.0 or older's nodes.caption for nodes.figure
+ # and nodes.title for nodes.admonition doesn't have source, line.
+ # this issue was filed to Docutils tracker:
+ # sf.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032
+ # sourceforge.net/p/docutils/patches/108/
+ if (isinstance(node, (
+ nodes.caption,
+ nodes.title,
+ nodes.rubric,
+ ))):
+ node.source = find_source_node(node)
+ node.line = 0 # need fix docutils to get `node.line`
+ return
+
+
IGNORED_NODES = (
nodes.Invisible,
nodes.Inline,
@@ -44,24 +75,7 @@ IGNORED_NODES = (
def extract_messages(doctree):
"""Extract translatable messages from a document tree."""
for node in doctree.traverse(nodes.TextElement):
- # workaround: nodes.term doesn't have source, line and rawsource
- # (fixed in Docutils r7495)
- if isinstance(node, nodes.term) and not node.source:
- definition_list_item = node.parent
- if definition_list_item.line is not None:
- node.source = definition_list_item.source
- node.line = definition_list_item.line - 1
- node.rawsource = definition_list_item.\
- rawsource.split("\n", 2)[0]
- # workaround: docutils-0.10.0 or older's nodes.caption for nodes.figure
- # and nodes.title for nodes.admonition doesn't have source, line.
- # this issue was filed to Docutils tracker:
- # sf.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032
- # sourceforge.net/p/docutils/patches/108/
- if isinstance(node, (nodes.caption, nodes.title, nodes.rubric)) \
- and not node.source:
- node.source = find_source_node(node)
- node.line = 0 #need fix docutils to get `node.line`
+ apply_source_workaround(node)
if not node.source:
continue # built-in message