pydata_sphinx_theme.pygment#
Handle pygment 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. |
Return theme options for the application w/ a fallback if they don't exist. |
|
|
Wraps the Sphinx logger to allow warning suppression. |
|
Overwrite pygments.css to allow dynamic light/dark switching. |
Module Contents#
- 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.get_theme_options_dict(app)[source]#
Return theme options for the application w/ a fallback if they don’t exist.
The “top-level” mapping (the one we should usually check first, and modify if desired) is
app.builder.theme_options
. It is created by Sphinx as a copy ofapp.config.html_theme_options
(containing user-configs from theirconf.py
); sometimes that copy never occurs though which is why we check both.- Parameters:
- Return type:
Dict[str, Any]
- pydata_sphinx_theme.pygment.maybe_warn(app, msg, *args, **kwargs)[source]#
Wraps the Sphinx logger to allow warning suppression.
- Parameters:
- 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: