1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/theme/pascal.js
Jonathan Cubides 453996530d
Add syntax highlighting for juvix code blocks in docs (#1971)
This PR adds initial syntax highlighting for juvix code blocks and REPL
sessions in Markdown files rendered by mdbook. After this PR, only two
themes would be supported to ease maintenance: Light and Dark (Ayu).

The implementation is a specifically tailored version of

- https://github.com/anoma/highlightjs-juvix (plugin for
HighlightJS,v11.7).

to be compatible with the infamous HighlightJS 10.1.1, to be used just
for MdBook.

The output can be seen here (make sure the CI finished to check the last
version, otherwise run the website locally):

- https://jonaprieto.github.io/juvix/tutorials/learn.html
2023-04-05 11:24:19 +02:00

84 lines
2.6 KiB
JavaScript

// To be used with highlight.js v10.1.1
function hljsDefinePascal(e) {
var a =
"exports register file shl array record property for mod while set ally label uses raise not stored class safecall var interface or private static exit index inherited to else stdcall override shr asm far resourcestring finalization packed virtual out and protected library do xorwrite goto near function end div overload object unit begin string on inline repeat until destructor write message program with read initialization except default nil if case cdecl in downto threadvar of try pascal const external constructor type public then implementation finally published procedure absolute reintroduce operator as is abstract alias assembler bitpacked break continue cppdecl cvar enumerator experimental platform deprecated unimplemented dynamic export far16 forward generic helper implements interrupt iochecks local name nodefault noreturn nostackframe oldfpccall otherwise saveregisters softfloat specialize strict unaligned varargs ",
r = [
e.C_LINE_COMMENT_MODE,
e.COMMENT(/\{/, /\}/, { relevance: 0 }),
e.COMMENT(/\(\*/, /\*\)/, { relevance: 10 }),
],
n = {
className: "meta",
variants: [
{ begin: /\{\$/, end: /\}/ },
{ begin: /\(\*\$/, end: /\*\)/ },
],
},
t = {
className: "string",
begin: /'/,
end: /'/,
contains: [{ begin: /''/ }],
},
s = { className: "string", begin: /(#\d+)+/ },
i = {
begin: e.IDENT_RE + "\\s*=\\s*class\\s*\\(",
returnBegin: !0,
contains: [e.TITLE_MODE],
},
c = {
className: "function",
beginKeywords: "function constructor destructor procedure",
end: /[:;]/,
keywords: "function constructor|10 destructor|10 procedure|10",
contains: [
e.TITLE_MODE,
{
className: "params",
begin: /\(/,
end: /\)/,
keywords: a,
contains: [t, s, n].concat(r),
},
n,
].concat(r),
};
return {
name: "Delphi",
aliases: [
"dpr",
"dfm",
"pas",
"pascal",
"freepascal",
"lazarus",
"lpr",
"lfm",
],
case_insensitive: !0,
keywords: a,
illegal: /"|\$[G-Zg-z]|\/\*|<\/|\|/,
contains: [
t,
s,
e.NUMBER_MODE,
{
className: "number",
relevance: 0,
variants: [
{ begin: "\\$[0-9A-Fa-f]+" },
{ begin: "&[0-7]+" },
{ begin: "%[01]+" },
],
},
i,
c,
n,
].concat(r),
};
}
module.exports = function (hljs) {
hljs.registerLanguage("pascal", hljsDefinePascal);
};