5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode('tiki', function(config) {
15
function inBlock(style, terminator, returnTokenizer) {
16
return function(stream, state) {
17
while (!stream.eol()) {
18
if (stream.match(terminator)) {
19
state.tokenize = inText;
25
if (returnTokenizer) state.tokenize = returnTokenizer;
31
function inLine(style) {
32
return function(stream, state) {
33
while(!stream.eol()) {
36
state.tokenize = inText;
41
function inText(stream, state) {
42
function chain(parser) {
43
state.tokenize = parser;
44
return parser(stream, state);
47
var sol = stream.sol();
48
var ch = stream.next();
55
stream.eatWhile(/[^\s\u00a0=\"\'\/?(}]/);
56
state.tokenize = inPlugin;
60
return chain(inBlock("strong", "__", inText));
64
return chain(inBlock("em", "''", inText));
68
return chain(inBlock("variable-2", "))", inText));
71
return chain(inBlock("variable-3", "]", inText));
75
return chain(inBlock("comment", "||"));
78
if (stream.eat("=")) {
79
return chain(inBlock("header string", "=-", inText));
80
} else if (stream.eat("-")) {
81
return chain(inBlock("error tw-deleted", "--", inText));
85
if (stream.match("=="))
86
return chain(inBlock("tw-underline", "===", inText));
90
return chain(inBlock("comment", "::"));
93
return chain(inBlock("tw-box", "^"));
96
if (stream.match("np~"))
97
return chain(inBlock("meta", "~/np~"));
105
if (stream.match('!!!!!')) {
106
return chain(inLine("header string"));
107
} else if (stream.match('!!!!')) {
108
return chain(inLine("header string"));
109
} else if (stream.match('!!!')) {
110
return chain(inLine("header string"));
111
} else if (stream.match('!!')) {
112
return chain(inLine("header string"));
114
return chain(inLine("header string"));
120
return chain(inLine("tw-listitem bracket"));
129
var indentUnit = config.indentUnit;
132
var pluginName, type;
133
function inPlugin(stream, state) {
134
var ch = stream.next();
135
var peek = stream.peek();
138
state.tokenize = inText;
141
} else if (ch == "(" || ch == ")") {
143
} else if (ch == "=") {
148
peek = stream.peek();
152
if (!/[\'\"]/.test(peek)) {
153
state.tokenize = inAttributeNoQuote();
158
} else if (/[\'\"]/.test(ch)) {
159
state.tokenize = inAttribute(ch);
160
return state.tokenize(stream, state);
162
stream.eatWhile(/[^\s\u00a0=\"\'\/?]/);
167
function inAttribute(quote) {
168
return function(stream, state) {
169
while (!stream.eol()) {
170
if (stream.next() == quote) {
171
state.tokenize = inPlugin;
179
function inAttributeNoQuote() {
180
return function(stream, state) {
181
while (!stream.eol()) {
182
var ch = stream.next();
183
var peek = stream.peek();
184
if (ch == " " || ch == "," || /[ )}]/.test(peek)) {
185
state.tokenize = inPlugin;
193
var curState, setStyle;
195
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
199
pass.apply(null, arguments);
203
function pushContext(pluginName, startOfLine) {
204
var noIndent = curState.context && curState.context.noIndent;
206
prev: curState.context,
207
pluginName: pluginName,
208
indent: curState.indented,
209
startOfLine: startOfLine,
214
function popContext() {
215
if (curState.context) curState.context = curState.context.prev;
218
function element(type) {
219
if (type == "openPlugin") {curState.pluginName = pluginName; return cont(attributes, endplugin(curState.startOfLine));}
220
else if (type == "closePlugin") {
222
if (curState.context) {
223
err = curState.context.pluginName != pluginName;
228
if (err) setStyle = "error";
229
return cont(endcloseplugin(err));
231
else if (type == "string") {
232
if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
233
if (curState.tokenize == inText) popContext();
239
function endplugin(startOfLine) {
240
return function(type) {
242
type == "selfclosePlugin" ||
246
if (type == "endPlugin") {pushContext(curState.pluginName, startOfLine); return cont();}
251
function endcloseplugin(err) {
252
return function(type) {
253
if (err) setStyle = "error";
254
if (type == "endPlugin") return cont();
259
function attributes(type) {
260
if (type == "keyword") {setStyle = "attribute"; return cont(attributes);}
261
if (type == "equals") return cont(attvalue, attributes);
264
function attvalue(type) {
265
if (type == "keyword") {setStyle = "string"; return cont();}
266
if (type == "string") return cont(attvaluemaybe);
269
function attvaluemaybe(type) {
270
if (type == "string") return cont(attvaluemaybe);
274
startState: function() {
275
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, pluginName: null, context: null};
277
token: function(stream, state) {
279
state.startOfLine = true;
280
state.indented = stream.indentation();
282
if (stream.eatSpace()) return null;
284
setStyle = type = pluginName = null;
285
var style = state.tokenize(stream, state);
286
if ((style || type) && style != "comment") {
289
var comb = state.cc.pop() || element;
290
if (comb(type || style)) break;
293
state.startOfLine = false;
294
return setStyle || style;
296
indent: function(state, textAfter) {
297
var context = state.context;
298
if (context && context.noIndent) return 0;
299
if (context && /^{\//.test(textAfter))
300
context = context.prev;
301
while (context && !context.startOfLine)
302
context = context.prev;
303
if (context) return context.indent + indentUnit;
310
CodeMirror.defineMIME("text/tiki", "tiki");