Anonymous avatar Anonymous committed 85a7b52

Don't interpret markup in productionlists.

Comments (0)

Files changed (2)

sphinx/directives.py

 
 # ------ production list (for the reference) ---------------------------------------
 
+token_re = re.compile('`([a-z_]+)`')
+
+def token_xrefs(text, env):
+    retnodes = []
+    pos = 0
+    for m in token_re.finditer(text):
+        if m.start() > pos:
+            txt = text[pos:m.start()]
+            retnodes.append(nodes.Text(txt, txt))
+        refnode = addnodes.pending_xref(m.group(1))
+        refnode['reftype'] = 'token'
+        refnode['reftarget'] = m.group(1)
+        refnode['modname'] = env.currmodule
+        refnode['classname'] = env.currclass
+        refnode += nodes.literal(m.group(1), m.group(1), classes=['xref'])
+        retnodes.append(refnode)
+        pos = m.end()
+    if pos < len(text):
+        retnodes.append(nodes.Text(text[pos:], text[pos:]))
+    print retnodes
+    return retnodes
+
 def productionlist_directive(name, arguments, options, content, lineno,
                              content_offset, block_text, state, state_machine):
     env = state.document.settings.env
     messages = []
     i = 0
 
-    # use token as the default role while in production list
-    roles._roles[''] = roles._role_registry['token']
     for rule in arguments[0].split('\n'):
         if i == 0 and ':' not in rule:
             # production group
                 subnode['ids'].append(idname)
             state.document.note_implicit_target(subnode, subnode)
             env.note_token(subnode['tokenname'])
-        inodes, imessages = state.inline_text(tokens, lineno+i)
-        subnode.extend(inodes)
-        messages.extend(imessages)
+        subnode.extend(token_xrefs(tokens, env))
         node.append(subnode)
-    del roles._roles['']
     return [node] + messages
 
 productionlist_directive.content = 0
 def xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
     env = inliner.document.settings.env
     text = utils.unescape(text)
-    # 'token' is the default role inside 'productionlist' directives
-    if typ == '':
-        typ = 'token'
     if typ in ('func', 'meth', 'cfunc') and \
            env.config.get('add_function_parentheses', True):
         text += '()'
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.