-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add a JSONC language variant for "JSON with Comments" #2016
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
Comments
Would this have to be a variant. What if we just added comments to the JSON parser so it simply allowed comments if they were present? |
Good catch. I just responded to that comment, we'll see where it goes. :-) |
@yyyc514 Why don't you want to use |
I have no idea what this question even means. Did GitHub already write a Highlight.js syntax we can just "use", otherwise I'm not sure what you're asking by "use". We're talking about the simplest/easiest to maintain/most pragmatic way to add comment highlighting to Highlight.js. Personally I think the answer is like "add it to the json syntax and make jsonc an alias". Aliases is a built in concept of Highlight.js for situations like this. |
Here is my attempt: https://github.com/highlightjs/highlight.js/pull/2155/files Welcome for thoughts/critiques. |
I was asking why you didn't want to use a distinct name like Inexperienced developers may be led to believe that JSON supports comments, which it obviously doesn't. Neither GitHub nor GitLab highlight comments when using the |
Oh I don't really have an opinion on that. I'm not sure "jsonc" is an official thing though. You'll see I asked in the other thread if we should make an alias for "jsonc" or not.
That would be equally possible if we had two different ones and "auto-detected" the one they were using... same issue, so I don't think this is a huge problem. |
It's not really an "official format" or anything, just a way of separating the two variations. FWIW, VS Code also uses it. |
Well, highlighter doesn't have to be as rigorous as compilers are. For now, fixed via #2155. |
@glen-84 Would you be happier if we added a "jsonc" alias? |
@yyyc514 It would be nice to have that as an option. 🙂 |
Similar to #406, which correctly points out that comments are not permitted in the JSON spec, can a new, very similar language be added that does permit comments and trailing commas?
This is often used in configuration files for (among other things) VS Code and Sublime Text. Github comparison of codefences for
json
versusjsonc
:Right now, I use
javascript
for these like #406 suggests, but it is much easier to discriminate keys and values with the JSON highlighting.The text was updated successfully, but these errors were encountered: