Skip to content

Commit

Permalink
docs: add missing formatting for cjson and jsonc and correct edit lin…
Browse files Browse the repository at this point in the history
…ks (#4116)
  • Loading branch information
armano2 committed Nov 11, 2021
1 parent ae130f1 commit 75e2ae0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/website/docusaurus.config.js
Expand Up @@ -42,7 +42,7 @@ const config = {
path: '../eslint-plugin/docs/rules',
sidebarPath: require.resolve('./sidebars/sidebar.rules.js'),
routeBasePath: 'rules',
editUrl: `${githubUrl}/edit/master/docs/`,
editUrl: `${githubUrl}/edit/master/packages/website/`,
remarkPlugins,
},
],
Expand All @@ -53,7 +53,7 @@ const config = {
path: '../../docs',
routeBasePath: 'docs',
sidebarPath: require.resolve('./sidebars/sidebar.base.js'),
editUrl: `${githubUrl}/edit/master/docs/`,
editUrl: `${githubUrl}/edit/master/packages/website/`,
remarkPlugins,
},
],
Expand Down
27 changes: 27 additions & 0 deletions packages/website/src/prism/language/jsonc.js
@@ -0,0 +1,27 @@
// https://www.json.org/json-en.html
Prism.languages.cjson = {
property: {
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
lookbehind: true,
greedy: true,
},
string: {
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
lookbehind: true,
greedy: true,
},
comment: {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true,
},
number: /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
punctuation: /[{}[\],]/,
operator: /:/,
boolean: /\b(?:false|true)\b/,
null: {
pattern: /\bnull\b/,
alias: 'keyword',
},
};

Prism.languages.jsonc = Prism.languages.cjson;
27 changes: 27 additions & 0 deletions packages/website/src/theme/prism-include-languages.js
@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
import siteConfig from '@generated/docusaurus.config';

const prismIncludeLanguages = PrismObject => {
if (ExecutionEnvironment.canUseDOM) {
const {
themeConfig: { prism = {} },
} = siteConfig;
const { additionalLanguages = [] } = prism;
window.Prism = PrismObject;

additionalLanguages.forEach(lang => {
require(`prismjs/components/prism-${lang}`); // eslint-disable-line
});

require(`../prism/language/jsonc`);
delete window.Prism;
}
};

export default prismIncludeLanguages;

0 comments on commit 75e2ae0

Please sign in to comment.