Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/smarty
File: smarty.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
/**
[3] Fix | Delete
* Smarty 2 and 3 mode.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
(function(mod) {
[7] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[8] Fix | Delete
mod(require("../../lib/codemirror"));
[9] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[10] Fix | Delete
define(["../../lib/codemirror"], mod);
[11] Fix | Delete
else // Plain browser env
[12] Fix | Delete
mod(CodeMirror);
[13] Fix | Delete
})(function(CodeMirror) {
[14] Fix | Delete
"use strict";
[15] Fix | Delete
[16] Fix | Delete
CodeMirror.defineMode("smarty", function(config, parserConf) {
[17] Fix | Delete
var rightDelimiter = parserConf.rightDelimiter || "}";
[18] Fix | Delete
var leftDelimiter = parserConf.leftDelimiter || "{";
[19] Fix | Delete
var version = parserConf.version || 2;
[20] Fix | Delete
var baseMode = CodeMirror.getMode(config, parserConf.baseMode || "null");
[21] Fix | Delete
[22] Fix | Delete
var keyFunctions = ["debug", "extends", "function", "include", "literal"];
[23] Fix | Delete
var regs = {
[24] Fix | Delete
operatorChars: /[+\-*&%=<>!?]/,
[25] Fix | Delete
validIdentifier: /[a-zA-Z0-9_]/,
[26] Fix | Delete
stringChar: /['"]/
[27] Fix | Delete
};
[28] Fix | Delete
[29] Fix | Delete
var last;
[30] Fix | Delete
function cont(style, lastType) {
[31] Fix | Delete
last = lastType;
[32] Fix | Delete
return style;
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
function chain(stream, state, parser) {
[36] Fix | Delete
state.tokenize = parser;
[37] Fix | Delete
return parser(stream, state);
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
// Smarty 3 allows { and } surrounded by whitespace to NOT slip into Smarty mode
[41] Fix | Delete
function doesNotCount(stream, pos) {
[42] Fix | Delete
if (pos == null) pos = stream.pos;
[43] Fix | Delete
return version === 3 && leftDelimiter == "{" &&
[44] Fix | Delete
(pos == stream.string.length || /\s/.test(stream.string.charAt(pos)));
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
function tokenTop(stream, state) {
[48] Fix | Delete
var string = stream.string;
[49] Fix | Delete
for (var scan = stream.pos;;) {
[50] Fix | Delete
var nextMatch = string.indexOf(leftDelimiter, scan);
[51] Fix | Delete
scan = nextMatch + leftDelimiter.length;
[52] Fix | Delete
if (nextMatch == -1 || !doesNotCount(stream, nextMatch + leftDelimiter.length)) break;
[53] Fix | Delete
}
[54] Fix | Delete
if (nextMatch == stream.pos) {
[55] Fix | Delete
stream.match(leftDelimiter);
[56] Fix | Delete
if (stream.eat("*")) {
[57] Fix | Delete
return chain(stream, state, tokenBlock("comment", "*" + rightDelimiter));
[58] Fix | Delete
} else {
[59] Fix | Delete
state.depth++;
[60] Fix | Delete
state.tokenize = tokenSmarty;
[61] Fix | Delete
last = "startTag";
[62] Fix | Delete
return "tag";
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
if (nextMatch > -1) stream.string = string.slice(0, nextMatch);
[67] Fix | Delete
var token = baseMode.token(stream, state.base);
[68] Fix | Delete
if (nextMatch > -1) stream.string = string;
[69] Fix | Delete
return token;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
// parsing Smarty content
[73] Fix | Delete
function tokenSmarty(stream, state) {
[74] Fix | Delete
if (stream.match(rightDelimiter, true)) {
[75] Fix | Delete
if (version === 3) {
[76] Fix | Delete
state.depth--;
[77] Fix | Delete
if (state.depth <= 0) {
[78] Fix | Delete
state.tokenize = tokenTop;
[79] Fix | Delete
}
[80] Fix | Delete
} else {
[81] Fix | Delete
state.tokenize = tokenTop;
[82] Fix | Delete
}
[83] Fix | Delete
return cont("tag", null);
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
if (stream.match(leftDelimiter, true)) {
[87] Fix | Delete
state.depth++;
[88] Fix | Delete
return cont("tag", "startTag");
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
var ch = stream.next();
[92] Fix | Delete
if (ch == "$") {
[93] Fix | Delete
stream.eatWhile(regs.validIdentifier);
[94] Fix | Delete
return cont("variable-2", "variable");
[95] Fix | Delete
} else if (ch == "|") {
[96] Fix | Delete
return cont("operator", "pipe");
[97] Fix | Delete
} else if (ch == ".") {
[98] Fix | Delete
return cont("operator", "property");
[99] Fix | Delete
} else if (regs.stringChar.test(ch)) {
[100] Fix | Delete
state.tokenize = tokenAttribute(ch);
[101] Fix | Delete
return cont("string", "string");
[102] Fix | Delete
} else if (regs.operatorChars.test(ch)) {
[103] Fix | Delete
stream.eatWhile(regs.operatorChars);
[104] Fix | Delete
return cont("operator", "operator");
[105] Fix | Delete
} else if (ch == "[" || ch == "]") {
[106] Fix | Delete
return cont("bracket", "bracket");
[107] Fix | Delete
} else if (ch == "(" || ch == ")") {
[108] Fix | Delete
return cont("bracket", "operator");
[109] Fix | Delete
} else if (/\d/.test(ch)) {
[110] Fix | Delete
stream.eatWhile(/\d/);
[111] Fix | Delete
return cont("number", "number");
[112] Fix | Delete
} else {
[113] Fix | Delete
[114] Fix | Delete
if (state.last == "variable") {
[115] Fix | Delete
if (ch == "@") {
[116] Fix | Delete
stream.eatWhile(regs.validIdentifier);
[117] Fix | Delete
return cont("property", "property");
[118] Fix | Delete
} else if (ch == "|") {
[119] Fix | Delete
stream.eatWhile(regs.validIdentifier);
[120] Fix | Delete
return cont("qualifier", "modifier");
[121] Fix | Delete
}
[122] Fix | Delete
} else if (state.last == "pipe") {
[123] Fix | Delete
stream.eatWhile(regs.validIdentifier);
[124] Fix | Delete
return cont("qualifier", "modifier");
[125] Fix | Delete
} else if (state.last == "whitespace") {
[126] Fix | Delete
stream.eatWhile(regs.validIdentifier);
[127] Fix | Delete
return cont("attribute", "modifier");
[128] Fix | Delete
} if (state.last == "property") {
[129] Fix | Delete
stream.eatWhile(regs.validIdentifier);
[130] Fix | Delete
return cont("property", null);
[131] Fix | Delete
} else if (/\s/.test(ch)) {
[132] Fix | Delete
last = "whitespace";
[133] Fix | Delete
return null;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
var str = "";
[137] Fix | Delete
if (ch != "/") {
[138] Fix | Delete
str += ch;
[139] Fix | Delete
}
[140] Fix | Delete
var c = null;
[141] Fix | Delete
while (c = stream.eat(regs.validIdentifier)) {
[142] Fix | Delete
str += c;
[143] Fix | Delete
}
[144] Fix | Delete
for (var i=0, j=keyFunctions.length; i<j; i++) {
[145] Fix | Delete
if (keyFunctions[i] == str) {
[146] Fix | Delete
return cont("keyword", "keyword");
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
if (/\s/.test(ch)) {
[150] Fix | Delete
return null;
[151] Fix | Delete
}
[152] Fix | Delete
return cont("tag", "tag");
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
function tokenAttribute(quote) {
[157] Fix | Delete
return function(stream, state) {
[158] Fix | Delete
var prevChar = null;
[159] Fix | Delete
var currChar = null;
[160] Fix | Delete
while (!stream.eol()) {
[161] Fix | Delete
currChar = stream.peek();
[162] Fix | Delete
if (stream.next() == quote && prevChar !== '\\') {
[163] Fix | Delete
state.tokenize = tokenSmarty;
[164] Fix | Delete
break;
[165] Fix | Delete
}
[166] Fix | Delete
prevChar = currChar;
[167] Fix | Delete
}
[168] Fix | Delete
return "string";
[169] Fix | Delete
};
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
function tokenBlock(style, terminator) {
[173] Fix | Delete
return function(stream, state) {
[174] Fix | Delete
while (!stream.eol()) {
[175] Fix | Delete
if (stream.match(terminator)) {
[176] Fix | Delete
state.tokenize = tokenTop;
[177] Fix | Delete
break;
[178] Fix | Delete
}
[179] Fix | Delete
stream.next();
[180] Fix | Delete
}
[181] Fix | Delete
return style;
[182] Fix | Delete
};
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
return {
[186] Fix | Delete
startState: function() {
[187] Fix | Delete
return {
[188] Fix | Delete
base: CodeMirror.startState(baseMode),
[189] Fix | Delete
tokenize: tokenTop,
[190] Fix | Delete
last: null,
[191] Fix | Delete
depth: 0
[192] Fix | Delete
};
[193] Fix | Delete
},
[194] Fix | Delete
copyState: function(state) {
[195] Fix | Delete
return {
[196] Fix | Delete
base: CodeMirror.copyState(baseMode, state.base),
[197] Fix | Delete
tokenize: state.tokenize,
[198] Fix | Delete
last: state.last,
[199] Fix | Delete
depth: state.depth
[200] Fix | Delete
};
[201] Fix | Delete
},
[202] Fix | Delete
innerMode: function(state) {
[203] Fix | Delete
if (state.tokenize == tokenTop)
[204] Fix | Delete
return {mode: baseMode, state: state.base};
[205] Fix | Delete
},
[206] Fix | Delete
token: function(stream, state) {
[207] Fix | Delete
var style = state.tokenize(stream, state);
[208] Fix | Delete
state.last = last;
[209] Fix | Delete
return style;
[210] Fix | Delete
},
[211] Fix | Delete
indent: function(state, text) {
[212] Fix | Delete
if (state.tokenize == tokenTop && baseMode.indent)
[213] Fix | Delete
return baseMode.indent(state.base, text);
[214] Fix | Delete
else
[215] Fix | Delete
return CodeMirror.Pass;
[216] Fix | Delete
},
[217] Fix | Delete
blockCommentStart: leftDelimiter + "*",
[218] Fix | Delete
blockCommentEnd: "*" + rightDelimiter
[219] Fix | Delete
};
[220] Fix | Delete
});
[221] Fix | Delete
[222] Fix | Delete
CodeMirror.defineMIME("text/x-smarty", "smarty");
[223] Fix | Delete
});
[224] Fix | Delete
[225] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function