Skip to content

Commit 1772a12

Browse files
Fixed plugins
1 parent a08d459 commit 1772a12

File tree

1 file changed

+61
-45
lines changed

1 file changed

+61
-45
lines changed

wikiLingo.js

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
CodeMirror.defineMode('wikiLingo', function(config) {
2+
var activeStyles = [];
23
function inBlock(style, terminator, returnTokenizer) {
34
return function(stream, state) {
5+
var styles;
6+
activeStyles.push(style);
47
while (!stream.eol()) {
58
if (stream.match(terminator)) {
69
state.tokenize = inText;
@@ -9,19 +12,27 @@ CodeMirror.defineMode('wikiLingo', function(config) {
912
stream.next();
1013
}
1114

12-
if (returnTokenizer) state.tokenize = returnTokenizer;
15+
if (returnTokenizer) {
16+
state.tokenize = returnTokenizer;
17+
}
1318

14-
return style;
19+
styles = activeStyles.join(' ');
20+
activeStyles.pop();
21+
return styles;
1522
};
1623
}
1724

1825
function inLine(style) {
1926
return function(stream, state) {
27+
var styles;
28+
activeStyles.push(style);
2029
while(!stream.eol()) {
2130
stream.next();
2231
}
2332
state.tokenize = inText;
24-
return style;
33+
styles = activeStyles.join(' ');
34+
activeStyles.pop();
35+
return styles;
2536
};
2637
}
2738

@@ -37,32 +48,27 @@ CodeMirror.defineMode('wikiLingo', function(config) {
3748
//non start of line
3849
switch (ch) { //switch is generally much faster than if, so it is used here
3950
case "{": //plugin
40-
stream.eat("/");
41-
stream.eatSpace();
42-
var tagName = "";
43-
var c;
44-
while ((c = stream.eat(/[^\s\u00a0=\"\'\/?(}]/))) tagName += c;
4551
state.tokenize = inPlugin;
46-
return "tag";
52+
return "bracket";
4753
break;
4854
case "_": //bold
4955
if (stream.eat("_")) {
50-
return chain(inBlock("strong", "__", inText));
56+
return chain(inBlock("strong", "__"));
5157
}
5258
break;
5359
case "'": //italics
5460
if (stream.eat("'")) {
5561
// Italic text
56-
return chain(inBlock("em", "''", inText));
62+
return chain(inBlock("em", "''"));
5763
}
5864
break;
5965
case "(":// Wiki Link
6066
if (stream.eat("(")) {
61-
return chain(inBlock("variable-2", "))", inText));
67+
return chain(inBlock("variable-2", "))"));
6268
}
6369
break;
6470
case "[":// Weblink
65-
return chain(inBlock("variable-3", "]", inText));
71+
return chain(inBlock("variable-3", "]"));
6672
break;
6773
case "|": //table
6874
if (stream.eat("|")) {
@@ -71,11 +77,11 @@ CodeMirror.defineMode('wikiLingo', function(config) {
7177
break;
7278
case "-":
7379
if (stream.eat("=")) {//titleBar
74-
return chain(inBlock("header string", "=-", inText));
80+
return chain(inBlock("header string", "=-"));
7581
}
7682

7783
else if (stream.eat("-")) {//deleted
78-
return chain(inBlock("comment wl-deleted", "--", inText));
84+
return chain(inBlock("comment wl-deleted", "--"));
7985
}
8086

8187
else if (stream.eat("~")) {//no parse
@@ -92,12 +98,12 @@ CodeMirror.defineMode('wikiLingo', function(config) {
9298
break;
9399
case "~":
94100
if (stream.eat("~")) {//color
95-
return chain(inBlock("variable-3", "~~", inText));
101+
return chain(inBlock("variable-3", "~~"));
96102
}
97103
break;
98104
case "=": //underline
99105
if (stream.match("==")) {
100-
return chain(inBlock("wl-underline", "===", inText));
106+
return chain(inBlock("wl-underline", "==="));
101107
}
102108
break;
103109
case ":":
@@ -120,7 +126,12 @@ CodeMirror.defineMode('wikiLingo', function(config) {
120126
break;
121127
case "%"://variable
122128
if (stream.match(/[a-zA-Z]/)) {
123-
return chain(inBlock("variable variable-2", "%"));
129+
stream.eatWhile(/[a-zA-Z_\-0-9]/);
130+
if (stream.eat('%')) {
131+
return "variable variable-2";
132+
} else {
133+
return "error";
134+
}
124135
}
125136
break;
126137
}
@@ -153,53 +164,58 @@ CodeMirror.defineMode('wikiLingo', function(config) {
153164
return null;
154165
}
155166

156-
var indentUnit = config.indentUnit;
167+
var indentUnit = config.indentUnit,
168+
169+
// Return variables for tokenizers
170+
pluginName,
171+
type,
172+
isQuote = /[\'\"`]/;
157173

158-
// Return variables for tokenizers
159-
var pluginName, type;
160174
function inPlugin(stream, state) {
161-
var ch = stream.next();
162-
var peek = stream.peek();
175+
if (stream.eatWhile(/[A-Z0-9_-]+/)) {
176+
//plugin
177+
return 'tag'
178+
} else if (stream.eatWhile(/[a-z0-9_-]+/)) {
179+
//inline-plugin
180+
return 'tag'
181+
}
163182

183+
var ch = stream.next(),
184+
peek = stream.peek();
164185
if (ch == "}") {
165186
state.tokenize = inText;
166187
//type = ch == ")" ? "endPlugin" : "selfclosePlugin"; inPlugin
167-
return "tag";
188+
return "bracket";
168189
} else if (ch == "(" || ch == ")") {
169190
return "bracket";
170191
} else if (ch == "=") {
171192
type = "equals";
172193

173-
if (peek == ">") {
174-
ch = stream.next();
175-
peek = stream.peek();
176-
}
177-
178194
//here we detect values directly after equal character with no quotes
179-
if (!/[\'\"]/.test(peek)) {
195+
if (!isQuote.test(peek)) {
180196
state.tokenize = inAttributeNoQuote();
181197
}
182198
//end detect values
183199

184200
return "operator";
185-
} else if (/[\'\"]/.test(ch)) {
201+
} else if (isQuote.test(ch)) {
186202
state.tokenize = inAttribute(ch);
187-
return state.tokenize(stream, state);
203+
return 'quote';
188204
} else {
189-
stream.eatWhile(/[^\s\u00a0=\"\'\/?]/);
205+
stream.eatWhile(/[^\s\u00a0=\"\'`\/?]/);
190206
return "keyword";
191207
}
192208
}
193209

194210
function inAttribute(quote) {
195211
return function(stream, state) {
196-
while (!stream.eol()) {
197-
if (stream.next() == quote) {
212+
switch (stream.next()) {
213+
case quote:
198214
state.tokenize = inPlugin;
199-
break;
200-
}
215+
return 'quote';
216+
default:
217+
return 'string';
201218
}
202-
return "string";
203219
};
204220
}
205221

@@ -208,14 +224,14 @@ CodeMirror.defineMode('wikiLingo', function(config) {
208224
while (!stream.eol()) {
209225
var ch = stream.next();
210226
var peek = stream.peek();
211-
if (ch == " " || ch == "," || /[ )}]/.test(peek)) {
212-
state.tokenize = inPlugin;
213-
break;
214-
}
227+
if (ch == " " || /[ )}]/.test(peek)) {
228+
state.tokenize = inPlugin;
229+
break;
230+
}
231+
}
232+
return "string";
233+
};
215234
}
216-
return "string";
217-
};
218-
}
219235

220236
var curState, setStyle;
221237
function pass() {

0 commit comments

Comments
 (0)