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

Instructions to change the dark mode code block styling don't work #49

Closed
gilch opened this issue Dec 11, 2020 · 16 comments
Closed

Instructions to change the dark mode code block styling don't work #49

gilch opened this issue Dec 11, 2020 · 16 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@gilch
Copy link

gilch commented Dec 11, 2020

URL: https://pradyunsg.me/furo/customisation/colors/#code-block-styling

What is missing or inaccurate about the content on this page?

Not sure if this is a doc issue or a bug. Instructions to change the dark mode code block styling don't work. (They do work for light mode.) Tested using Sphinx==3.3.1 and furo==2020.12.9b21, the latest versions released on PyPI.

I pasted these lines in my docs/conf.py used by Sphinx.

pygments_style = "sphinx"
pygments_dark_style = "monokai"

Changing pygments_style to another valid Pygments style affects the syntax highlighting in light mode when I rebuild the docs with Sphinx, but changing pygments_dark_style doesn't do anything. Dark mode is always the same style.

@gilch gilch added the documentation Improvements or additions to documentation label Dec 11, 2020
@pradyunsg
Copy link
Owner

HUH! Indeed.

https://github.com/sphinx-doc/sphinx/blob/9cf28264917800534e56a92c1fa5c1196c73e73f/sphinx/builders/html/__init__.py#L264

Looks like I've read the Sphinx code wrong! Sphinx doesn't seem to allow customising the dark color theme out-of-the-box. I might need to start getting hacky about this. :o

@pradyunsg pradyunsg added the bug Something isn't working label Dec 12, 2020
@pradyunsg
Copy link
Owner

Fixed in d5df1d4. :)

@gilch
Copy link
Author

gilch commented Dec 29, 2020

@pradyunsg I updated to furo==2020.12.28b23 and it's still not working for me. The dark style is still locked on native.

I tried deleting the build folder and loading the page with no browser cache. No luck. I double-checked site-packages and it appears to have your changes. E.g. __init__.py has the from sphinx.highlighting import PygmentsBridge and def _builder_inited(app):

@pradyunsg
Copy link
Owner

I think I reproduced the behaviour you're describing and released a fix in beta24. Try that out and lemme know if it works! :)

@gilch
Copy link
Author

gilch commented Dec 30, 2020

@pradyunsg Updated to furo==2020.12.30.beta24. No luck. I'm still locked on native in dark mode.

@pradyunsg
Copy link
Owner

Try cleaning up the previous build's artifacts? I'm unable to reproduce this.

If it's still happening, could you provide a reproducer for this (and reopen the issue as well)? :)

@gilch
Copy link
Author

gilch commented Dec 30, 2020

Do you mean open a new issue for the same issue? I don't have the permissions to have a reopen button for this one.

I tried in a fresh virtual environment. pip install -r requirements.txt containing:

sphinx==3.1.2
furo==2020.12.30.beta24

I did a sphinx-quickstart in an empty directory with default settings and Furo for the required ones.
I opened the generated conf.py and replaced the line

html_theme = 'alabaster'

with

html_theme = 'furo'
pygments_style = "sphinx"
pygments_dark_style = "monokai"

I appended the lines

.. code-block:: Python

   def foo(a=1,b='b'): pass

to the generated index.rst to have some code to highlight.

I ran make html.
I found the generated pages in _build/html/ and served the index.html in PyCharm by using the "open with Edge" button. The dark style is still native, not monokai.


The browser and server don't seem relevant however. I double-checked the _build/html/static/pygments_dark.css and it's identical to the file loaded by Edge. Monokai isn't in the build.

I manually changed the line

.highlight .k { color: #6ab825; font-weight: bold } /* Keyword */

in pygments_dark.css to

.highlight .k { color: #fff; font-weight: bold } /* Keyword */

and the highlighting color changed, so this is the stylesheet that is definitely being applied in dark mode.

I checked site-packages/furo/__init__.py, and it contains __version__ = "2020.12.30.beta24".

I appended the line

import furo; print("Furo:", furo.__version__)

to conf.py and it prints out Furo: 2020.12.30.beta24 when I run make html.

I added a breakpoint() to the end of _builder_inited() in site-packages:

(Pdb) app.config.pygments_dark_style
'native'

That looks wrong. I changed it like so:

(Pdb) builder.dark_highlighter = PygmentsBridge("html",'monokai')
(Pdb) c

Now the built dark highlighter isn't native when I load it in the browser.

@pradyunsg pradyunsg reopened this Dec 30, 2020
@pradyunsg
Copy link
Owner

app.config.pygments_dark_style
'native'

Well well well. What happens on newer versions of Sphinx? This might be an environment management bug in the older Sphinx version, maybe?

@gilch
Copy link
Author

gilch commented Dec 30, 2020

Updated to sphinx==3.4.1 in my project and it didn't help. I'll try it in a fresh environment.

@gilch
Copy link
Author

gilch commented Dec 31, 2020

Fresh environment is the same. Debugger inspection is the same. app.config.pygments_dark_style is 'native'.

@pradyunsg
Copy link
Owner

This should be resolved with beta25. Could you try again?

@gilch
Copy link
Author

gilch commented Feb 21, 2021

Fresh environment with new versions

sphinx==3.5.1
furo==2021.2.21.b25

is the same.

(Pdb) app.config.pygments_dark_style
'native'
(Pdb) __version__
'2021.02.21.beta25'

And again, I can manually set builder.dark_highlighter = PygmentsBridge("html",'monokai') in the debugger to get the right colors, but it seems to be ignoring the pygments_dark_style in conf.py.

@pradyunsg
Copy link
Owner

What is Sphinx doing...

@pradyunsg pradyunsg changed the title Instructions to change the dark mode code block styling don't work. Instructions to change the dark mode code block styling don't work Feb 27, 2021
@pradyunsg
Copy link
Owner

Okay, with 784a670, this is definitely done now. You should be able to try this by using pip install furo==2021.3.20b31 (which I also yanked, coz... reasons that aren't related to this).

@gilch
Copy link
Author

gilch commented Apr 18, 2022

Maybe a separate issue, but I've noticed that formatting for a light pygments theme (tango) bled through to the formatting for a dark theme (monokai). It works fine if I use the same theme for both. Anything the dark theme left unspecified was set by the light theme. E.g. for number literals, the color worked as expected, but became bold text in the dark theme only when I had tango as the light theme.

@pradyunsg
Copy link
Owner

Hiya! Please file a new discussion for this. Making comments on closed issues makes things harder for me to keep up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants