[misc] use highlight.js for syntax highlighting in blog post #18318
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.
To get highlighting to work, we just need to import the CSS and run the highlight.js that does the highlighting in JS client side. We can add the lines at the top of the blog post to do this. I've made it only support bash and python for now to help with detection. But if we have a reason to, we can remove that and let it try them all.
In a previous PR I've added the necessary
<code>
tags.I've picked the theme
a11y-light
. Try the other themes here: https://highlightjs.org/demoatom-one-light
seems nice too.Since we're highlighting nicely now, we can just remove the extra indendation.
I've also noticed that we're pretty good at specifying the language in code blocks in the changelog. So we can take that language and use it in the code block as a class to tell highlight.js exactly what language that code block is in.
If this is useful, we can remove the limitation of only python and bash support from the top configuration in the future.
This is useful for smaller blocks of a few lines where maybe it doesn't detect the language properly.
Using the modified script, here's a part of the html from the 1.14 blog:
It looks like this in the html generated:
And in the blog post itself, with the blog CSS like heading colors or limited width: