docs: enable syntax highlighting for cue

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-06-03 18:01:17 -07:00
parent 4bce5de08b
commit c76f65aa14
3 changed files with 57 additions and 1 deletions

View File

@ -19,7 +19,7 @@ module.exports = {
themeConfig: { themeConfig: {
sidebarCollapsible: false, sidebarCollapsible: false,
prism: { prism: {
defaultLanguage: "go", theme: require("prism-react-renderer/themes/vsDark"),
}, },
navbar: { navbar: {
logo: { logo: {

View File

@ -0,0 +1,24 @@
/**
* 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: { additionalLanguages = [] } = {} },
} = siteConfig;
window.Prism = PrismObject;
additionalLanguages.forEach((lang) => {
require(`prismjs/components/prism-${lang}`); // eslint-disable-line
});
require("./prism.cue.js");
delete window.Prism;
}
};
export default prismIncludeLanguages;

View File

@ -0,0 +1,32 @@
Prism.languages.cue = Prism.languages.extend("clike", {
// https://github.com/PrismJS/prism/blob/master/components/prism-swift.js
string: {
pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
greedy: true,
inside: {
interpolation: {
pattern: /\\\#*\((?:[^()]|\([^)]+\))+\)/,
inside: {
delimiter: {
pattern: /^\\\#*\(|\)$/,
alias: "variable",
},
},
},
},
},
// https://cuelang.org/docs/references/spec/#values
keyword: /\b(?:package|import|if|else|for|in|let)\b/,
boolean: /\b(?:true|false)\b/,
constant: /\b(?:_\|_|_)\b/,
// https://github.com/PrismJS/prism/blob/master/components/prism-go.js
number: /(?:\b0x[a-f\d]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
operator:
/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
// https://cuelang.org/docs/references/spec/#predeclared-identifiers
builtin:
/\b(?:len|null|bool|int|float|string|bytes|number|u?int(?:8|16|32|64|128)?|rune|float(?:32|64))\b/,
});