The release of Code.Movie 0.0.30 adds support for C-style comments in JSON, with no breaking changes. Code.Movie is a JavaScript library that animates source code for the web - imagine a combination of git diffs, syntax highlighting, code annotations and CSS transitions.
[]
["World"]
["Hello", "World"]
[ "Hello", "World" ]
[ "World", "Hello" ]
The new boolean option comments
for the JSON language module enables support for C-style comments:
// JSON with line comments! { "editor.cursorStyle": "line" }
// JSON with line comments! { "editor.cursorStyle": "line" /* and block comments! */ }
// JSON with line comments! { "editor.cursorStyle": "line" /* check out my VS code config */ }
// check out my VS code config { "editor.cursorStyle": "line", "editor.fontFamily": "Fira Code" /* best coding font... */ }
// check out my VS code config { "editor.cursorStyle": "line", "editor.fontFamily": "Fira Code", "editor.fontLigatures": false /* ... IF this is false! */ }
// check out my VS code config { "editor.cursorStyle": "line", "editor.fontFamily": "Fira Code", "editor.fontLigatures": false /* come and fight me on social media! :) */ }
This is sometimes called "JSONC" and is, as far as I can tell, not really a proper standard. Is is however widely used (among other things in TypeScript's tsconfig.json
), so I just made up a grammar and made it available as a dialect of JSON. To use it, load and instantiate the JSON module as per usual, but pass the option comments: true
:
import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
// unlocks line and block comments
let jsonWithComments = json({ comments: true });
let html = animateHTML([{ code: "[42 /* Hello */ ] // World" }], {
tabSize: 2,
language: jsonWithComments,
});
➡️➡️import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
// unlocks line and block comments
let jsonWithComments = json({ comments: true });
let html = animateHTML([{ code: "[42 /* Hello */ ] // World" }], {
tabSize: 2,
language: jsonWithComments,
});
The comments
option is optional and JSON module continues to default so proper RFC8259-compliant JSON without support for comments. Support for JSON with comments has also been added to the playground.