G-code syntax highlighting: register gcode grammar in code_note_highlight; add hljs-name/attr colors to theme

This commit is contained in:
trilium-share-gruvbox
2026-09-07 16:58:48 +02:00
parent 3f9a502496
commit 6a818442be
2 changed files with 37 additions and 1 deletions
+31
View File
@@ -3,8 +3,39 @@
var codes = document.querySelectorAll("#content pre code:not(.language-mermaid)");
if (!codes.length) return;
function registerGcode() {
if (window.hljs.getLanguage("gcode")) return;
window.hljs.registerLanguage("gcode", function (hljs) {
return {
name: "G-code (ISO 6983)",
aliases: ["nc"],
case_insensitive: true,
keywords: {
$pattern: "[A-Z_][A-Z0-9_.]*",
keyword: "IF DO WHILE ENDWHILE CALL ENDIF SUB ENDSUB GOTO REPEAT ENDREPEAT EQ LT GT NE GE LE OR XOR"
},
contains: [
{ className: "meta", begin: /[O][0-9]+/ },
{ className: "meta", begin: /[%]/ },
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.COMMENT(/\(/, /\)/),
{ className: "number", begin: /[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)/ },
{ className: "string", begin: /["]/, end: /["]/, illegal: null },
{ className: "name", begin: /[G][0-9]+([.][0-9]+)?/ },
{ className: "name", begin: /[M][0-9]+([.][0-9]+)?/ },
{ className: "attr", begin: /(VC|VS)[0-9]+/ },
{ className: "attr", begin: /[#][0-9]+/ },
{ className: "built_in", begin: /(ATAN|ABS|ACOS|ASIN|SIN|COS|EXP|FIX|FUP|ROUND|LN|TAN)(\[)/, end: /[\]]/, contains: [{ className: "number", begin: /[+-]?[0-9.]+/ }] },
{ className: "symbol", begin: /[N][0-9]+/ }
]
};
});
}
function apply() {
if (!window.hljs) return;
registerGcode();
codes.forEach(function (c) {
c.classList.add("hljs");
hljs.highlightElement(c);
+6 -1
View File
@@ -1787,4 +1787,9 @@ html.theme-light .mermaid svg .cluster .nodeLabel,
html.theme-light .mermaid svg .cluster-label text {
fill: #556753 !important;
color: #556753 !important;
}
}
/* ---------- G-code / Zusatz-Scopes (name = G/M-Codes, attr = Parameter) ---------- */
.hljs-name { color: #E1CE98; }
.hljs-attr { color: #77838a; }
html.theme-light .hljs-name { color: #4c6c94; }
html.theme-light .hljs-attr { color: #556753; }