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

@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''.

@apollo13 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:
@apollo13 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
@timgraham
Owner

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

@timgraham timgraham closed this
@freakboy3742

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

@freakboy3742 freakboy3742 reopened this
@mrmachine

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

@timgraham 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. @jgsogo
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
View
14 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:
@apollo13 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.