Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

fixed bug#6681: RST default reference role tries docutils' default role ... #368

Closed
wants to merge 1 commit into from

5 participants

jgsogo Tim Graham Russell Keith-Magee Tai Lee Florian Apolloner
jgsogo

Fixes bug#6681 as described in https://code.djangoproject.com/ticket/6681

Docutils establish a ''DEFAULT_INTERPRETED_ROLE'' which is overriden by django with cmsreference role.

Django's role is intended to work on admin docs, but it's not suitable for general purpose as it needs some keys in ''inliner.document.settings''.

Florian Apolloner apollo13 commented on the diff September 16, 2012
django/contrib/admindocs/utils.py
@@ -92,13 +92,17 @@ def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
92 92
     docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
93 93
 
94 94
 def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
95  
-    if options is None: options = {}
96  
-    if content is None: content = []
97  
-    context = inliner.document.settings.default_reference_context
98  
-    node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
99  
-    return [node], []
  95
+    try:
  96
+        if options is None: options = {}
  97
+        if content is None: content = []
  98
+        context = inliner.document.settings.default_reference_context
  99
+        node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
  100
+        return [node], []
  101
+    except:
1
Florian Apolloner Owner

Is there really no alternative to a plain except? This would even catch KeyboardInterupt etc which we surely don't want. Which exceptions can occur here? As a last resort you can use except Exception, but I'd prefer it explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tim Graham
Owner

Ticket has been closed as contrib.markup has been deprecated.

Tim Graham timgraham closed this May 31, 2013
Russell Keith-Magee
Owner

Reopening, as this isn't a problem with contrib.markup, but a problem with contrib.admindocs.

Russell Keith-Magee freakboy3742 reopened this June 17, 2013
Tai Lee

An improved fix at #1277 -- no need to set a global default at all.

Tim Graham timgraham closed this June 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 11, 2012
jgsogo fixed bug#6681: RST default reference role tries docutils' default ro…
…le before raising
a854461
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 9 additions and 5 deletions. Show diff stats Hide diff stats

  1. 14  django/contrib/admindocs/utils.py
14  django/contrib/admindocs/utils.py
@@ -92,13 +92,17 @@ def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
92 92
     docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
93 93
 
94 94
 def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
95  
-    if options is None: options = {}
96  
-    if content is None: content = []
97  
-    context = inliner.document.settings.default_reference_context
98  
-    node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
99  
-    return [node], []
  95
+    try:
  96
+        if options is None: options = {}
  97
+        if content is None: content = []
  98
+        context = inliner.document.settings.default_reference_context
  99
+        node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
  100
+        return [node], []
  101
+    except:
  102
+        return _DOCUTILS_DEFAULT_INTERPRETED_ROLE(name, rawtext, text, lineno, inliner, options=options, content=content)
100 103
 
101 104
 if docutils_is_available:
  105
+    _DOCUTILS_DEFAULT_INTERPRETED_ROLE = docutils.parsers.rst.roles._role_registry.get(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE, None)
102 106
     docutils.parsers.rst.roles.register_canonical_role('cmsreference', default_reference_role)
103 107
     docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE = 'cmsreference'
104 108
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.