summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-01-03 16:04:23 +0100
committerGeorg Brandl <georg@python.org>2010-01-03 16:04:23 +0100
commitbc033e2d4ced76efe960ea557ac56e4142f33222 (patch)
treeb5e92f56e1a73df4d505f335bc7036dddced45e0 /sphinx/util
parente7ead814127708601c5ba64453461ce5f0991bd0 (diff)
parent66febe79c7881126b13fc380b5b66685bd661993 (diff)
downloadsphinx-bc033e2d4ced76efe960ea557ac56e4142f33222.tar.gz
merge with 0.6
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 59589b6d..b719b391 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -32,7 +32,8 @@ ENOENT = getattr(errno, 'ENOENT', 0)
# Generally useful regular expressions.
ws_re = re.compile(r'\s+')
-caption_ref_re = re.compile(r'^([^<]+?)\s*<(.+)>$')
+explicit_title_re = re.compile('^(.+?)\s*<(.*?)>$', re.DOTALL)
+caption_ref_re = explicit_title_re # b/w compat alias
url_re = re.compile(r'(?P<schema>.+)://.*')
# SEP separates path elements in the canonical file names
@@ -450,34 +451,40 @@ def clean_astext(node):
return node.astext()
+def split_explicit_title(text):
+ """Split role content into title and target, if given."""
+ match = explicit_title_re.match(text)
+ if match:
+ return True, match.group(1), match.group(2)
+ return False, text, text
+
+
# monkey-patch Node.traverse to get more speed
# traverse() is called so many times during a build that it saves
# on average 20-25% overall build time!
-def _all_traverse(self):
+def _all_traverse(self, result):
"""Version of Node.traverse() that doesn't need a condition."""
- result = []
result.append(self)
for child in self.children:
- result.extend(child._all_traverse())
+ child._all_traverse(result)
return result
-def _fast_traverse(self, cls):
+def _fast_traverse(self, cls, result):
"""Version of Node.traverse() that only supports instance checks."""
- result = []
if isinstance(self, cls):
result.append(self)
for child in self.children:
- result.extend(child._fast_traverse(cls))
+ child._fast_traverse(cls, result)
return result
def _new_traverse(self, condition=None,
include_self=1, descend=1, siblings=0, ascend=0):
if include_self and descend and not siblings and not ascend:
if condition is None:
- return self._all_traverse()
+ return self._all_traverse([])
elif isinstance(condition, (types.ClassType, type)):
- return self._fast_traverse(condition)
+ return self._fast_traverse(condition, [])
return self._old_traverse(condition, include_self,
descend, siblings, ascend)