mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Groovy code highlighting does not take effect

Open zhang13690 opened this issue 1 year ago • 3 comments

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

zhang13690 avatar Nov 28 '24 10:11 zhang13690

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.

ghost avatar Dec 19 '24 19:12 ghost

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.

szabgab avatar Feb 27 '25 07:02 szabgab

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.zip file
  • unizp it in some empty folder
  • move the highlight.min.js file to src/highlight.js in 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.

szabgab avatar Mar 01 '25 19:03 szabgab