mirror of
https://github.com/documize/community.git
synced 2025-08-01 19:45:24 +02:00
CodeMirror dependency upgraded to v5.32.0
For handling Markdown and Code section types
This commit is contained in:
parent
3337db6b27
commit
0336f84a83
351 changed files with 3408 additions and 1945 deletions
132
gui/public/codemirror/mode/soy/soy.js
vendored
Executable file → Normal file
132
gui/public/codemirror/mode/soy/soy.js
vendored
Executable file → Normal file
|
@ -31,6 +31,12 @@
|
|||
}
|
||||
|
||||
function tokenUntil(stream, state, untilRegExp) {
|
||||
if (stream.sol()) {
|
||||
for (var indent = 0; indent < state.indent; indent++) {
|
||||
if (!stream.eat(/\s/)) break;
|
||||
}
|
||||
if (indent) return null;
|
||||
}
|
||||
var oldString = stream.string;
|
||||
var match = untilRegExp.exec(oldString.substr(stream.pos));
|
||||
if (match) {
|
||||
|
@ -39,7 +45,8 @@
|
|||
stream.string = oldString.substr(0, stream.pos + match.index);
|
||||
}
|
||||
var result = stream.hideFirstChars(state.indent, function() {
|
||||
return state.localMode.token(stream, state.localState);
|
||||
var localState = last(state.localStates);
|
||||
return localState.mode.token(stream, localState.state);
|
||||
});
|
||||
stream.string = oldString;
|
||||
return result;
|
||||
|
@ -80,11 +87,14 @@
|
|||
kindTag: [],
|
||||
soyState: [],
|
||||
templates: null,
|
||||
variables: null,
|
||||
variables: prepend(null, 'ij'),
|
||||
scopes: null,
|
||||
indent: 0,
|
||||
localMode: modes.html,
|
||||
localState: CodeMirror.startState(modes.html)
|
||||
quoteKind: null,
|
||||
localStates: [{
|
||||
mode: modes.html,
|
||||
state: CodeMirror.startState(modes.html)
|
||||
}]
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -98,8 +108,13 @@
|
|||
variables: state.variables,
|
||||
scopes: state.scopes,
|
||||
indent: state.indent, // Indentation of the following line.
|
||||
localMode: state.localMode,
|
||||
localState: CodeMirror.copyState(state.localMode, state.localState)
|
||||
quoteKind: state.quoteKind,
|
||||
localStates: state.localStates.map(function(localState) {
|
||||
return {
|
||||
mode: localState.mode,
|
||||
state: CodeMirror.copyState(localState.mode, localState.state)
|
||||
};
|
||||
})
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -113,8 +128,34 @@
|
|||
} else {
|
||||
stream.skipToEnd();
|
||||
}
|
||||
if (!state.scopes) {
|
||||
var paramRe = /@param\??\s+(\S+)/g;
|
||||
var current = stream.current();
|
||||
for (var match; (match = paramRe.exec(current)); ) {
|
||||
state.variables = prepend(state.variables, match[1]);
|
||||
}
|
||||
}
|
||||
return "comment";
|
||||
|
||||
case "string":
|
||||
var match = stream.match(/^.*?(["']|\\[\s\S])/);
|
||||
if (!match) {
|
||||
stream.skipToEnd();
|
||||
} else if (match[1] == state.quoteKind) {
|
||||
state.quoteKind = null;
|
||||
state.soyState.pop();
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
|
||||
if (stream.match(/^\/\*/)) {
|
||||
state.soyState.push("comment");
|
||||
return "comment";
|
||||
} else if (stream.match(stream.sol() || (state.soyState.length && last(state.soyState) != "literal") ? /^\s*\/\/.*/ : /^\s+\/\/.*/)) {
|
||||
return "comment";
|
||||
}
|
||||
|
||||
switch (last(state.soyState)) {
|
||||
case "templ-def":
|
||||
if (match = stream.match(/^\.?([\w]+(?!\.[\w]+)*)/)) {
|
||||
state.templates = prepend(state.templates, match[1]);
|
||||
|
@ -139,8 +180,8 @@
|
|||
return null;
|
||||
|
||||
case "param-def":
|
||||
if (match = stream.match(/^([\w]+)(?=:)/)) {
|
||||
state.variables = prepend(state.variables, match[1]);
|
||||
if (match = stream.match(/^\w+/)) {
|
||||
state.variables = prepend(state.variables, match[0]);
|
||||
state.soyState.pop();
|
||||
state.soyState.push("param-type");
|
||||
return "def";
|
||||
|
@ -172,6 +213,7 @@
|
|||
if (stream.match(/^\/?}/)) {
|
||||
if (state.tag == "/template" || state.tag == "/deltemplate") {
|
||||
popscope(state);
|
||||
state.variables = prepend(null, 'ij');
|
||||
state.indent = 0;
|
||||
} else {
|
||||
if (state.tag == "/for" || state.tag == "/foreach") {
|
||||
|
@ -187,12 +229,20 @@
|
|||
var kind = match[1];
|
||||
state.kind.push(kind);
|
||||
state.kindTag.push(state.tag);
|
||||
state.localMode = modes[kind] || modes.html;
|
||||
state.localState = CodeMirror.startState(state.localMode);
|
||||
var mode = modes[kind] || modes.html;
|
||||
var localState = last(state.localStates);
|
||||
if (localState.mode.indent) {
|
||||
state.indent += localState.mode.indent(localState.state, "");
|
||||
}
|
||||
state.localStates.push({
|
||||
mode: mode,
|
||||
state: CodeMirror.startState(mode)
|
||||
});
|
||||
}
|
||||
return "attribute";
|
||||
} else if (stream.match(/^"/)) {
|
||||
} else if (match = stream.match(/^["']/)) {
|
||||
state.soyState.push("string");
|
||||
state.quoteKind = match;
|
||||
return "string";
|
||||
}
|
||||
if (match = stream.match(/^\$([\w]+)/)) {
|
||||
|
@ -211,55 +261,53 @@
|
|||
return this.token(stream, state);
|
||||
}
|
||||
return tokenUntil(stream, state, /\{\/literal}/);
|
||||
|
||||
case "string":
|
||||
var match = stream.match(/^.*?("|\\[\s\S])/);
|
||||
if (!match) {
|
||||
stream.skipToEnd();
|
||||
} else if (match[1] == "\"") {
|
||||
state.soyState.pop();
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
|
||||
if (stream.match(/^\/\*/)) {
|
||||
state.soyState.push("comment");
|
||||
return "comment";
|
||||
} else if (stream.match(stream.sol() ? /^\s*\/\/.*/ : /^\s+\/\/.*/)) {
|
||||
return "comment";
|
||||
} else if (stream.match(/^\{literal}/)) {
|
||||
if (stream.match(/^\{literal}/)) {
|
||||
state.indent += config.indentUnit;
|
||||
state.soyState.push("literal");
|
||||
return "keyword";
|
||||
} else if (match = stream.match(/^\{([\/@\\]?[\w?]*)/)) {
|
||||
|
||||
// A tag-keyword must be followed by whitespace, comment or a closing tag.
|
||||
} else if (match = stream.match(/^\{([\/@\\]?\w+\??)(?=[\s\}]|\/[/*])/)) {
|
||||
if (match[1] != "/switch")
|
||||
state.indent += (/^(\/|(else|elseif|ifempty|case|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit;
|
||||
state.indent += (/^(\/|(else|elseif|ifempty|case|fallbackmsg|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit;
|
||||
state.tag = match[1];
|
||||
if (state.tag == "/" + last(state.kindTag)) {
|
||||
// We found the tag that opened the current kind="".
|
||||
state.kind.pop();
|
||||
state.kindTag.pop();
|
||||
state.localMode = modes[last(state.kind)] || modes.html;
|
||||
state.localState = CodeMirror.startState(state.localMode);
|
||||
state.localStates.pop();
|
||||
var localState = last(state.localStates);
|
||||
if (localState.mode.indent) {
|
||||
state.indent -= localState.mode.indent(localState.state, "");
|
||||
}
|
||||
}
|
||||
state.soyState.push("tag");
|
||||
if (state.tag == "template" || state.tag == "deltemplate") {
|
||||
state.soyState.push("templ-def");
|
||||
}
|
||||
if (state.tag == "call" || state.tag == "delcall") {
|
||||
} else if (state.tag == "call" || state.tag == "delcall") {
|
||||
state.soyState.push("templ-ref");
|
||||
}
|
||||
if (state.tag == "let") {
|
||||
} else if (state.tag == "let") {
|
||||
state.soyState.push("var-def");
|
||||
}
|
||||
if (state.tag == "for" || state.tag == "foreach") {
|
||||
} else if (state.tag == "for" || state.tag == "foreach") {
|
||||
state.scopes = prepend(state.scopes, state.variables);
|
||||
state.soyState.push("var-def");
|
||||
}
|
||||
if (state.tag.match(/^@param\??/)) {
|
||||
} else if (state.tag == "namespace") {
|
||||
if (!state.scopes) {
|
||||
state.variables = prepend(null, 'ij');
|
||||
}
|
||||
} else if (state.tag.match(/^@(?:param\??|inject)/)) {
|
||||
state.soyState.push("param-def");
|
||||
}
|
||||
return "keyword";
|
||||
|
||||
// Not a tag-keyword; it's an implicit print tag.
|
||||
} else if (stream.eat('{')) {
|
||||
state.tag = "print";
|
||||
state.indent += 2 * config.indentUnit;
|
||||
state.soyState.push("tag");
|
||||
return "keyword";
|
||||
}
|
||||
|
||||
return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/);
|
||||
|
@ -277,14 +325,16 @@
|
|||
if (state.tag != "switch" && /^\{(case|default)\b/.test(textAfter)) indent -= config.indentUnit;
|
||||
if (/^\{\/switch\b/.test(textAfter)) indent -= config.indentUnit;
|
||||
}
|
||||
if (indent && state.localMode.indent)
|
||||
indent += state.localMode.indent(state.localState, textAfter);
|
||||
var localState = last(state.localStates);
|
||||
if (indent && localState.mode.indent) {
|
||||
indent += localState.mode.indent(localState.state, textAfter);
|
||||
}
|
||||
return indent;
|
||||
},
|
||||
|
||||
innerMode: function(state) {
|
||||
if (state.soyState.length && last(state.soyState) != "literal") return null;
|
||||
else return {state: state.localState, mode: state.localMode};
|
||||
else return last(state.localStates);
|
||||
},
|
||||
|
||||
electricInput: /^\s*\{(\/|\/template|\/deltemplate|\/switch|fallbackmsg|elseif|else|case|default|ifempty|\/literal\})$/,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue