Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

5 participants

Javier G. Sogo Tim Graham Russell Keith-Magee Tai Lee Florian Apolloner
Javier G. Sogo

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
django/contrib/admindocs/utils.py
@@ -92,13 +92,17 @@ def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
- if options is None: options = {}
- if content is None: content = []
- context = inliner.document.settings.default_reference_context
- node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
- return [node], []
+ try:
+ if options is None: options = {}
+ if content is None: content = []
+ context = inliner.document.settings.default_reference_context
+ node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
+ return [node], []
+ except:
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
Russell Keith-Magee

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

Russell Keith-Magee freakboy3742 reopened this
Tai Lee

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

Tim Graham timgraham closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 11, 2012
  1. Javier G. Sogo
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 5 deletions.
  1. +9 −5 django/contrib/admindocs/utils.py
14 django/contrib/admindocs/utils.py
View
@@ -92,13 +92,17 @@ def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
- if options is None: options = {}
- if content is None: content = []
- context = inliner.document.settings.default_reference_context
- node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
- return [node], []
+ try:
+ if options is None: options = {}
+ if content is None: content = []
+ context = inliner.document.settings.default_reference_context
+ node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
+ return [node], []
+ except:
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
+ return _DOCUTILS_DEFAULT_INTERPRETED_ROLE(name, rawtext, text, lineno, inliner, options=options, content=content)
if docutils_is_available:
+ _DOCUTILS_DEFAULT_INTERPRETED_ROLE = docutils.parsers.rst.roles._role_registry.get(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE, None)
docutils.parsers.rst.roles.register_canonical_role('cmsreference', default_reference_role)
docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE = 'cmsreference'
Something went wrong with that request. Please try again.