Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying pygments theme using module.Class syntax #1593

Open
cmarqu opened this issue Dec 14, 2023 · 3 comments
Open

Support specifying pygments theme using module.Class syntax #1593

cmarqu opened this issue Dec 14, 2023 · 3 comments

Comments

@cmarqu
Copy link
Contributor

cmarqu commented Dec 14, 2023

Sphinx allows setting the pygments style not only via "stylename" but also via a string containing module.Class syntax
(handled in
https://github.com/sphinx-doc/sphinx/blob/35965903177c6ed9a6afb62ccd33243a746a3fc0/sphinx/highlighting.py#L112).

However, pydata-sphinx-theme doesn't support that syntax due to the following check:

if style_name not in pygments_styles:

(Using my own pygments style does work when I add an entry point as shown in https://github.com/pygments/pygments-plugin-scaffolding/blob/main/pyproject.toml)

Some more detail is in sphinx-doc/sphinx#9105 (comment)

@drammock
Copy link
Collaborator

Agreed, seems like we should support the module.Class syntax too. Are you up for opening a PR to implement that?

@cmarqu
Copy link
Contributor Author

cmarqu commented Dec 15, 2023

I didn't immediately see how to do it, but I'll try to take another look.

@12rambau
Copy link
Collaborator

12rambau commented Jan 2, 2024

In our codebase, the pygments is simply used to generate 2 custom stylesheets. They are both createde by this function:

def get_pygments_stylesheet(light_style: str, dark_style: str) -> str:

In short you create the classic html output and then encapsulate it in the correct "theme" selector.

If you can still perform this trick with a custom molude.Class syntax then the sanity check can be reduced to only "str" entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants