summaryrefslogtreecommitdiff
path: root/sphinx/roles.py
diff options
context:
space:
mode:
authorgeorg.brandl <devnull@localhost>2008-03-09 21:31:42 +0000
committergeorg.brandl <devnull@localhost>2008-03-09 21:31:42 +0000
commitacf7ba76be2778dc81c2d082a047778c483da03c (patch)
tree6f607bf159a21f1d6db1c98e0888a7a5c90a9dea /sphinx/roles.py
parent73515bbb31a4ef8c295144407edf66da0248d618 (diff)
downloadsphinx-acf7ba76be2778dc81c2d082a047778c483da03c.tar.gz
A leading '~' in a object cross-reference hides the module part.
Diffstat (limited to 'sphinx/roles.py')
-rw-r--r--sphinx/roles.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/sphinx/roles.py b/sphinx/roles.py
index 99922845..6a5c8599 100644
--- a/sphinx/roles.py
+++ b/sphinx/roles.py
@@ -120,12 +120,21 @@ def xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
rawtext, text, classes=['xref'])], []
pnode = addnodes.pending_xref(rawtext)
pnode['reftype'] = typ
- # if the first character is a dot, search more specific namespaces first
- # else search builtins first
- if text[0:1] == '.' and \
- typ in ('data', 'exc', 'func', 'class', 'const', 'attr', 'meth'):
- text = text[1:]
- pnode['refspecific'] = True
+ innertext = text
+ # special actions for Python object cross-references
+ if typ in ('data', 'exc', 'func', 'class', 'const', 'attr', 'meth'):
+ # if the first character is a dot, search more specific namespaces first
+ # else search builtins first
+ if text[0:1] == '.':
+ text = text[1:]
+ pnode['refspecific'] = True
+ # if the first character is a tilde, don't display the module/class parts
+ # of the contents
+ if text[0:1] == '~':
+ text = text[1:]
+ dot = text.rfind('.')
+ if dot != -1:
+ innertext = text[dot+1:]
if typ == 'term':
pnode['reftarget'] = ws_re.sub(' ', text).lower()
elif typ == 'ref':
@@ -152,7 +161,7 @@ def xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
pnode['reftarget'] = ws_re.sub('', text)
pnode['modname'] = env.currmodule
pnode['classname'] = env.currclass
- pnode += innernodetypes.get(typ, nodes.literal)(rawtext, text, classes=['xref'])
+ pnode += innernodetypes.get(typ, nodes.literal)(rawtext, innertext, classes=['xref'])
return [pnode], []