Skip to content

Commit

Permalink
Convert jsonc to json in code blocks (#442)
Browse files Browse the repository at this point in the history
Prism doesn't support JSONC, but its syntax highlighting works for comments in JSON.
So, this change converts automatically `jsonc` to `json` in Markdown code blocks.

See also https://prismjs.com/#supported-languages
  • Loading branch information
ybiquitous authored Sep 3, 2024
1 parent 246bd8c commit 3919833
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/generate-docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,26 @@ function makeRuleSymbolsAccessbile() {
return transform;
}

// NOTE: Prism doesn't support JSONC.
function jsoncToJson() {
function visitor(node) {
node.lang = 'json';
}

function transform(tree) {
visit(tree, { type: 'code', lang: 'jsonc' }, visitor);
}

return transform;
}

function processMarkdown(file, { rewriter }) {
const content = remark()
.use(remarkGFM)
.use(rewriteLink, { rewriter })
.use(wrapProblemExample)
.use(makeRuleSymbolsAccessbile)
.use(jsoncToJson)
.processSync(fs.readFileSync(file, 'utf8'))
.toString();

Expand Down

0 comments on commit 3919833

Please sign in to comment.