Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/soy
File: soy.js
// CodeMirror, copyright (c) by Marijn Haverbeke and others
[0] Fix | Delete
// Distributed under an MIT license: http://codemirror.net/LICENSE
[1] Fix | Delete
[2] Fix | Delete
(function(mod) {
[3] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[4] Fix | Delete
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"));
[5] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[6] Fix | Delete
define(["../../lib/codemirror", "../htmlmixed/htmlmixed"], mod);
[7] Fix | Delete
else // Plain browser env
[8] Fix | Delete
mod(CodeMirror);
[9] Fix | Delete
})(function(CodeMirror) {
[10] Fix | Delete
"use strict";
[11] Fix | Delete
[12] Fix | Delete
var indentingTags = ["template", "literal", "msg", "fallbackmsg", "let", "if", "elseif",
[13] Fix | Delete
"else", "switch", "case", "default", "foreach", "ifempty", "for",
[14] Fix | Delete
"call", "param", "deltemplate", "delcall", "log"];
[15] Fix | Delete
[16] Fix | Delete
CodeMirror.defineMode("soy", function(config) {
[17] Fix | Delete
var textMode = CodeMirror.getMode(config, "text/plain");
[18] Fix | Delete
var modes = {
[19] Fix | Delete
html: CodeMirror.getMode(config, {name: "text/html", multilineTagIndentFactor: 2, multilineTagIndentPastTag: false}),
[20] Fix | Delete
attributes: textMode,
[21] Fix | Delete
text: textMode,
[22] Fix | Delete
uri: textMode,
[23] Fix | Delete
css: CodeMirror.getMode(config, "text/css"),
[24] Fix | Delete
js: CodeMirror.getMode(config, {name: "text/javascript", statementIndent: 2 * config.indentUnit})
[25] Fix | Delete
};
[26] Fix | Delete
[27] Fix | Delete
function last(array) {
[28] Fix | Delete
return array[array.length - 1];
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
function tokenUntil(stream, state, untilRegExp) {
[32] Fix | Delete
var oldString = stream.string;
[33] Fix | Delete
var match = untilRegExp.exec(oldString.substr(stream.pos));
[34] Fix | Delete
if (match) {
[35] Fix | Delete
// We don't use backUp because it backs up just the position, not the state.
[36] Fix | Delete
// This uses an undocumented API.
[37] Fix | Delete
stream.string = oldString.substr(0, stream.pos + match.index);
[38] Fix | Delete
}
[39] Fix | Delete
var result = stream.hideFirstChars(state.indent, function() {
[40] Fix | Delete
return state.localMode.token(stream, state.localState);
[41] Fix | Delete
});
[42] Fix | Delete
stream.string = oldString;
[43] Fix | Delete
return result;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
return {
[47] Fix | Delete
startState: function() {
[48] Fix | Delete
return {
[49] Fix | Delete
kind: [],
[50] Fix | Delete
kindTag: [],
[51] Fix | Delete
soyState: [],
[52] Fix | Delete
indent: 0,
[53] Fix | Delete
localMode: modes.html,
[54] Fix | Delete
localState: CodeMirror.startState(modes.html)
[55] Fix | Delete
};
[56] Fix | Delete
},
[57] Fix | Delete
[58] Fix | Delete
copyState: function(state) {
[59] Fix | Delete
return {
[60] Fix | Delete
tag: state.tag, // Last seen Soy tag.
[61] Fix | Delete
kind: state.kind.concat([]), // Values of kind="" attributes.
[62] Fix | Delete
kindTag: state.kindTag.concat([]), // Opened tags with kind="" attributes.
[63] Fix | Delete
soyState: state.soyState.concat([]),
[64] Fix | Delete
indent: state.indent, // Indentation of the following line.
[65] Fix | Delete
localMode: state.localMode,
[66] Fix | Delete
localState: CodeMirror.copyState(state.localMode, state.localState)
[67] Fix | Delete
};
[68] Fix | Delete
},
[69] Fix | Delete
[70] Fix | Delete
token: function(stream, state) {
[71] Fix | Delete
var match;
[72] Fix | Delete
[73] Fix | Delete
switch (last(state.soyState)) {
[74] Fix | Delete
case "comment":
[75] Fix | Delete
if (stream.match(/^.*?\*\//)) {
[76] Fix | Delete
state.soyState.pop();
[77] Fix | Delete
} else {
[78] Fix | Delete
stream.skipToEnd();
[79] Fix | Delete
}
[80] Fix | Delete
return "comment";
[81] Fix | Delete
[82] Fix | Delete
case "variable":
[83] Fix | Delete
if (stream.match(/^}/)) {
[84] Fix | Delete
state.indent -= 2 * config.indentUnit;
[85] Fix | Delete
state.soyState.pop();
[86] Fix | Delete
return "variable-2";
[87] Fix | Delete
}
[88] Fix | Delete
stream.next();
[89] Fix | Delete
return null;
[90] Fix | Delete
[91] Fix | Delete
case "tag":
[92] Fix | Delete
if (stream.match(/^\/?}/)) {
[93] Fix | Delete
if (state.tag == "/template" || state.tag == "/deltemplate") state.indent = 0;
[94] Fix | Delete
else state.indent -= (stream.current() == "/}" || indentingTags.indexOf(state.tag) == -1 ? 2 : 1) * config.indentUnit;
[95] Fix | Delete
state.soyState.pop();
[96] Fix | Delete
return "keyword";
[97] Fix | Delete
} else if (stream.match(/^([\w?]+)(?==)/)) {
[98] Fix | Delete
if (stream.current() == "kind" && (match = stream.match(/^="([^"]+)/, false))) {
[99] Fix | Delete
var kind = match[1];
[100] Fix | Delete
state.kind.push(kind);
[101] Fix | Delete
state.kindTag.push(state.tag);
[102] Fix | Delete
state.localMode = modes[kind] || modes.html;
[103] Fix | Delete
state.localState = CodeMirror.startState(state.localMode);
[104] Fix | Delete
}
[105] Fix | Delete
return "attribute";
[106] Fix | Delete
} else if (stream.match(/^"/)) {
[107] Fix | Delete
state.soyState.push("string");
[108] Fix | Delete
return "string";
[109] Fix | Delete
}
[110] Fix | Delete
stream.next();
[111] Fix | Delete
return null;
[112] Fix | Delete
[113] Fix | Delete
case "literal":
[114] Fix | Delete
if (stream.match(/^(?=\{\/literal})/)) {
[115] Fix | Delete
state.indent -= config.indentUnit;
[116] Fix | Delete
state.soyState.pop();
[117] Fix | Delete
return this.token(stream, state);
[118] Fix | Delete
}
[119] Fix | Delete
return tokenUntil(stream, state, /\{\/literal}/);
[120] Fix | Delete
[121] Fix | Delete
case "string":
[122] Fix | Delete
var match = stream.match(/^.*?("|\\[\s\S])/);
[123] Fix | Delete
if (!match) {
[124] Fix | Delete
stream.skipToEnd();
[125] Fix | Delete
} else if (match[1] == "\"") {
[126] Fix | Delete
state.soyState.pop();
[127] Fix | Delete
}
[128] Fix | Delete
return "string";
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
if (stream.match(/^\/\*/)) {
[132] Fix | Delete
state.soyState.push("comment");
[133] Fix | Delete
return "comment";
[134] Fix | Delete
} else if (stream.match(stream.sol() ? /^\s*\/\/.*/ : /^\s+\/\/.*/)) {
[135] Fix | Delete
return "comment";
[136] Fix | Delete
} else if (stream.match(/^\{\$[\w?]*/)) {
[137] Fix | Delete
state.indent += 2 * config.indentUnit;
[138] Fix | Delete
state.soyState.push("variable");
[139] Fix | Delete
return "variable-2";
[140] Fix | Delete
} else if (stream.match(/^\{literal}/)) {
[141] Fix | Delete
state.indent += config.indentUnit;
[142] Fix | Delete
state.soyState.push("literal");
[143] Fix | Delete
return "keyword";
[144] Fix | Delete
} else if (match = stream.match(/^\{([\/@\\]?[\w?]*)/)) {
[145] Fix | Delete
if (match[1] != "/switch")
[146] Fix | Delete
state.indent += (/^(\/|(else|elseif|case|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit;
[147] Fix | Delete
state.tag = match[1];
[148] Fix | Delete
if (state.tag == "/" + last(state.kindTag)) {
[149] Fix | Delete
// We found the tag that opened the current kind="".
[150] Fix | Delete
state.kind.pop();
[151] Fix | Delete
state.kindTag.pop();
[152] Fix | Delete
state.localMode = modes[last(state.kind)] || modes.html;
[153] Fix | Delete
state.localState = CodeMirror.startState(state.localMode);
[154] Fix | Delete
}
[155] Fix | Delete
state.soyState.push("tag");
[156] Fix | Delete
return "keyword";
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/);
[160] Fix | Delete
},
[161] Fix | Delete
[162] Fix | Delete
indent: function(state, textAfter) {
[163] Fix | Delete
var indent = state.indent, top = last(state.soyState);
[164] Fix | Delete
if (top == "comment") return CodeMirror.Pass;
[165] Fix | Delete
[166] Fix | Delete
if (top == "literal") {
[167] Fix | Delete
if (/^\{\/literal}/.test(textAfter)) indent -= config.indentUnit;
[168] Fix | Delete
} else {
[169] Fix | Delete
if (/^\s*\{\/(template|deltemplate)\b/.test(textAfter)) return 0;
[170] Fix | Delete
if (/^\{(\/|(fallbackmsg|elseif|else|ifempty)\b)/.test(textAfter)) indent -= config.indentUnit;
[171] Fix | Delete
if (state.tag != "switch" && /^\{(case|default)\b/.test(textAfter)) indent -= config.indentUnit;
[172] Fix | Delete
if (/^\{\/switch\b/.test(textAfter)) indent -= config.indentUnit;
[173] Fix | Delete
}
[174] Fix | Delete
if (indent && state.localMode.indent)
[175] Fix | Delete
indent += state.localMode.indent(state.localState, textAfter);
[176] Fix | Delete
return indent;
[177] Fix | Delete
},
[178] Fix | Delete
[179] Fix | Delete
innerMode: function(state) {
[180] Fix | Delete
if (state.soyState.length && last(state.soyState) != "literal") return null;
[181] Fix | Delete
else return {state: state.localState, mode: state.localMode};
[182] Fix | Delete
},
[183] Fix | Delete
[184] Fix | Delete
electricInput: /^\s*\{(\/|\/template|\/deltemplate|\/switch|fallbackmsg|elseif|else|case|default|ifempty|\/literal\})$/,
[185] Fix | Delete
lineComment: "//",
[186] Fix | Delete
blockCommentStart: "/*",
[187] Fix | Delete
blockCommentEnd: "*/",
[188] Fix | Delete
blockCommentContinue: " * ",
[189] Fix | Delete
fold: "indent"
[190] Fix | Delete
};
[191] Fix | Delete
}, "htmlmixed");
[192] Fix | Delete
[193] Fix | Delete
CodeMirror.registerHelper("hintWords", "soy", indentingTags.concat(
[194] Fix | Delete
["delpackage", "namespace", "alias", "print", "css", "debugger"]));
[195] Fix | Delete
[196] Fix | Delete
CodeMirror.defineMIME("text/x-soy", "soy");
[197] Fix | Delete
});
[198] Fix | Delete
[199] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function