diff options
| author | Adam Johnson <me@adamj.eu> | 2020-03-31 09:37:38 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2020-04-01 15:15:21 +0200 |
| commit | 0342d47e7a8571242a570b91dea3c137436740d4 (patch) | |
| tree | ba498b92af4257836298bd28d5be9ec6458799ae /docs/_ext | |
| parent | c9437596fe54fb5cf0330ee5a96e260903a2d683 (diff) | |
[3.0.x] Prevented (and corrected) single backtick usage in docs.
Backport of 1cdfe8d91215eefaa18c398069dd9c6879a9511d from master.
Diffstat (limited to 'docs/_ext')
| -rw-r--r-- | docs/_ext/djangodocs.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py index 95ae530680..95d8e89c9b 100644 --- a/docs/_ext/djangodocs.py +++ b/docs/_ext/djangodocs.py @@ -11,10 +11,11 @@ from docutils.statemachine import ViewList from sphinx import addnodes from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.directives import CodeBlock +from sphinx.errors import SphinxError from sphinx.domains.std import Cmdoption from sphinx.errors import ExtensionError from sphinx.util import logging -from sphinx.util.console import bold +from sphinx.util.console import bold, red from sphinx.writers.html import HTMLTranslator logger = logging.getLogger(__name__) @@ -67,6 +68,7 @@ def setup(app): ) app.add_directive('console', ConsoleDirective) app.connect('html-page-context', html_page_context_hook) + app.add_role('default-role-error', default_role_error) return {'parallel_read_safe': True} @@ -371,3 +373,14 @@ def html_page_context_hook(app, pagename, templatename, context, doctree): # This way it's include only from HTML files rendered from reST files where # the ConsoleDirective is used. context['include_console_assets'] = getattr(doctree, '_console_directive_used_flag', False) + + +def default_role_error( + name, rawtext, text, lineno, inliner, options=None, content=None +): + msg = ( + "Default role used (`single backticks`) at line %s: %s. Did you mean " + "to use two backticks for ``code``, or miss an underscore for a " + "`link`_ ?" % (lineno, rawtext) + ) + raise SphinxError(red(msg)) |
