WIP: Add auto light/dark syntax highlight theme switch with chroma #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I use syntax highlighting in my personal website and I wanted to discuss about having light/dark syntax highlight switching. Is this something other people also want or care about?
From what I looked, hugo-PaperMod does not currently offer that and the css variable
--hljs-bg: #2e2e33;
that defines the background is hard-coded the same for light and dark. I am not sure why the background is set in the hugo paperMod sheet anyway... maybe a highlightjs limitation? I didn't look into it.I was already using chroma, which is the built-in syntax highlighter from hugo and I find it fantastic as I don't need to care about which languages are supported in the highlightjs bundle or its size. Chroma runs when hugo builds the site and it works by either
I was using the first approach, but I couldn't figure out a way of making it work if I wanted to switch light and dark. Maybe I could add some JS that would later toggle the things? It seemed to be a pain.
I tried approach 2 then, which is this PR. It has the following:
hugo gen chromastyles --style=emacs
hugo gen chromastyles --style=dracula
and then search/replace.chroma
to.dark .chroma
I tested this against my website locally, making sure
config
hadnoClasses = false
set so that hugo chroma uses the classes approach.The result can be seen in the quick video below where I toggle the style.
Screen.Recording.2020-12-19.at.04.40.26.mov
Questions
hugo gen chromastyles
withsed
for necessary changes and then saving the css, or some hugo templating thing)