Skip to content

Commit b1a19b2

Browse files
committed
Add Ren'Py code block highlighting
1 parent 96dfe0b commit b1a19b2

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

app/src/protyle/render/highlightRender.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN, z
3232
setCodeTheme(cdn);
3333

3434
addScript(`${cdn}/js/highlight.js/highlight.min.js?v=11.11.1`, "protyleHljsScript").then(() => {
35-
addScript(`${cdn}/js/highlight.js/third-languages.js?v=2.0.1`, "protyleHljsThirdScript").then(() => {
35+
addScript(`${cdn}/js/highlight.js/third-languages.js?v=2.0.2`, "protyleHljsThirdScript").then(() => {
3636
codeElements.forEach((block: HTMLElement) => {
3737
if (block.getAttribute("data-render") === "true") {
3838
return;

app/stage/protyle/js/highlight.js/third-languages.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
// Ren'Py script language support.
2+
hljs.registerLanguage("renpy", (hljs) => {
3+
const IDENT = /[A-Za-z_][A-Za-z0-9_]*/;
4+
const RENPY_KEYWORDS = [
5+
"add", "at", "behind", "call", "camera", "centered", "contains",
6+
"default", "define", "drag", "draggroup", "elif", "else", "event",
7+
"expression", "hide", "hotspot", "if", "image", "init", "jump",
8+
"key", "label", "menu", "nvl", "on", "pass", "python", "queue",
9+
"repeat", "return", "scene", "screen", "show", "side", "sound",
10+
"stop", "style", "text", "time", "timer", "transform", "use",
11+
"voice", "while", "with", "window", "zorder"
12+
].join(" ");
13+
const PYTHON_KEYWORDS = [
14+
"and", "as", "assert", "async", "await", "break", "class",
15+
"continue", "def", "del", "except", "False", "finally", "for",
16+
"from", "global", "import", "in", "is", "lambda", "None",
17+
"nonlocal", "not", "or", "raise", "True", "try", "yield"
18+
].join(" ");
19+
20+
return {
21+
name: "Ren'Py",
22+
aliases: ["rpy"],
23+
keywords: {
24+
keyword: `${RENPY_KEYWORDS} ${PYTHON_KEYWORDS}`,
25+
literal: "True False None yes no",
26+
built_in: "Character DynamicCharacter Solid Null Fade Dissolve MoveTransition Pause SetVariable ToggleVariable Show Hide Jump Call Return Function Play Queue Stop"
27+
},
28+
contains: [
29+
hljs.HASH_COMMENT_MODE,
30+
hljs.QUOTE_STRING_MODE,
31+
hljs.APOS_STRING_MODE,
32+
hljs.NUMBER_MODE,
33+
{
34+
className: "meta",
35+
begin: /^\s*\$+/,
36+
end: /$/,
37+
contains: [
38+
hljs.HASH_COMMENT_MODE,
39+
hljs.QUOTE_STRING_MODE,
40+
hljs.APOS_STRING_MODE,
41+
hljs.NUMBER_MODE
42+
]
43+
},
44+
{
45+
className: "section",
46+
begin: /^\s*(label|screen|transform|style|image)\s+/,
47+
end: /:/,
48+
keywords: "label screen transform style image"
49+
},
50+
{
51+
className: "title",
52+
begin: new RegExp(`^\\s*${IDENT.source}(?=\\s+["'])`)
53+
},
54+
{
55+
className: "variable",
56+
begin: /\[[^\]\n]+\]/
57+
}
58+
]
59+
};
60+
});
61+
162
// https://cdn.jsdelivr.net/npm/highlightjs-solidity@2.0.6/dist/yul.min.js
263
hljs.registerLanguage("yul",(()=>{"use strict";function e(){try{return!0
364
}catch(e){return!1}}

0 commit comments

Comments
 (0)