1
1
CodeMirror . defineMode ( 'wikiLingo' , function ( config ) {
2
+ var activeStyles = [ ] ;
2
3
function inBlock ( style , terminator , returnTokenizer ) {
3
4
return function ( stream , state ) {
5
+ var styles ;
6
+ activeStyles . push ( style ) ;
4
7
while ( ! stream . eol ( ) ) {
5
8
if ( stream . match ( terminator ) ) {
6
9
state . tokenize = inText ;
@@ -9,19 +12,27 @@ CodeMirror.defineMode('wikiLingo', function(config) {
9
12
stream . next ( ) ;
10
13
}
11
14
12
- if ( returnTokenizer ) state . tokenize = returnTokenizer ;
15
+ if ( returnTokenizer ) {
16
+ state . tokenize = returnTokenizer ;
17
+ }
13
18
14
- return style ;
19
+ styles = activeStyles . join ( ' ' ) ;
20
+ activeStyles . pop ( ) ;
21
+ return styles ;
15
22
} ;
16
23
}
17
24
18
25
function inLine ( style ) {
19
26
return function ( stream , state ) {
27
+ var styles ;
28
+ activeStyles . push ( style ) ;
20
29
while ( ! stream . eol ( ) ) {
21
30
stream . next ( ) ;
22
31
}
23
32
state . tokenize = inText ;
24
- return style ;
33
+ styles = activeStyles . join ( ' ' ) ;
34
+ activeStyles . pop ( ) ;
35
+ return styles ;
25
36
} ;
26
37
}
27
38
@@ -37,32 +48,27 @@ CodeMirror.defineMode('wikiLingo', function(config) {
37
48
//non start of line
38
49
switch ( ch ) { //switch is generally much faster than if, so it is used here
39
50
case "{" : //plugin
40
- stream . eat ( "/" ) ;
41
- stream . eatSpace ( ) ;
42
- var tagName = "" ;
43
- var c ;
44
- while ( ( c = stream . eat ( / [ ^ \s \u00a0 = \" \' \/ ? ( } ] / ) ) ) tagName += c ;
45
51
state . tokenize = inPlugin ;
46
- return "tag " ;
52
+ return "bracket " ;
47
53
break ;
48
54
case "_" : //bold
49
55
if ( stream . eat ( "_" ) ) {
50
- return chain ( inBlock ( "strong" , "__" , inText ) ) ;
56
+ return chain ( inBlock ( "strong" , "__" ) ) ;
51
57
}
52
58
break ;
53
59
case "'" : //italics
54
60
if ( stream . eat ( "'" ) ) {
55
61
// Italic text
56
- return chain ( inBlock ( "em" , "''" , inText ) ) ;
62
+ return chain ( inBlock ( "em" , "''" ) ) ;
57
63
}
58
64
break ;
59
65
case "(" :// Wiki Link
60
66
if ( stream . eat ( "(" ) ) {
61
- return chain ( inBlock ( "variable-2" , "))" , inText ) ) ;
67
+ return chain ( inBlock ( "variable-2" , "))" ) ) ;
62
68
}
63
69
break ;
64
70
case "[" :// Weblink
65
- return chain ( inBlock ( "variable-3" , "]" , inText ) ) ;
71
+ return chain ( inBlock ( "variable-3" , "]" ) ) ;
66
72
break ;
67
73
case "|" : //table
68
74
if ( stream . eat ( "|" ) ) {
@@ -71,11 +77,11 @@ CodeMirror.defineMode('wikiLingo', function(config) {
71
77
break ;
72
78
case "-" :
73
79
if ( stream . eat ( "=" ) ) { //titleBar
74
- return chain ( inBlock ( "header string" , "=-" , inText ) ) ;
80
+ return chain ( inBlock ( "header string" , "=-" ) ) ;
75
81
}
76
82
77
83
else if ( stream . eat ( "-" ) ) { //deleted
78
- return chain ( inBlock ( "comment wl-deleted" , "--" , inText ) ) ;
84
+ return chain ( inBlock ( "comment wl-deleted" , "--" ) ) ;
79
85
}
80
86
81
87
else if ( stream . eat ( "~" ) ) { //no parse
@@ -92,12 +98,12 @@ CodeMirror.defineMode('wikiLingo', function(config) {
92
98
break ;
93
99
case "~" :
94
100
if ( stream . eat ( "~" ) ) { //color
95
- return chain ( inBlock ( "variable-3" , "~~" , inText ) ) ;
101
+ return chain ( inBlock ( "variable-3" , "~~" ) ) ;
96
102
}
97
103
break ;
98
104
case "=" : //underline
99
105
if ( stream . match ( "==" ) ) {
100
- return chain ( inBlock ( "wl-underline" , "===" , inText ) ) ;
106
+ return chain ( inBlock ( "wl-underline" , "===" ) ) ;
101
107
}
102
108
break ;
103
109
case ":" :
@@ -120,7 +126,12 @@ CodeMirror.defineMode('wikiLingo', function(config) {
120
126
break ;
121
127
case "%" ://variable
122
128
if ( stream . match ( / [ a - z A - Z ] / ) ) {
123
- return chain ( inBlock ( "variable variable-2" , "%" ) ) ;
129
+ stream . eatWhile ( / [ a - z A - Z _ \- 0 - 9 ] / ) ;
130
+ if ( stream . eat ( '%' ) ) {
131
+ return "variable variable-2" ;
132
+ } else {
133
+ return "error" ;
134
+ }
124
135
}
125
136
break ;
126
137
}
@@ -153,53 +164,58 @@ CodeMirror.defineMode('wikiLingo', function(config) {
153
164
return null ;
154
165
}
155
166
156
- var indentUnit = config . indentUnit ;
167
+ var indentUnit = config . indentUnit ,
168
+
169
+ // Return variables for tokenizers
170
+ pluginName ,
171
+ type ,
172
+ isQuote = / [ \' \" ` ] / ;
157
173
158
- // Return variables for tokenizers
159
- var pluginName , type ;
160
174
function inPlugin ( stream , state ) {
161
- var ch = stream . next ( ) ;
162
- var peek = stream . peek ( ) ;
175
+ if ( stream . eatWhile ( / [ A - Z 0 - 9 _ - ] + / ) ) {
176
+ //plugin
177
+ return 'tag'
178
+ } else if ( stream . eatWhile ( / [ a - z 0 - 9 _ - ] + / ) ) {
179
+ //inline-plugin
180
+ return 'tag'
181
+ }
163
182
183
+ var ch = stream . next ( ) ,
184
+ peek = stream . peek ( ) ;
164
185
if ( ch == "}" ) {
165
186
state . tokenize = inText ;
166
187
//type = ch == ")" ? "endPlugin" : "selfclosePlugin"; inPlugin
167
- return "tag " ;
188
+ return "bracket " ;
168
189
} else if ( ch == "(" || ch == ")" ) {
169
190
return "bracket" ;
170
191
} else if ( ch == "=" ) {
171
192
type = "equals" ;
172
193
173
- if ( peek == ">" ) {
174
- ch = stream . next ( ) ;
175
- peek = stream . peek ( ) ;
176
- }
177
-
178
194
//here we detect values directly after equal character with no quotes
179
- if ( ! / [ \' \" ] / . test ( peek ) ) {
195
+ if ( ! isQuote . test ( peek ) ) {
180
196
state . tokenize = inAttributeNoQuote ( ) ;
181
197
}
182
198
//end detect values
183
199
184
200
return "operator" ;
185
- } else if ( / [ \' \" ] / . test ( ch ) ) {
201
+ } else if ( isQuote . test ( ch ) ) {
186
202
state . tokenize = inAttribute ( ch ) ;
187
- return state . tokenize ( stream , state ) ;
203
+ return 'quote' ;
188
204
} else {
189
- stream . eatWhile ( / [ ^ \s \u00a0 = \" \' \/ ? ] / ) ;
205
+ stream . eatWhile ( / [ ^ \s \u00a0 = \" \' ` \/ ? ] / ) ;
190
206
return "keyword" ;
191
207
}
192
208
}
193
209
194
210
function inAttribute ( quote ) {
195
211
return function ( stream , state ) {
196
- while ( ! stream . eol ( ) ) {
197
- if ( stream . next ( ) == quote ) {
212
+ switch ( stream . next ( ) ) {
213
+ case quote :
198
214
state . tokenize = inPlugin ;
199
- break ;
200
- }
215
+ return 'quote' ;
216
+ default :
217
+ return 'string' ;
201
218
}
202
- return "string" ;
203
219
} ;
204
220
}
205
221
@@ -208,14 +224,14 @@ CodeMirror.defineMode('wikiLingo', function(config) {
208
224
while ( ! stream . eol ( ) ) {
209
225
var ch = stream . next ( ) ;
210
226
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
+ } ;
215
234
}
216
- return "string" ;
217
- } ;
218
- }
219
235
220
236
var curState , setStyle ;
221
237
function pass ( ) {
0 commit comments