Use add_css_file instead of template modification

This commit is contained in:
Septatrix 2020-03-13 15:59:28 +01:00
parent d269483a6f
commit 25f90ed3ee
2 changed files with 3 additions and 4 deletions

View File

@ -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."""

View File

@ -96,9 +96,6 @@
{%- macro 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 pygments_dark_style %}
<link rel="stylesheet" href="{{ pathto('_static/pygments_dark.css', 1) }}" type="text/css" media="(prefers-color-scheme: dark)" id="pygments_dark_css" />
{%- endif %}
{%- for css in css_files %}
{%- if css|attr("filename") %}
{{ css_tag(css) }}