summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-24 14:00:13 +0900
committerGitHub <noreply@github.com>2021-01-24 14:00:13 +0900
commitee5560b7739932d0a7735be0cc81f28d76a61e92 (patch)
tree08ef05255d52f25da34eefc0af20ff6112d3cc1c
parent37fc43a4d389e173902207e753f4c9e28465e454 (diff)
parenta957d6f7108f2ada9f5c9314d2077f6ccba1fe57 (diff)
downloadsphinx-git-ee5560b7739932d0a7735be0cc81f28d76a61e92.tar.gz
Merge pull request #8732 from tk0miya/refactor_documentation_options
refactor: html theme: Insert documentation_options.js via script_files
-rw-r--r--CHANGES2
-rw-r--r--sphinx/builders/html/__init__.py4
-rw-r--r--sphinx/themes/basic/layout.html3
3 files changed, 6 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index f9c046ca6..3d9f89cd5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -25,6 +25,8 @@ Incompatible changes
:confval:`man_make_section_directory`)
* #8380: html search: search results are wrapped with ``<p>`` instead of
``<div>``
+* html theme: Move a script tag for documentation_options.js in
+ basic/layout.html to ``script_files`` variable
* html theme: Move CSS tags in basic/layout.html to ``css_files`` variable
* #8508: LaTeX: uplatex becomes a default setting of latex_engine for Japanese
documents
diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index a5dfe4104..4e8d6a007 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -310,6 +310,8 @@ class StandaloneHTMLBuilder(Builder):
self.css_files.append(Stylesheet(filename, **kwargs)) # type: ignore
def init_js_files(self) -> None:
+ self.add_js_file('documentation_options.js', id="documentation_options",
+ data_url_root='', priority=200)
self.add_js_file('jquery.js', priority=200)
self.add_js_file('underscore.js', priority=200)
self.add_js_file('doctools.js', priority=200)
@@ -1139,6 +1141,8 @@ def setup_js_tag_helper(app: Sphinx, pagename: str, templatexname: str,
if value is not None:
if key == 'body':
body = value
+ elif key == 'data_url_root':
+ attrs.append('data-url_root="%s"' % pathto('', resource=True))
else:
attrs.append('%s="%s"' % (key, html.escape(value, True)))
if js.filename:
diff --git a/sphinx/themes/basic/layout.html b/sphinx/themes/basic/layout.html
index bae8ddd68..8d1e4f608 100644
--- a/sphinx/themes/basic/layout.html
+++ b/sphinx/themes/basic/layout.html
@@ -17,9 +17,7 @@
{%- set reldelim2 = reldelim2 is not defined and ' |' or reldelim2 %}
{%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and
(sidebars != []) %}
-{%- set url_root = pathto('', 1) %}
{# URL root should never be #, then all links are fragments #}
-{%- if url_root == '#' %}{% set url_root = '' %}{% endif %}
{%- if not embedded and docstitle %}
{%- set titlesuffix = " &#8212; "|safe + docstitle|e %}
{%- else %}
@@ -88,7 +86,6 @@
{%- endmacro %}
{%- macro script() %}
- <script id="documentation_options" data-url_root="{{ url_root }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
{%- for js in script_files %}
{{ js_tag(js) }}
{%- endfor %}