G-code syntax highlighting: register gcode grammar in code_note_highlight; add hljs-name/attr colors to theme
This commit is contained in:
@@ -3,8 +3,39 @@
|
|||||||
var codes = document.querySelectorAll("#content pre code:not(.language-mermaid)");
|
var codes = document.querySelectorAll("#content pre code:not(.language-mermaid)");
|
||||||
if (!codes.length) return;
|
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() {
|
function apply() {
|
||||||
if (!window.hljs) return;
|
if (!window.hljs) return;
|
||||||
|
registerGcode();
|
||||||
codes.forEach(function (c) {
|
codes.forEach(function (c) {
|
||||||
c.classList.add("hljs");
|
c.classList.add("hljs");
|
||||||
hljs.highlightElement(c);
|
hljs.highlightElement(c);
|
||||||
|
|||||||
@@ -1787,4 +1787,9 @@ html.theme-light .mermaid svg .cluster .nodeLabel,
|
|||||||
html.theme-light .mermaid svg .cluster-label text {
|
html.theme-light .mermaid svg .cluster-label text {
|
||||||
fill: #556753 !important;
|
fill: #556753 !important;
|
||||||
color: #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; }
|
||||||
Reference in New Issue
Block a user