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

Syntax Highlighting for "JSON with Comments" a.k.a. jsonc #2360

Open
harmathy opened this issue Apr 10, 2024 · 2 comments
Open

Syntax Highlighting for "JSON with Comments" a.k.a. jsonc #2360

harmathy opened this issue Apr 10, 2024 · 2 comments
Labels
A-Highlighting Area: Code colored syntax highlighting C-enhancement Category: Enhancement or feature request

Comments

@harmathy
Copy link

harmathy commented Apr 10, 2024

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

Notes

If #2313 is considered, Prism seems to also render comments in "normal" JSON, but there is no jsonc alias.

@harmathy harmathy added the C-enhancement Category: Enhancement or feature request label Apr 10, 2024
@ehuss ehuss added the A-Highlighting Area: Code colored syntax highlighting label Apr 12, 2024
@ehuss
Copy link
Contributor

ehuss commented Apr 12, 2024

As a workaround, I'd recommend using the javascript language tag.

@cestef
Copy link

cestef commented Jun 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Highlighting Area: Code colored syntax highlighting C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

3 participants