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

Add missing class="hljs" to pre tag #2

Merged
merged 1 commit into from
May 31, 2022

Conversation

stami
Copy link

@stami stami commented Apr 3, 2022

Highlight.js styles have a root .hljs class that contains root text color and background color.

This PR adds that class to the outputted HTML and fixes background styles not applying.

Easiest to see when using a dark theme: before the background was white (or other inherited site background) but after this addition the code block uses the background color of the given style.

Before:
before

After:
after

I'm using Atom One Dark styles there.

@alex-ross
Copy link
Owner

@stami and @stami-fb do you know why this is needed? According to Highlight JS usage page this should not be required.

@stami
Copy link
Author

stami commented May 31, 2022

Well, I couldn't figure out how to get the theme's background color to apply without adding the class. 😁

I guess in the usage page the hljs.highlightAll(); call dynamically searches for any <pre><code> tags from the page and adds the class there, but in this static site plugin it is not done.

I'm confused, does this plugin work for you without the hljs class? Try with a theme that has different background color than your website otherwise has to see it. In my example (the screenshots) I'm using Atom One Dark theme and it has the dark background set in that .hljs block. Without my addition, that class is found nowhere in the generated static html and so the background is left white (the upper screenshot). 🤔

@alex-ross
Copy link
Owner

@stami hmm... You are correct. In my own site the site has the same background as i expect in the colorscheme.

In worst case, what could go wrong adding it twice 😉.

I will merge this and release a 1.0.2 version very soon with this improvement. Thanks for your contribution.

@alex-ross alex-ross merged commit cc55513 into alex-ross:master May 31, 2022
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

Successfully merging this pull request may close these issues.

3 participants