Groovy code highlighting does not take effect
Problem
When I used the markdown syntax of “```groovy ... ```“ to put in Groovy code, I found that the code was not highlighted during preview. Other programming languages don't seem to have this problem. May I ask why?
Steps
No response
Possible Solution(s)
It may be related to highlight.js, but when I tried using the official file of this js separately, I found that there was no problem with highlighting in Groovy.
Notes
No response
Version
mdbook v0.4.43
There's only a certain subset of languages it supports out of the box, https://rust-lang.github.io/mdBook/format/theme/syntax-highlighting.html#supported-languages.
You'd have to add your own highlight.js file for groovy to work.
Following up on @slightlybelowzen , the built-in highlighting is implemented in src/theme/highlight.js which is an old copy from https://highlightjs.org
As I understand you could download a new version of highlight.js that includes Groovy from there and use that or you could go to the longer route and send a PR to upgrade the highlight.js in mdbook including all the currently supported languages. Thought first you might want to verify that the core developers are even interested in such an upgrade.
Going over all the issues mentioning highlight, it seems people are suggesting switching from highlight.js to other tools.
A solution:
- Go to https://highlightjs.org/
- Check the languages for which you'd like to have support in your book.
- Click on download
- Wait for some 10 seconds till the download starts and save the
highlight.zipfile - unizp it in some empty folder
- move the
highlight.min.jsfile tosrc/highlight.jsin your book - make sure you mark your code snippets with groovy (as you do above)
I applied this to my Groovy Maven that was just extracted from my old site that used a home-grown system.