LaravelTest
312 строк · 8.3 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode('tiki', function(config) {15function inBlock(style, terminator, returnTokenizer) {16return function(stream, state) {17while (!stream.eol()) {18if (stream.match(terminator)) {19state.tokenize = inText;20break;21}22stream.next();23}24
25if (returnTokenizer) state.tokenize = returnTokenizer;26
27return style;28};29}30
31function inLine(style) {32return function(stream, state) {33while(!stream.eol()) {34stream.next();35}36state.tokenize = inText;37return style;38};39}40
41function inText(stream, state) {42function chain(parser) {43state.tokenize = parser;44return parser(stream, state);45}46
47var sol = stream.sol();48var ch = stream.next();49
50//non start of line51switch (ch) { //switch is generally much faster than if, so it is used here52case "{": //plugin53stream.eat("/");54stream.eatSpace();55stream.eatWhile(/[^\s\u00a0=\"\'\/?(}]/);56state.tokenize = inPlugin;57return "tag";58case "_": //bold59if (stream.eat("_"))60return chain(inBlock("strong", "__", inText));61break;62case "'": //italics63if (stream.eat("'"))64return chain(inBlock("em", "''", inText));65break;66case "(":// Wiki Link67if (stream.eat("("))68return chain(inBlock("variable-2", "))", inText));69break;70case "[":// Weblink71return chain(inBlock("variable-3", "]", inText));72break;73case "|": //table74if (stream.eat("|"))75return chain(inBlock("comment", "||"));76break;77case "-":78if (stream.eat("=")) {//titleBar79return chain(inBlock("header string", "=-", inText));80} else if (stream.eat("-")) {//deleted81return chain(inBlock("error tw-deleted", "--", inText));82}83break;84case "=": //underline85if (stream.match("=="))86return chain(inBlock("tw-underline", "===", inText));87break;88case ":":89if (stream.eat(":"))90return chain(inBlock("comment", "::"));91break;92case "^": //box93return chain(inBlock("tw-box", "^"));94break;95case "~": //np96if (stream.match("np~"))97return chain(inBlock("meta", "~/np~"));98break;99}100
101//start of line types102if (sol) {103switch (ch) {104case "!": //header at start of line105if (stream.match('!!!!!')) {106return chain(inLine("header string"));107} else if (stream.match('!!!!')) {108return chain(inLine("header string"));109} else if (stream.match('!!!')) {110return chain(inLine("header string"));111} else if (stream.match('!!')) {112return chain(inLine("header string"));113} else {114return chain(inLine("header string"));115}116break;117case "*": //unordered list line item, or <li /> at start of line118case "#": //ordered list line item, or <li /> at start of line119case "+": //ordered list line item, or <li /> at start of line120return chain(inLine("tw-listitem bracket"));121break;122}123}124
125//stream.eatWhile(/[&{]/); was eating up plugins, turned off to act less like html and more like tiki126return null;127}128
129var indentUnit = config.indentUnit;130
131// Return variables for tokenizers132var pluginName, type;133function inPlugin(stream, state) {134var ch = stream.next();135var peek = stream.peek();136
137if (ch == "}") {138state.tokenize = inText;139//type = ch == ")" ? "endPlugin" : "selfclosePlugin"; inPlugin140return "tag";141} else if (ch == "(" || ch == ")") {142return "bracket";143} else if (ch == "=") {144type = "equals";145
146if (peek == ">") {147stream.next();148peek = stream.peek();149}150
151//here we detect values directly after equal character with no quotes152if (!/[\'\"]/.test(peek)) {153state.tokenize = inAttributeNoQuote();154}155//end detect values156
157return "operator";158} else if (/[\'\"]/.test(ch)) {159state.tokenize = inAttribute(ch);160return state.tokenize(stream, state);161} else {162stream.eatWhile(/[^\s\u00a0=\"\'\/?]/);163return "keyword";164}165}166
167function inAttribute(quote) {168return function(stream, state) {169while (!stream.eol()) {170if (stream.next() == quote) {171state.tokenize = inPlugin;172break;173}174}175return "string";176};177}178
179function inAttributeNoQuote() {180return function(stream, state) {181while (!stream.eol()) {182var ch = stream.next();183var peek = stream.peek();184if (ch == " " || ch == "," || /[ )}]/.test(peek)) {185state.tokenize = inPlugin;186break;187}188}189return "string";190};191}192
193var curState, setStyle;194function pass() {195for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);196}
197
198function cont() {199pass.apply(null, arguments);200return true;201}
202
203function pushContext(pluginName, startOfLine) {204var noIndent = curState.context && curState.context.noIndent;205curState.context = {206prev: curState.context,207pluginName: pluginName,208indent: curState.indented,209startOfLine: startOfLine,210noIndent: noIndent211};212}
213
214function popContext() {215if (curState.context) curState.context = curState.context.prev;216}
217
218function element(type) {219if (type == "openPlugin") {curState.pluginName = pluginName; return cont(attributes, endplugin(curState.startOfLine));}220else if (type == "closePlugin") {221var err = false;222if (curState.context) {223err = curState.context.pluginName != pluginName;224popContext();225} else {226err = true;227}228if (err) setStyle = "error";229return cont(endcloseplugin(err));230}231else if (type == "string") {232if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");233if (curState.tokenize == inText) popContext();234return cont();235}236else return cont();237}
238
239function endplugin(startOfLine) {240return function(type) {241if (242type == "selfclosePlugin" ||243type == "endPlugin"244)245return cont();246if (type == "endPlugin") {pushContext(curState.pluginName, startOfLine); return cont();}247return cont();248};249}
250
251function endcloseplugin(err) {252return function(type) {253if (err) setStyle = "error";254if (type == "endPlugin") return cont();255return pass();256};257}
258
259function attributes(type) {260if (type == "keyword") {setStyle = "attribute"; return cont(attributes);}261if (type == "equals") return cont(attvalue, attributes);262return pass();263}
264function attvalue(type) {265if (type == "keyword") {setStyle = "string"; return cont();}266if (type == "string") return cont(attvaluemaybe);267return pass();268}
269function attvaluemaybe(type) {270if (type == "string") return cont(attvaluemaybe);271else return pass();272}
273return {274startState: function() {275return {tokenize: inText, cc: [], indented: 0, startOfLine: true, pluginName: null, context: null};276},277token: function(stream, state) {278if (stream.sol()) {279state.startOfLine = true;280state.indented = stream.indentation();281}282if (stream.eatSpace()) return null;283
284setStyle = type = pluginName = null;285var style = state.tokenize(stream, state);286if ((style || type) && style != "comment") {287curState = state;288while (true) {289var comb = state.cc.pop() || element;290if (comb(type || style)) break;291}292}293state.startOfLine = false;294return setStyle || style;295},296indent: function(state, textAfter) {297var context = state.context;298if (context && context.noIndent) return 0;299if (context && /^{\//.test(textAfter))300context = context.prev;301while (context && !context.startOfLine)302context = context.prev;303if (context) return context.indent + indentUnit;304else return 0;305},306electricChars: "/"307};308});309
310CodeMirror.defineMIME("text/tiki", "tiki");311
312});313