Skip to content

Commit 80de90a

Browse files
humitosmitya57
andauthored
Remove Sphinx<5 compatibility leftovers (#1512)
* Remove Sphinx<5 compatibility Since 2.0 we do not support Sphinx<5. * Always use `writer-html5` Since 2.0 HTML4 writer is not supported. * Use `css_tag` helper to inject CSS files * Revert "Remove Sphinx<5 compatibility" Keep `sphinx_version_info`. It will be required. This reverts commit 3afbed2. * Set `data-content_root` for Sphinx >= 7.2 Copied from #1507 * Default value for `DISPLAY` and `--new-tab` * Visual test with Firefox and tox Allows developer to run ``` tox -e py310-sphinx72-firefox ``` This will run the tests and open a Firefox after building the demo site showing the `demo/demo.html` page on it. Then, you can also run: ``` tox -e py310-sphinx61-firefox ``` and compare the visual differences. Idea copied from #1388 Closes #1388 * Update sphinx_rtd_theme/layout.html Co-authored-by: Dmitry Shachnev <[email protected]> * Remove code from merge conflict * Revert a mistake done on merging * Update CSS logic again * Minor refactor to undocumented `extra_css_files` option --------- Co-authored-by: Dmitry Shachnev <[email protected]>
1 parent 17111ad commit 80de90a

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

sphinx_rtd_theme/layout.html

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
{%- set titlesuffix = "" %}
88
{%- endif %}
99
{%- set lang_attr = 'en' if language == None else (language | replace('_', '-')) %}
10-
{%- set sphinx_writer = 'writer-html5' if html5_doctype else 'writer-html4' -%}
1110

1211
{# Build sphinx_version_info tuple from sphinx_version string in pure Jinja #}
1312
{%- set (_ver_major, _ver_minor) = (sphinx_version.split('.') | list)[:2] | map('int') -%}
1413
{%- set sphinx_version_info = (_ver_major, _ver_minor, -1) -%}
1514

1615
<!DOCTYPE html>
17-
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}"{% if sphinx_version_info >= (7, 2) %} data-content_root="{{ content_root }}"{% endif %}>
16+
<html class="writer-html5" lang="{{ lang_attr }}"{% if sphinx_version_info >= (7, 2) %} data-content_root="{{ content_root }}"{% endif %}>
1817
<head>
1918
<meta charset="utf-8" />
2019
{{- metatags }}
@@ -24,10 +23,6 @@
2423
{%- endblock -%}
2524

2625
{#- CSS #}
27-
{%- if sphinx_version_info < (4, 0) -%}
28-
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
29-
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
30-
{%- endif %}
3126
{%- for css_file in css_files %}
3227
{%- if css_file|attr("filename") %}
3328
{{ css_tag(css_file) }}
@@ -36,18 +31,19 @@
3631
{%- endif %}
3732
{%- endfor %}
3833

39-
{# "extra_css_files" is a theme option and it's always a string #}
34+
{#
35+
"extra_css_files" is an undocumented Read the Docs theme specific option.
36+
There is no need to check for ``|attr("filename")`` here because it's always a string.
37+
Note that this option should be removed in favor of regular ``html_css_files``:
38+
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_css_files
39+
#}
4040
{%- for css_file in extra_css_files %}
4141
<link rel="stylesheet" href="{{ pathto(css_file, 1)|escape }}" type="text/css" />
4242
{%- endfor -%}
4343

44-
{#- FAVICON
45-
favicon_url is the only context var necessary since Sphinx 4.
46-
In Sphinx<4, we use favicon but need to prepend path info.
47-
#}
48-
{%- set _favicon_url = favicon_url | default(pathto('_static/' + (favicon or ""), 1)) %}
49-
{%- if favicon_url or favicon %}
50-
<link rel="shortcut icon" href="{{ _favicon_url }}"/>
44+
{#- FAVICON #}
45+
{%- if favicon_url %}
46+
<link rel="shortcut icon" href="{{ favicon_url }}"/>
5147
{%- endif %}
5248

5349
{#- CANONICAL URL (deprecated) #}
@@ -66,30 +62,9 @@
6662
<script src="{{ pathto('_static/js/html5shiv.min.js', 1) }}"></script>
6763
<![endif]-->
6864
{%- if not embedded %}
69-
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
70-
{%- if sphinx_version_info >= (1, 8) -%}
71-
{%- if sphinx_version_info < (4, 0) -%}
72-
<script id="documentation_options" data-url_root="{{ url_root }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
73-
{%- endif -%}
74-
{%- for scriptfile in script_files %}
75-
{{ js_tag(scriptfile) }}
76-
{%- endfor %}
77-
{%- else %}
78-
<script>
79-
var DOCUMENTATION_OPTIONS = {
80-
URL_ROOT:'{{ url_root }}',
81-
VERSION:'{{ release|e }}',
82-
LANGUAGE:'{{ language }}',
83-
COLLAPSE_INDEX:false,
84-
FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
85-
HAS_SOURCE: {{ has_source|lower }},
86-
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
87-
};
88-
</script>
89-
{%- for scriptfile in script_files %}
90-
<script src="{{ pathto(scriptfile, 1) }}"></script>
91-
{%- endfor %}
92-
{%- endif %}
65+
{%- for scriptfile in script_files %}
66+
{{ js_tag(scriptfile) }}
67+
{%- endfor %}
9368
<script src="{{ pathto('_static/js/theme.js', 1) }}"></script>
9469

9570
{#- OPENSEARCH #}

0 commit comments

Comments
 (0)