From 6a818442be59a557a12064fce03a429a31b17dc0 Mon Sep 17 00:00:00 2001 From: trilium-share-gruvbox Date: Mon, 7 Sep 2026 16:58:48 +0200 Subject: [PATCH] G-code syntax highlighting: register gcode grammar in code_note_highlight; add hljs-name/attr colors to theme --- scripts/code_note_highlight.js | 31 +++++++++++++++++++++++++++++++ theme/blog_share_theme.css | 7 ++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/scripts/code_note_highlight.js b/scripts/code_note_highlight.js index 49749fb..ddc5a36 100644 --- a/scripts/code_note_highlight.js +++ b/scripts/code_note_highlight.js @@ -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); diff --git a/theme/blog_share_theme.css b/theme/blog_share_theme.css index 64ffefe..e7de39a 100644 --- a/theme/blog_share_theme.css +++ b/theme/blog_share_theme.css @@ -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; -} \ No newline at end of file +} +/* ---------- 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; } \ No newline at end of file