Skip to content

Commit

Permalink
Merge pull request #1123 from readthedocs/Blendify/sphinx4
Browse files Browse the repository at this point in the history
Add compatibility for sphinx4
  • Loading branch information
agjohnson committed Jul 19, 2021
2 parents 6417def + 0207996 commit 380647d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -8,7 +8,7 @@ commands:
type: string
sphinx-version:
type: string
default: "16,17,18,20,21,22,23,24,30,31,32,33,34,latest"
default: "16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,latest"
steps:
- checkout
- run: pip install --user tox
Expand Down
1 change: 0 additions & 1 deletion sphinx_rtd_theme/__init__.py
Expand Up @@ -31,7 +31,6 @@ def config_initiated(app, config):
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
)


# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
def setup(app):
if python_version[0] < 3:
Expand Down
14 changes: 11 additions & 3 deletions sphinx_rtd_theme/layout.html
Expand Up @@ -9,6 +9,10 @@
{%- 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, _ver_bugfix) = sphinx_version.split('.') | map('int') -%}
{%- set sphinx_version_info = (_ver_major, _ver_minor, _ver_bugfix) -%}

<!DOCTYPE html>
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}" >
<head>
Expand All @@ -20,8 +24,10 @@
{%- endblock -%}

{#- CSS #}
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/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 in css_files %}
{%- if css|attr("rel") %}
<link rel="{{ css.rel }}" href="{{ pathto(css.filename, 1) }}" type="text/css"{% if css.title is not none %} title="{{ css.title }}"{% endif %} />
Expand Down Expand Up @@ -56,8 +62,10 @@
<![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 >= "1.8.0" -%}
{%- 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 %}
Expand Down
2 changes: 1 addition & 1 deletion sphinx_rtd_theme/static/css/theme.css

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions src/sass/_theme_rst.sass
Expand Up @@ -94,11 +94,19 @@
font-family: $code-font-family
font-size: 12px
line-height: 1.4

// Do not allow selection of code block prompts
div.highlight .gp
user-select: none
pointer-events: none

// Do not allow selection of code block prompts and line numbers
div.highlight
span.linenos, .gp
user-select: none
pointer-events: none

span.linenos
display: inline-block
padding-left: 0px
padding-right: ($base-line-height / 2)
margin-right: ($base-line-height / 2)
border-right: 1px solid lighten($table-border-color, 2%)

.code-block-caption
font-style: italic
Expand Down Expand Up @@ -452,6 +460,12 @@
.property
display: inline-block
padding-right: 8px
// This is keywords such as "const"
.k
font-style: italic
.sig-name, .descname, .descclassname
font-family: $code-font-family
color: $black
// Doc links to sourcecode
.viewcode-link, .viewcode-back
display: inline-block
Expand Down
1 change: 1 addition & 0 deletions tests/util.py
Expand Up @@ -33,6 +33,7 @@ def build(root, builder='html', **kwargs):
confoverrides = kwargs.pop('confoverrides', {})
confoverrides['html_theme'] = 'sphinx_rtd_theme'
extensions = confoverrides.get('extensions', [])
extensions.append('sphinx_rtd_theme')
extensions.append('readthedocs_ext.readthedocs')
confoverrides['extensions'] = extensions
kwargs['confoverrides'] = confoverrides
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,36,37,38,39}-sphinx{16,17,18,20,21,22,23,24,30,31,32,33,34,latest}
envlist = py{27,36,37,38,39}-sphinx{16,17,18,20,21,22,23,24,30,31,32,33,34,35,40,41,latest}

[testenv]
setev =
Expand All @@ -22,6 +22,9 @@ deps =
sphinx32: Sphinx < 3.3
sphinx33: Sphinx < 3.4
sphinx34: Sphinx < 3.5
sphinx35: Sphinx < 3.6
sphinx40: Sphinx < 4.1
sphinx41: Sphinx < 4.2
sphinxlatest: Sphinx
commands =
pytest {posargs} tests/
Expand Down

0 comments on commit 380647d

Please sign in to comment.