pydata_sphinx_theme.pygment#

Handle pygment css.

inspired by the Furo theme pradyunsg/furo

Module Contents#

Functions#

_get_styles(formatter, prefix)

Get styles out of a formatter, where everything has the correct prefix.

get_pygments_stylesheet(light_style, dark_style)

Generate the theme-specific pygments.css.

overwrite_pygments_css(app[, exception])

Overwrite pygments.css to allow dynamic light/dark switching.

pydata_sphinx_theme.pygment._get_styles(formatter, prefix)[source]#

Get styles out of a formatter, where everything has the correct prefix.

Parameters:
  • formatter (pygments.formatters.HtmlFormatter) –

  • prefix (str) –

Return type:

None

pydata_sphinx_theme.pygment.get_pygments_stylesheet(light_style, dark_style)[source]#

Generate the theme-specific pygments.css.

There is no way to tell Sphinx how the theme handles modes.

Parameters:
  • light_style (str) –

  • dark_style (str) –

Return type:

str

pydata_sphinx_theme.pygment.overwrite_pygments_css(app, exception=None)[source]#

Overwrite pygments.css to allow dynamic light/dark switching.

Sphinx natively supports config variables pygments_style and pygments_dark_style. However, quoting from www.sphinx-doc.org/en/master/development/theming.html#creating-themes

The pygments_dark_style setting […is used] when the CSS media query (prefers-color-scheme: dark) evaluates to true.

This does not allow for dynamic switching by the user, so at build time we overwrite the pygment.css file so that it embeds 2 versions:

  • the light theme prefixed with “[data-theme=”light”]”

  • the dark theme prefixed with “[data-theme=”dark”]”

Fallbacks are defined in this function in case the user-requested (or our theme-specified) pygments theme is not available.

Parameters:

app (sphinx.application.Sphinx) –