Skip to content

Commit

Permalink
Remove Sphinx<5 compatibility leftovers (#1512)
Browse files Browse the repository at this point in the history
* 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 <mitya57@users.noreply.github.com>

* 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 <mitya57@users.noreply.github.com>
  • Loading branch information
humitos and mitya57 committed Jan 3, 2024
1 parent 17111ad commit 80de90a
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions sphinx_rtd_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
{%- set titlesuffix = "" %}
{%- endif %}
{%- set lang_attr = 'en' if language == None else (language | replace('_', '-')) %}
{%- set sphinx_writer = 'writer-html5' if html5_doctype else 'writer-html4' -%}

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

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

{#- CSS #}
{%- if sphinx_version_info < (4, 0) -%}
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
{%- endif %}
{%- for css_file in css_files %}
{%- if css_file|attr("filename") %}
{{ css_tag(css_file) }}
Expand All @@ -36,18 +31,19 @@
{%- endif %}
{%- endfor %}

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

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

{#- CANONICAL URL (deprecated) #}
Expand All @@ -66,30 +62,9 @@
<script src="{{ pathto('_static/js/html5shiv.min.js', 1) }}"></script>
<![endif]-->
{%- if not embedded %}
{# 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 #}
{%- if sphinx_version_info >= (1, 8) -%}
{%- if sphinx_version_info < (4, 0) -%}
<script id="documentation_options" data-url_root="{{ url_root }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
{%- endif -%}
{%- for scriptfile in script_files %}
{{ js_tag(scriptfile) }}
{%- endfor %}
{%- else %}
<script>
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'{{ url_root }}',
VERSION:'{{ release|e }}',
LANGUAGE:'{{ language }}',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
HAS_SOURCE: {{ has_source|lower }},
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
};
</script>
{%- for scriptfile in script_files %}
<script src="{{ pathto(scriptfile, 1) }}"></script>
{%- endfor %}
{%- endif %}
{%- for scriptfile in script_files %}
{{ js_tag(scriptfile) }}
{%- endfor %}
<script src="{{ pathto('_static/js/theme.js', 1) }}"></script>

{#- OPENSEARCH #}
Expand Down

0 comments on commit 80de90a

Please sign in to comment.