Add syntax highlighting for Gleam, preliminary version

This commit is contained in:
Mikko Ahlroth 2023-01-02 21:29:55 +02:00
parent 7733947270
commit 14501a6d09
4 changed files with 39 additions and 3 deletions

View file

@ -36,7 +36,7 @@
<div id="length">Waiting...</div>
<div id="info">
v2.1.0 | © Nicd 2022 | <a href="https://gitlab.com/Nicd/t" target="_blank">Source</a> | <a href="./licenses.txt"
v2.2.0 | © Nicd 2022 | <a href="https://gitlab.com/Nicd/t" target="_blank">Source</a> | <a href="./licenses.txt"
target="_blank">Licenses</a>
</div>
</footer>

View file

@ -300,6 +300,7 @@ export const LANGUAGE_NAMES = [
"yaml",
"yang",
"zig",
"gleam",
];
export const LANGUAGES = new Map();

View file

@ -72,7 +72,9 @@ function getLanguageClassName(language) {
* Render all the language choices in the dropdown.
*/
function renderLanguageOptions() {
for (const language of LANGUAGE_NAMES) {
const languages = [...LANGUAGE_NAMES];
languages.sort();
for (const language of languages) {
const option = document.createElement("option");
option.value = language;
option.textContent = language;
@ -98,7 +100,11 @@ async function highlightLanguage() {
dataOptions.language
);
for (const dep of [...deps, dataOptions.language]) {
await import(`./vendor/prism/components/prism-${dep}.js`);
try {
await import(`./vendor/prism/components/prism-${dep}.js`);
} catch {
await import(`./vendor/prism-patches/prism-${dep}.js`);
}
}
if (viewMode === ViewMode.VIEW) {

29
vendor/prism-patches/prism-gleam.js vendored Normal file
View file

@ -0,0 +1,29 @@
Prism.languages.gleam = {
doc: {
pattern: /\/\/\/\/?.*/,
greedy: true,
},
comment: {
pattern: /\/\/.*/,
greedy: true,
},
function: /(?<=fn )([a-z_][a-zA-Z0-9_]+)(?=\()/,
keyword:
/\b(use|case|if|external|fn|import|let|assert|try|pub|type|opaque|const|todo|as)\b/,
operator: {
pattern:
/(<<|>>|<-|->|\|>|<>|\.\.|<=\.?|>=\.?|==\.?|!=\.?|<\.?|>\.?|&&|\|\||\+\.?|-\.?|\/\.?|\*\.?|%\.?|=)/,
greedy: true,
},
string: {
pattern: /"(?:\\(?:\r\n|[\s\S])|(?!")[^\\\r\n])*"/,
greedy: true,
inside: {
punctuation: /\\./,
},
},
punctuation: /[.\\:,{}()]/,
number:
/\b(?:0b[0-1]+|0o[0-7]+|[[:digit:]][[:digit:]_]*(\\.[[:digit:]]*)?|0x[[:xdigit:]]+)\b/,
boolean: /\b(?:True|False)\b/,
};