Anonymous avatar Anonymous committed fb8cc36

Enable :role:`title <target>` syntax for all xref role types.

Comments (0)

Files changed (1)

     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
-    text = utils.unescape(text)
+    text = utils.unescape(etext)
     targetid = 'index-%s' % env.index_num
     env.index_num += 1
     indexnode = addnodes.index()
         indexnode['entries'] = [('single', text, targetid, text),
                                 ('single', 'environment variable; %s' % text,
                                  targetid, text)]
-        pnode = addnodes.pending_xref(rawtext)
-        pnode['reftype'] = 'envvar'
-        pnode['reftarget'] = text
-        pnode += nodes.strong(text, text, classes=['xref'])
-        return [indexnode, targetnode, pnode], []
+        xref_nodes = xfileref_role(typ, rawtext, etext, lineno, inliner,
+                                   options, content)[0]
+        return [indexnode, targetnode] + xref_nodes, []
     elif typ == 'pep':
         env.note_index_entry('single', 'Python Enhancement Proposals!PEP %s' % text,
                              targetid, 'PEP %s' % text)
     'ref': nodes.emphasis,
     'term': nodes.emphasis,
     'token': nodes.strong,
+    'envvar': nodes.strong,
     'option': addnodes.literal_emphasis,
 }
 
         text = text[1:]
         return [innernodetypes.get(typ, nodes.literal)(
             rawtext, text, classes=['xref'])], []
-    pnode = addnodes.pending_xref(rawtext)
-    pnode['reftype'] = typ
-    innertext = text
+    # we want a cross-reference, create the reference node
+    pnode = addnodes.pending_xref(rawtext, reftype=typ, refcaption=False,
+                                  modname=env.currmodule, classname=env.currclass)
     # 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
             pnode['refspecific'] = True
         # if the first character is a tilde, don't display the module/class parts
         # of the contents
-        if text[0:1] == '~':
+        elif 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':
-        brace = text.find('<')
-        if brace != -1:
-            pnode['refcaption'] = True
-            m = caption_ref_re.match(text)
-            if not m:
-                # fallback
-                pnode['reftarget'] = text[brace+1:]
-                text = text[:brace]
-            else:
-                pnode['reftarget'] = m.group(2)
-                text = m.group(1)
+    innertext = text
+    # look if explicit title and target are given
+    brace = text.find('<')
+    if brace != -1:
+        pnode['refcaption'] = True
+        m = caption_ref_re.match(text)
+        if m:
+            target = m.group(2)
+            innertext = m.group(1)
         else:
-            pnode['refcaption'] = False
-            pnode['reftarget'] = ws_re.sub('', text)
+            # fallback: everything after '<' is the target
+            target = text[brace+1:]
+            innertext = text[:brace]
+    # else, generate target from title
+    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':
+        # strip option marker from target
         if text[0] in '-/':
-            pnode['reftarget'] = text[1:]
+            target = text[1:]
         else:
-            pnode['reftarget'] = text
+            target = text
     else:
-        pnode['reftarget'] = ws_re.sub('', text)
-    pnode['modname'] = env.currmodule
-    pnode['classname'] = env.currclass
+        target = ws_re.sub('', text)
+    pnode['reftarget'] = target
     pnode += innernodetypes.get(typ, nodes.literal)(rawtext, innertext, classes=['xref'])
     return [pnode], []
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.