summaryrefslogtreecommitdiff
path: root/sphinx
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-08-11 21:17:30 +0200
committerGeorg Brandl <georg@python.org>2009-08-11 21:17:30 +0200
commit43b0f0519a9d14a32e0607b79035f67bbe70a01b (patch)
treeda4730b9568c009eaa4bbf5f52d55eb5d3c8a2d4 /sphinx
parentcc6fb3d54926794ec20124b7f9e58956057f61d2 (diff)
downloadsphinx-43b0f0519a9d14a32e0607b79035f67bbe70a01b.tar.gz
Simplify explicit title matching.
Diffstat (limited to 'sphinx')
-rw-r--r--sphinx/directives/other.py5
-rw-r--r--sphinx/util/__init__.py21
2 files changed, 10 insertions, 16 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index 6e2712a8..50db49ce 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -14,7 +14,8 @@ from docutils.parsers.rst import directives
from sphinx import addnodes
from sphinx.locale import pairindextypes
-from sphinx.util import patfilter, ws_re, caption_ref_re, url_re, docname_join
+from sphinx.util import patfilter, ws_re, url_re, docname_join, \
+ explicit_title_re
from sphinx.util.compat import Directive, directive_dwim, make_admonition
@@ -55,7 +56,7 @@ class TocTree(Directive):
continue
if not glob:
# look for explicit titles ("Some Title <document>")
- m = caption_ref_re.match(entry)
+ m = explicit_title_re.match(entry)
if m:
ref = m.group(2)
title = m.group(1)
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 9d677233..72b2a9c8 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -28,7 +28,8 @@ import sphinx
# Generally useful regular expressions.
ws_re = re.compile(r'\s+')
-caption_ref_re = re.compile(r'^([^<]+?)\s*<(.+)>$')
+explicit_title_re = re.compile('^(.+?)\s*<(.*?)>$')
+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
@@ -437,21 +438,13 @@ 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."""
- brace = text.find('<')
- if brace != -1:
- m = caption_ref_re.match(text)
- if m:
- target = m.group(2)
- title = m.group(1)
- else:
- # fallback: everything after '<' is the target
- target = text[brace+1:]
- title = text[:brace]
- return True, title, target
- else:
- return False, text, text
+ match = explicit_title_re.match(text)
+ if match:
+ return True, m.group(1), m.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