diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 4beadab1e..bd8db9b54 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -505,7 +505,6 @@ class StandaloneHTMLBuilder(Builder): 'logo': logo, 'favicon': favicon, 'html5_doctype': html5_ready and not self.config.html4_writer, - 'pygments_dark_style': self.dark_highlighter is not None, } if self.theme: self.globalcontext.update( @@ -743,6 +742,9 @@ class StandaloneHTMLBuilder(Builder): if self.dark_highlighter: with open(path.join(self.outdir, '_static', 'pygments_dark.css'), 'w') as f: f.write(self.dark_highlighter.get_stylesheet()) + self.add_css_file('pygments_dark.css', + media='(prefers-color-scheme: dark)', + id='pygments_dark_css') def create_pygments_aux_style_files(self) -> None: """create a style file for pygments.""" diff --git a/sphinx/themes/basic/layout.html b/sphinx/themes/basic/layout.html index 0cb54e18a..9692ea2c4 100644 --- a/sphinx/themes/basic/layout.html +++ b/sphinx/themes/basic/layout.html @@ -96,9 +96,6 @@ {%- macro css() %} - {%- if pygments_dark_style %} - - {%- endif %} {%- for css in css_files %} {%- if css|attr("filename") %} {{ css_tag(css) }}