pydata_sphinx_theme.pygments#
Handle Pygments css.
inspired by the Furo theme pradyunsg/furo
Functions#
|
Get styles out of a formatter, where everything has the correct prefix. |
|
Generate the theme-specific pygments.css. |
|
Overwrite pygments.css to allow dynamic light/dark switching. |
Module Contents#
- pydata_sphinx_theme.pygments._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.pygments.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.pygments.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: