diff options
Diffstat (limited to 'static/highlight/highlight-gleam.js')
-rw-r--r-- | static/highlight/highlight-gleam.js | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/static/highlight/highlight-gleam.js b/static/highlight/highlight-gleam.js new file mode 100644 index 0000000..807d9ec --- /dev/null +++ b/static/highlight/highlight-gleam.js @@ -0,0 +1,119 @@ +/** + * Registers gleam as a language + * + * Largely based off https://github.com/gleam-lang/website/blob/main/javascript/highlightjs-gleam.js + * Edited to work with minified hightlightjs core v11 (module) + */ + +import hljs from "./highlight.core.min.js"; + +hljs.registerLanguage("gleam", function (hljs) { + const KEYWORDS = { + className: "keyword", + beginKeywords: + "as assert auto case const delegate derive echo else fn if " + + "implement import let macro opaque panic pub test todo type use", + }; + const STRING = { + className: "string", + variants: [{ begin: /"/, end: /"/ }], + contains: [hljs.BACKSLASH_ESCAPE], + relevance: 0, + }; + const NAME = { + className: "variable", + begin: "\\b[a-z][a-z0-9_]*\\b", + relevance: 0, + }; + const DISCARD_NAME = { + className: "comment", + begin: "\\b_[a-z][a-z0-9_]*\\b", + relevance: 0, + }; + const NUMBER = { + className: "number", + variants: [ + { + // binary + begin: "\\b0[bB](?:_?[01]+)+", + }, + { + // octal + begin: "\\b0[oO](?:_?[0-7]+)+", + }, + { + // hex + begin: "\\b0[xX](?:_?[0-9a-fA-F]+)+", + }, + { + // dec, float + begin: "\\b\\d(?:_?\\d+)*(?:\\.(?:\\d(?:_?\\d+)*)*)?", + }, + ], + relevance: 0, + }; + + return { + name: "Gleam", + aliases: ["gleam"], + contains: [ + hljs.C_LINE_COMMENT_MODE, + STRING, + { + // bit array + begin: "<<", + end: ">>", + contains: [ + { + className: "keyword", + beginKeywords: + "binary bits bytes int float bit_string bit_array bits utf8 utf16 " + + "utf32 utf8_codepoint utf16_codepoint utf32_codepoint signed " + + "unsigned big little native unit size", + }, + KEYWORDS, + STRING, + NAME, + DISCARD_NAME, + NUMBER, + ], + relevance: 10, + }, + { + className: "function", + beginKeywords: "fn", + end: "\\(", + excludeEnd: true, + contains: [ + { + className: "title", + begin: "[a-z][a-z0-9_]*\\w*", + relevance: 0, + }, + ], + }, + { + className: "attribute", + begin: "@", + end: "\\(", + excludeEnd: true, + }, + KEYWORDS, + { + // Type names and constructors + className: "title", + begin: "\\b[A-Z][A-Za-z0-9]*\\b", + relevance: 0, + }, + { + className: "operator", + begin: "[+\\-*/%!=<>&|.]+", + relevance: 0, + }, + NAME, + DISCARD_NAME, + NUMBER, + ], + }; +}); +hljs.highlightAll();
\ No newline at end of file |