mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Simplify explicit title matching.
This commit is contained in:
@@ -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)
|
||||
|
||||
+7
-14
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user