aboutsummaryrefslogtreecommitdiff
path: root/src/edit.js
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2020-04-09 19:48:28 +0200
committern-peugnet <n.peugnet@free.fr>2020-04-09 20:01:26 +0200
commit5420260c5e6757e2de76bce2265b01a58ae27067 (patch)
treeb7bbaf89e87ee26360eaf86187849c1159db906e /src/edit.js
parent9f3d969508114c692949b55de39277fd6584c7d3 (diff)
downloadwcms-5420260c5e6757e2de76bce2265b01a58ae27067.tar.gz
wcms-5420260c5e6757e2de76bce2265b01a58ae27067.zip
feat: add keywords coloration for each macro
Diffstat (limited to 'src/edit.js')
-rw-r--r--src/edit.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/edit.js b/src/edit.js
index ed89de1..7496adf 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -13,12 +13,38 @@ import 'codemirror/addon/mode/overlay';
import 'codemirror/addon/mode/simple';
CodeMirror.defineSimpleMode('wcms', {
+ // detect a Wcms markup then pass to 'wcms' mode
start: [
{
- regex: /%(?:HEADER|NAV|ASIDE|MAIN|FOOTER|SUMMARY|LIST|MEDIA)(?:\?(?:[^ &]+=[^ &]+&?)+)?%/,
+ regex: /%(?=(HEADER|NAV|ASIDE|MAIN|FOOTER|SUMMARY|LIST|MEDIA)(\?[^\s]*)?%)/,
token: 'wcms',
+ next: 'wcms',
},
],
+ // 'wcms' mode, for each macro, if there is parameters, pass to its associated mode
+ wcms: [
+ {
+ regex: /(HEADER|NAV|ASIDE|MAIN|FOOTER)\?/,
+ token: 'wcms',
+ next: 'element',
+ },
+ { regex: /SUMMARY\?/, token: 'wcms', next: 'summary' },
+ { regex: /LIST\?/, token: 'wcms', next: 'list' },
+ { regex: /MEDIA\?/, token: 'wcms', next: 'media' },
+ { regex: /[^&]*&/, token: 'wcms', pop: true },
+ { regex: /.*%/, token: 'wcms', next: 'start' },
+ ],
+ // 'element' mode, parameters' keywords of 'element' macros
+ element: [{ regex: null, push: 'wcms' }],
+ // 'summary' mode, parameters' keywords of the 'summary' macro
+ summary: [
+ { regex: /min|max/, token: 'keyword', push: 'wcms' },
+ { regex: null, push: 'wcms' },
+ ],
+ // 'list' mode, parameters' keywords of the 'list' macro
+ list: [{ regex: null, push: 'wcms' }],
+ // 'media' mode, parameters' keywords of the 'media' macro
+ media: [{ regex: null, push: 'wcms' }],
});
CodeMirror.defineMode('wcms-markdown', (config, parserConfig) => {