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

Add a JSONC language variant for "JSON with Comments" #2016

Closed
michaelblyons opened this issue Apr 12, 2019 · 12 comments
Closed

Add a JSONC language variant for "JSON with Comments" #2016

michaelblyons opened this issue Apr 12, 2019 · 12 comments

Comments

@michaelblyons
Copy link

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 versus jsonc:

[
    // The foo
    { "foo": [ "baz", 4, true ] },
    // The bar
    { "bar": [ "biff", 10, false ] },
]
[
    // The foo
    { "foo": [ "baz", 4, true ] },
    // The bar
    { "bar": [ "biff", 10, false ] },
]

Right now, I use javascript for these like #406 suggests, but it is much easier to discriminate keys and values with the JSON highlighting.

@joshgoebel
Copy link
Member

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?

@michaelblyons
Copy link
Author

@yyyc514 Personally, I wouldn't mind if they were permitted in the JSON parser, but a repo member already weighed in on that in #406. I hoped that a variant would be a reasonable compromise.

@joshgoebel
Copy link
Member

Good catch. I just responded to that comment, we'll see where it goes. :-)

@glen-84
Copy link

glen-84 commented Oct 5, 2019

@yyyc514 Why don't you want to use jsonc, like GitHub does?

@joshgoebel
Copy link
Member

Why don't you want to use jsonc, like GitHub does?

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.

@joshgoebel
Copy link
Member

Here is my attempt:

https://github.com/highlightjs/highlight.js/pull/2155/files

Welcome for thoughts/critiques.

@glen-84
Copy link

glen-84 commented Oct 6, 2019

I have no idea what this question even means

I was asking why you didn't want to use a distinct name like jsonc (used on GitHub), to differentiate between JSON and JSON with comments.

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 json language (which is the correct behaviour, in my opinion).

@joshgoebel
Copy link
Member

I was asking why you didn't want to use a distinct name like jsonc (used on GitHub), to differentiate between JSON and JSON with comments.

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.

Inexperienced developers may be led to believe that JSON supports comments, which it obviously doesn't.

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.

@glen-84
Copy link

glen-84 commented Oct 6, 2019

I'm not sure "jsonc" is an official thing though

It's not really an "official format" or anything, just a way of separating the two variations. FWIW, VS Code also uses it.

@egor-rogov
Copy link
Collaborator

I was asking why you didn't want to use a distinct name like jsonc (used on GitHub), to differentiate between JSON and JSON with comments.

Inexperienced developers may be led to believe that JSON supports comments, which it obviously doesn't.

Well, highlighter doesn't have to be as rigorous as compilers are. For now, fixed via #2155.
We can add an alias jsonc though, if it helps.

@joshgoebel
Copy link
Member

@glen-84 Would you be happier if we added a "jsonc" alias?

@glen-84
Copy link

glen-84 commented Oct 6, 2019

@yyyc514 It would be nice to have that as an option. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants