\n')
+ raise nodes.SkipNode
+ else:
+ self.visit_literal_block(node)
+
+
+class ConsoleDirective(CodeBlock):
+ """
+ A reStructuredText directive which renders a two-tab code block in which
+ the second tab shows a Windows command line equivalent of the usual
+ Unix-oriented examples.
+ """
+ required_arguments = 0
+ # The 'doscon' Pygments formatter needs a prompt like this. '>' alone
+ # won't do it because then it simply paints the whole command line as a
+ # grey comment with no highlighting at all.
+ WIN_PROMPT = r'...\> '
+
+ def run(self):
+
+ def args_to_win(cmdline):
+ changed = False
+ out = []
+ for token in cmdline.split():
+ if token[:2] == './':
+ token = token[2:]
+ changed = True
+ elif token[:2] == '~/':
+ token = '%HOMEPATH%\\' + token[2:]
+ changed = True
+ elif token == 'make':
+ token = 'make.bat'
+ changed = True
+ if '://' not in token and 'git' not in cmdline:
+ out.append(token.replace('/', '\\'))
+ changed = True
+ else:
+ out.append(token)
+ if changed:
+ return ' '.join(out)
+ return cmdline
+
+ def cmdline_to_win(line):
+ if line.startswith('# '):
+ return 'REM ' + args_to_win(line[2:])
+ if line.startswith('$ # '):
+ return 'REM ' + args_to_win(line[4:])
+ if line.startswith('$ ./manage.py'):
+ return 'manage.py ' + args_to_win(line[13:])
+ if line.startswith('$ manage.py'):
+ return 'manage.py ' + args_to_win(line[11:])
+ if line.startswith('$ ./runtests.py'):
+ return 'runtests.py ' + args_to_win(line[15:])
+ if line.startswith('$ ./'):
+ return args_to_win(line[4:])
+ if line.startswith('$ python3'):
+ return 'py ' + args_to_win(line[9:])
+ if line.startswith('$ python'):
+ return 'py ' + args_to_win(line[8:])
+ if line.startswith('$ '):
+ return args_to_win(line[2:])
+ return None
+
+ def code_block_to_win(content):
+ bchanged = False
+ lines = []
+ for line in content:
+ modline = cmdline_to_win(line)
+ if modline is None:
+ lines.append(line)
+ else:
+ lines.append(self.WIN_PROMPT + modline)
+ bchanged = True
+ if bchanged:
+ return ViewList(lines)
+ return None
+
+ env = self.state.document.settings.env
+ self.arguments = ['console']
+ lit_blk_obj = super().run()[0]
+
+ # Only do work when the djangohtml HTML Sphinx builder is being used,
+ # invoke the default behavior for the rest.
+ if env.app.builder.name not in ('djangohtml', 'json'):
+ return [lit_blk_obj]
+
+ lit_blk_obj['uid'] = str(env.new_serialno('console'))
+ # Only add the tabbed UI if there is actually a Windows-specific
+ # version of the CLI example.
+ win_content = code_block_to_win(self.content)
+ if win_content is None:
+ lit_blk_obj['win_console_text'] = None
+ else:
+ self.content = win_content
+ lit_blk_obj['win_console_text'] = super().run()[0].rawsource
+
+ # Replace the literal_node object returned by Sphinx's CodeBlock with
+ # the ConsoleNode wrapper.
+ return [ConsoleNode(lit_blk_obj)]
+
+
+def html_page_context_hook(app, pagename, templatename, context, doctree):
+ # Put a bool on the context used to render the template. It's used to
+ # control inclusion of console-tabs.css and activation of the JavaScript.
+ # 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`): %s. Did you mean to use two "
+ "backticks for ``code``, or miss an underscore for a `link`_ ?"
+ % rawtext
+ )
+ logger.warning(msg, location=(inliner.document.current_source, lineno))
+ return [nodes.Text(text)], []
diff --git a/docs/conf.py b/docs/conf.py
index a50963b..3f2fafe 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -350,7 +350,7 @@ texinfo_documents = [
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"python": ('https://docs.python.org/', None),
- "django": ('https://docs.djangoproject.com/en/1.9/', 'django.inv'),
+ "django": ('https://docs.djangoproject.com/en/3.2/', 'django.inv'),
}
autodoc_member_order = 'bysource'
@@ -360,8 +360,8 @@ locale_dirs = ['../test_venv/lib/python2.7/site-packages/django/conf/locale/']
def _download_django_inv():
import requests
- with open(_download_django_inv.path, 'w') as f:
- r = requests.get("https://docs.djangoproject.com/en/1.9/_objects")
+ with open(_download_django_inv.path, 'wb') as f:
+ r = requests.get("https://docs.djangoproject.com/en/3.2/_objects")
f.write(r.content)
_download_django_inv.path = os.path.abspath(os.path.join(os.path.dirname(__file__), "django.inv"))
diff --git a/docs/index.rst b/docs/index.rst
index 7ad7ed1..cb7041d 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -23,6 +23,7 @@ Indices and tables
==================
* :ref:`genindex`
+
.. * :ref:`modindex`
.. * :ref:`search`