diff options
| author | Georg Brandl <georg@python.org> | 2010-01-02 20:54:59 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2010-01-02 20:54:59 +0100 |
| commit | 64c741270a7aae68c6279e50fab5ead1fe2f5733 (patch) | |
| tree | b6cc798f602e603e5271ec3eeb5518d47c85eb67 /sphinx/util | |
| parent | 7e8cbbe18b8ef054ecab9b6a0c35dfa52c5ea338 (diff) | |
| parent | 5e16dd1887cd40985476aee5072cd492f0071491 (diff) | |
| download | sphinx-64c741270a7aae68c6279e50fab5ead1fe2f5733.tar.gz | |
merge with 0.6
Diffstat (limited to 'sphinx/util')
| -rw-r--r-- | sphinx/util/__init__.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 3cf58e0e..bfea1c22 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 @@ -442,34 +443,40 @@ def copy_static_entry(source, target, builder, context={}): shutil.copytree(source, target) + +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) |
