mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Enable :role:title <target>
syntax for all xref role types.
This commit is contained in:
parent
d739756f2a
commit
14da7605e4
@ -37,9 +37,9 @@ for rolename, nodeclass in generic_docroles.iteritems():
|
|||||||
roles.register_generic_role(rolename, nodeclass)
|
roles.register_generic_role(rolename, nodeclass)
|
||||||
|
|
||||||
|
|
||||||
def indexmarkup_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
def indexmarkup_role(typ, rawtext, etext, lineno, inliner, options={}, content=[]):
|
||||||
env = inliner.document.settings.env
|
env = inliner.document.settings.env
|
||||||
text = utils.unescape(text)
|
text = utils.unescape(etext)
|
||||||
targetid = 'index-%s' % env.index_num
|
targetid = 'index-%s' % env.index_num
|
||||||
env.index_num += 1
|
env.index_num += 1
|
||||||
indexnode = addnodes.index()
|
indexnode = addnodes.index()
|
||||||
@ -52,11 +52,9 @@ def indexmarkup_role(typ, rawtext, text, lineno, inliner, options={}, content=[]
|
|||||||
indexnode['entries'] = [('single', text, targetid, text),
|
indexnode['entries'] = [('single', text, targetid, text),
|
||||||
('single', 'environment variable; %s' % text,
|
('single', 'environment variable; %s' % text,
|
||||||
targetid, text)]
|
targetid, text)]
|
||||||
pnode = addnodes.pending_xref(rawtext)
|
xref_nodes = xfileref_role(typ, rawtext, etext, lineno, inliner,
|
||||||
pnode['reftype'] = 'envvar'
|
options, content)[0]
|
||||||
pnode['reftarget'] = text
|
return [indexnode, targetnode] + xref_nodes, []
|
||||||
pnode += nodes.strong(text, text, classes=['xref'])
|
|
||||||
return [indexnode, targetnode, pnode], []
|
|
||||||
elif typ == 'pep':
|
elif typ == 'pep':
|
||||||
env.note_index_entry('single', 'Python Enhancement Proposals!PEP %s' % text,
|
env.note_index_entry('single', 'Python Enhancement Proposals!PEP %s' % text,
|
||||||
targetid, 'PEP %s' % text)
|
targetid, 'PEP %s' % text)
|
||||||
@ -100,6 +98,7 @@ innernodetypes = {
|
|||||||
'ref': nodes.emphasis,
|
'ref': nodes.emphasis,
|
||||||
'term': nodes.emphasis,
|
'term': nodes.emphasis,
|
||||||
'token': nodes.strong,
|
'token': nodes.strong,
|
||||||
|
'envvar': nodes.strong,
|
||||||
'option': addnodes.literal_emphasis,
|
'option': addnodes.literal_emphasis,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +117,9 @@ def xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
|||||||
text = text[1:]
|
text = text[1:]
|
||||||
return [innernodetypes.get(typ, nodes.literal)(
|
return [innernodetypes.get(typ, nodes.literal)(
|
||||||
rawtext, text, classes=['xref'])], []
|
rawtext, text, classes=['xref'])], []
|
||||||
pnode = addnodes.pending_xref(rawtext)
|
# we want a cross-reference, create the reference node
|
||||||
pnode['reftype'] = typ
|
pnode = addnodes.pending_xref(rawtext, reftype=typ, refcaption=False,
|
||||||
innertext = text
|
modname=env.currmodule, classname=env.currclass)
|
||||||
# special actions for Python object cross-references
|
# special actions for Python object cross-references
|
||||||
if typ in ('data', 'exc', 'func', 'class', 'const', 'attr', 'meth'):
|
if typ in ('data', 'exc', 'func', 'class', 'const', 'attr', 'meth'):
|
||||||
# if the first character is a dot, search more specific namespaces first
|
# if the first character is a dot, search more specific namespaces first
|
||||||
@ -130,37 +129,38 @@ def xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
|||||||
pnode['refspecific'] = True
|
pnode['refspecific'] = True
|
||||||
# if the first character is a tilde, don't display the module/class parts
|
# if the first character is a tilde, don't display the module/class parts
|
||||||
# of the contents
|
# of the contents
|
||||||
if text[0:1] == '~':
|
elif text[0:1] == '~':
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
dot = text.rfind('.')
|
dot = text.rfind('.')
|
||||||
if dot != -1:
|
if dot != -1:
|
||||||
innertext = text[dot+1:]
|
innertext = text[dot+1:]
|
||||||
if typ == 'term':
|
innertext = text
|
||||||
pnode['reftarget'] = ws_re.sub(' ', text).lower()
|
# look if explicit title and target are given
|
||||||
elif typ == 'ref':
|
|
||||||
brace = text.find('<')
|
brace = text.find('<')
|
||||||
if brace != -1:
|
if brace != -1:
|
||||||
pnode['refcaption'] = True
|
pnode['refcaption'] = True
|
||||||
m = caption_ref_re.match(text)
|
m = caption_ref_re.match(text)
|
||||||
if not m:
|
if m:
|
||||||
# fallback
|
target = m.group(2)
|
||||||
pnode['reftarget'] = text[brace+1:]
|
innertext = m.group(1)
|
||||||
text = text[:brace]
|
|
||||||
else:
|
else:
|
||||||
pnode['reftarget'] = m.group(2)
|
# fallback: everything after '<' is the target
|
||||||
text = m.group(1)
|
target = text[brace+1:]
|
||||||
else:
|
innertext = text[:brace]
|
||||||
pnode['refcaption'] = False
|
# else, generate target from title
|
||||||
pnode['reftarget'] = ws_re.sub('', text)
|
elif typ == 'term':
|
||||||
|
# normalize whitespace in definition terms (if the term reference is
|
||||||
|
# broken over a line, a newline will be in text)
|
||||||
|
target = ws_re.sub(' ', text).lower()
|
||||||
elif typ == 'option':
|
elif typ == 'option':
|
||||||
|
# strip option marker from target
|
||||||
if text[0] in '-/':
|
if text[0] in '-/':
|
||||||
pnode['reftarget'] = text[1:]
|
target = text[1:]
|
||||||
else:
|
else:
|
||||||
pnode['reftarget'] = text
|
target = text
|
||||||
else:
|
else:
|
||||||
pnode['reftarget'] = ws_re.sub('', text)
|
target = ws_re.sub('', text)
|
||||||
pnode['modname'] = env.currmodule
|
pnode['reftarget'] = target
|
||||||
pnode['classname'] = env.currclass
|
|
||||||
pnode += innernodetypes.get(typ, nodes.literal)(rawtext, innertext, classes=['xref'])
|
pnode += innernodetypes.get(typ, nodes.literal)(rawtext, innertext, classes=['xref'])
|
||||||
return [pnode], []
|
return [pnode], []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user