mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-18 08:13:40 +08:00
chore(code): reintegrate batch syntax
This commit is contained in:
parent
01f02b736c
commit
efc08a61ef
@ -1,51 +1,48 @@
|
|||||||
// Source: https://github.com/deathau/cm-editor-syntax-highlight-obsidian/issues/27#issuecomment-1340586596
|
/**
|
||||||
(() => {
|
* @module
|
||||||
var varsAndArgsRegex = /(%[0-9]|%~\S+|%\S+%)/;
|
*
|
||||||
|
* Ported to CodeMirror 6 from https://github.com/deathau/cm-editor-syntax-highlight-obsidian/issues/27#issuecomment-1340586596
|
||||||
|
*/
|
||||||
|
|
||||||
CodeMirror.defineSimpleMode("batch", {
|
import { simpleMode } from "@codemirror/legacy-modes/mode/simple-mode";
|
||||||
start: [
|
|
||||||
{ //comment
|
const varsAndArgsRegex = /(%[0-9]|%~\S+|%\S+%)/;
|
||||||
|
|
||||||
|
export const batch = simpleMode({
|
||||||
|
start: [
|
||||||
|
{ //comment
|
||||||
regex: /(rem|::)(?:\s.*|$)/i,
|
regex: /(rem|::)(?:\s.*|$)/i,
|
||||||
token: "comment",
|
token: "comment",
|
||||||
sol: true
|
sol: true
|
||||||
},
|
},
|
||||||
{ //echo
|
{ //echo
|
||||||
regex: /(@echo|echo)/i,
|
regex: /(@echo|echo)/i,
|
||||||
token: "builtin",
|
token: "builtin",
|
||||||
sol: true,
|
sol: true,
|
||||||
next: "echo"
|
next: "echo"
|
||||||
},
|
},
|
||||||
{ //commands
|
{ //commands
|
||||||
regex: /(?:\s|^)(assoc|aux|break|call|cd|chcp|chdir|choice|cls|cmdextversion|color|com1|com2|com3|com4|com|con|copy|country|ctty|date|defined|del|dir|do|dpath|else|endlocal|erase|errorlevel|exist|exit|for|ftype|goto|if|in|loadfix|loadhigh|lpt|lpt1|lpt2|lpt3|lpt4|md|mkdir|move|not|nul|path|pause|popd|prn|prompt|pushd|rd|rename|ren|rmdir|setlocal|set|shift|start|time|title|type|verify|ver|vol)(?:\s|$)/i,
|
regex: /(?:\s|^)(assoc|aux|break|call|cd|chcp|chdir|choice|cls|cmdextversion|color|com1|com2|com3|com4|com|con|copy|country|ctty|date|defined|del|dir|do|dpath|else|endlocal|erase|errorlevel|exist|exit|for|ftype|goto|if|in|loadfix|loadhigh|lpt|lpt1|lpt2|lpt3|lpt4|md|mkdir|move|not|nul|path|pause|popd|prn|prompt|pushd|rd|rename|ren|rmdir|setlocal|set|shift|start|time|title|type|verify|ver|vol)(?:\s|$)/i,
|
||||||
token: "builtin"
|
token: "builtin"
|
||||||
},
|
},
|
||||||
{ //variables and arguments
|
{ //variables and arguments
|
||||||
regex: varsAndArgsRegex,
|
regex: varsAndArgsRegex,
|
||||||
token: "variable-2"
|
token: "variable-2"
|
||||||
},
|
},
|
||||||
{ //label
|
{ //label
|
||||||
regex: /\s*:.*/,
|
regex: /\s*:.*/,
|
||||||
token: "string",
|
token: "string",
|
||||||
sol: true
|
sol: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
echo: [
|
echo: [
|
||||||
{ //highlight variables and arguments in echo command
|
{ //highlight variables and arguments in echo command
|
||||||
regex: varsAndArgsRegex,
|
regex: varsAndArgsRegex,
|
||||||
token: "variable-2"
|
token: "variable-2"
|
||||||
},
|
},
|
||||||
{ //go back to start state at end of line
|
{ //go back to start state at end of line
|
||||||
regex: /.$/,
|
regex: /.$/,
|
||||||
next: "start"
|
next: "start"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
CodeMirror.defineMIME("application/x-bat", "batch");
|
|
||||||
CodeMirror.modeInfo.push({
|
|
||||||
ext: [ "bat", "cmd" ],
|
|
||||||
mime: "application/x-bat",
|
|
||||||
mode: "batch",
|
|
||||||
name: "Batch file"
|
|
||||||
});
|
|
||||||
})();
|
|
@ -6,7 +6,7 @@ const byMimeType: Record<string, (() => Promise<StreamParser<unknown>>) | null>
|
|||||||
"text/x-ttcn-asn": async () => (await import('@codemirror/legacy-modes/mode/ttcn')).ttcn,
|
"text/x-ttcn-asn": async () => (await import('@codemirror/legacy-modes/mode/ttcn')).ttcn,
|
||||||
"application/x-aspx": null,
|
"application/x-aspx": null,
|
||||||
"text/x-asterisk": async () => (await import('@codemirror/legacy-modes/mode/asterisk')).asterisk,
|
"text/x-asterisk": async () => (await import('@codemirror/legacy-modes/mode/asterisk')).asterisk,
|
||||||
"application/x-bat": null,
|
"application/x-bat": async () => (await import("./languages/batch.js")).batch,
|
||||||
"text/x-brainfuck": async () => (await import('@codemirror/legacy-modes/mode/brainfuck')).brainfuck,
|
"text/x-brainfuck": async () => (await import('@codemirror/legacy-modes/mode/brainfuck')).brainfuck,
|
||||||
"text/x-csrc": async () => (await import('@codemirror/legacy-modes/mode/clike')).c,
|
"text/x-csrc": async () => (await import('@codemirror/legacy-modes/mode/clike')).c,
|
||||||
"text/x-csharp": async () => (await import('@codemirror/legacy-modes/mode/clike')).csharp,
|
"text/x-csharp": async () => (await import('@codemirror/legacy-modes/mode/clike')).csharp,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user