Syntax Highlighting for "JSON with Comments" a.k.a. jsonc
Problem
In JSON there are no comments allowed. This is also honored by Github syntax highlighting in fenced code blocks:
{
// Note: there might be additional sizes available
"sizes": [ "S", "M", "L", "XL", "XXL" ]
}
There is also "JSON with Comments" or jsonc (see Github language list)
which allows C-style comments
{
// Note: there might be additional sizes available
"sizes": [ "S", "M", "L", "XL", "XXL" ]
}
This is prominently used in tsconfig.json, jsconfig.json and
vscode configuration files.
It would be nice to have syntax highlighting support for such code blocks.
A code fence with jsonc should be highlighted:
```jsonc
{
// Note: there might be additional sizes available
"sizes": [ "S", "M", "L", "XL", "XXL" ]
}
```
Proposed Solution
- Support for "JSON with Comments" in highlight.js: highlightjs/highlight.js/issues/2016
- this adds rendering of C-style comments to normal JSON
-
jsoncalias also available: highlightjs/highlight.js/issues/4018- seemingly not yet contained in a stable release
Notes
If #2313 is considered, Prism seems to also render comments in "normal" JSON, but there is no jsonc alias.
As a workaround, I'd recommend using the javascript language tag.
You can also replace mdbook's highlighting engine by overriding it's files in the theme folder. I have a working example with shiki at https://github.com/cestef/rwalk/tree/93b2034657d4e69aa4803941bfeb92f99eab5977/docs/theme.
This could pretty much work with any package you like, not sure how prism works though.