codemirror-rails 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +40 -7
- data/lib/codemirror/rails.rb +2 -0
- data/lib/codemirror/rails/engine.rb +6 -0
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror.js +85 -45
- data/vendor/assets/javascripts/codemirror/modes/clojure.js +207 -0
- data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +42 -25
- data/vendor/assets/javascripts/codemirror/modes/css.js +3 -3
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +4 -0
- data/vendor/assets/javascripts/codemirror/modes/jinja2.js +42 -0
- data/vendor/assets/javascripts/codemirror/modes/lua.js +4 -2
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +230 -0
- data/vendor/assets/javascripts/codemirror/modes/ntriples.js +172 -0
- data/vendor/assets/javascripts/codemirror/modes/pascal.js +138 -0
- data/vendor/assets/javascripts/codemirror/modes/php.js +3 -2
- data/vendor/assets/javascripts/codemirror/modes/python.js +5 -6
- data/vendor/assets/javascripts/codemirror/modes/r.js +9 -2
- data/vendor/assets/javascripts/codemirror/modes/ruby.js +36 -23
- data/vendor/assets/javascripts/codemirror/modes/scheme.js +51 -31
- data/vendor/assets/javascripts/codemirror/modes/xml.js +4 -4
- data/vendor/assets/stylesheets/codemirror.css +1 -0
- data/vendor/assets/stylesheets/codemirror/modes/markdown.css +10 -0
- data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +17 -0
- data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +24 -0
- metadata +12 -5
@@ -11,24 +11,28 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|
11
11
|
|
12
12
|
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]");
|
13
13
|
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
14
|
-
var doubleOperators = new RegExp("^((\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))");
|
15
|
-
var doubleDelimiters = new RegExp("^((
|
14
|
+
var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))");
|
15
|
+
var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
16
16
|
var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))");
|
17
17
|
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
18
18
|
|
19
19
|
var wordOperators = wordRegexp(['and', 'or', 'not',
|
20
20
|
'is', 'isnt', 'in',
|
21
21
|
'instanceof', 'typeof']);
|
22
|
-
var
|
23
|
-
'
|
24
|
-
|
25
|
-
'
|
26
|
-
'
|
27
|
-
var keywords = wordRegexp(commonKeywords);
|
22
|
+
var indentKeywords = ['for', 'while', 'loop', 'if', 'unless', 'else',
|
23
|
+
'switch', 'try', 'catch', 'finally', 'class'];
|
24
|
+
var commonKeywords = ['break', 'by', 'continue', 'debugger', 'delete',
|
25
|
+
'do', 'in', 'of', 'new', 'return', 'then',
|
26
|
+
'this', 'throw', 'when', 'until'];
|
28
27
|
|
28
|
+
var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
indentKeywords = wordRegexp(indentKeywords);
|
31
|
+
|
32
|
+
|
33
|
+
var stringPrefixes = new RegExp("^('{3}|\"{3}|['\"])");
|
34
|
+
var regexPrefixes = new RegExp("^(/{3}|/)");
|
35
|
+
var commonConstants = ['Infinity', 'NaN', 'undefined', 'null', 'true', 'false', 'on', 'off', 'yes', 'no'];
|
32
36
|
var constants = wordRegexp(commonConstants);
|
33
37
|
|
34
38
|
// Tokenizers
|
@@ -99,9 +103,18 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|
99
103
|
|
100
104
|
// Handle strings
|
101
105
|
if (stream.match(stringPrefixes)) {
|
102
|
-
state.tokenize =
|
106
|
+
state.tokenize = tokenFactory(stream.current(), 'string');
|
103
107
|
return state.tokenize(stream, state);
|
104
108
|
}
|
109
|
+
// Handle regex literals
|
110
|
+
if (stream.match(regexPrefixes)) {
|
111
|
+
if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division
|
112
|
+
state.tokenize = tokenFactory(stream.current(), 'string-2');
|
113
|
+
return state.tokenize(stream, state);
|
114
|
+
} else {
|
115
|
+
stream.backUp(1);
|
116
|
+
}
|
117
|
+
}
|
105
118
|
|
106
119
|
// Handle operators and delimiters
|
107
120
|
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
@@ -133,37 +146,33 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|
133
146
|
return ERRORCLASS;
|
134
147
|
}
|
135
148
|
|
136
|
-
function
|
137
|
-
while ('rub'.indexOf(delimiter[0].toLowerCase()) >= 0) {
|
138
|
-
delimiter = delimiter.substr(1);
|
139
|
-
}
|
149
|
+
function tokenFactory(delimiter, outclass) {
|
140
150
|
var delim_re = new RegExp(delimiter);
|
141
151
|
var singleline = delimiter.length == 1;
|
142
|
-
var OUTCLASS = 'string';
|
143
152
|
|
144
153
|
return function tokenString(stream, state) {
|
145
154
|
while (!stream.eol()) {
|
146
|
-
stream.eatWhile(/[^'"
|
155
|
+
stream.eatWhile(/[^'"\/\\]/);
|
147
156
|
if (stream.eat('\\')) {
|
148
157
|
stream.next();
|
149
158
|
if (singleline && stream.eol()) {
|
150
|
-
return
|
159
|
+
return outclass;
|
151
160
|
}
|
152
161
|
} else if (stream.match(delim_re)) {
|
153
162
|
state.tokenize = tokenBase;
|
154
|
-
return
|
163
|
+
return outclass;
|
155
164
|
} else {
|
156
|
-
stream.eat(/['"]/);
|
165
|
+
stream.eat(/['"\/]/);
|
157
166
|
}
|
158
167
|
}
|
159
168
|
if (singleline) {
|
160
169
|
if (conf.mode.singleLineStringErrors) {
|
161
|
-
|
170
|
+
outclass = ERRORCLASS
|
162
171
|
} else {
|
163
172
|
state.tokenize = tokenBase;
|
164
173
|
}
|
165
174
|
}
|
166
|
-
return
|
175
|
+
return outclass;
|
167
176
|
};
|
168
177
|
}
|
169
178
|
|
@@ -225,7 +234,7 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|
225
234
|
}
|
226
235
|
}
|
227
236
|
|
228
|
-
// Handle
|
237
|
+
// Handle properties
|
229
238
|
if (current === '@') {
|
230
239
|
style = state.tokenize(stream, state);
|
231
240
|
current = stream.current();
|
@@ -237,10 +246,10 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|
237
246
|
}
|
238
247
|
|
239
248
|
// Handle scope changes.
|
240
|
-
if (current === '
|
249
|
+
if (current === 'return') {
|
241
250
|
state.dedent += 1;
|
242
251
|
}
|
243
|
-
if ((current === '->' &&
|
252
|
+
if (((current === '->' || current === '=>') &&
|
244
253
|
!state.lambda &&
|
245
254
|
state.scopes[0].type == 'coffee' &&
|
246
255
|
stream.peek() === '')
|
@@ -251,6 +260,14 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|
251
260
|
if (delimiter_index !== -1) {
|
252
261
|
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
253
262
|
}
|
263
|
+
if (indentKeywords.exec(current)){
|
264
|
+
indent(stream, state);
|
265
|
+
}
|
266
|
+
if (current == 'then'){
|
267
|
+
dedent(stream, state);
|
268
|
+
}
|
269
|
+
|
270
|
+
|
254
271
|
if (style === 'dedent') {
|
255
272
|
if (dedent(stream, state)) {
|
256
273
|
return ERRORCLASS;
|
@@ -4,7 +4,7 @@ CodeMirror.defineMode("css", function(config) {
|
|
4
4
|
|
5
5
|
function tokenBase(stream, state) {
|
6
6
|
var ch = stream.next();
|
7
|
-
if (ch == "@") {stream.eatWhile(
|
7
|
+
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
|
8
8
|
else if (ch == "/" && stream.eat("*")) {
|
9
9
|
state.tokenize = tokenCComment;
|
10
10
|
return tokenCComment(stream, state);
|
@@ -20,7 +20,7 @@ CodeMirror.defineMode("css", function(config) {
|
|
20
20
|
return state.tokenize(stream, state);
|
21
21
|
}
|
22
22
|
else if (ch == "#") {
|
23
|
-
stream.eatWhile(
|
23
|
+
stream.eatWhile(/[\w\\\-]/);
|
24
24
|
return ret("atom", "hash");
|
25
25
|
}
|
26
26
|
else if (ch == "!") {
|
@@ -38,7 +38,7 @@ CodeMirror.defineMode("css", function(config) {
|
|
38
38
|
return ret(null, ch);
|
39
39
|
}
|
40
40
|
else {
|
41
|
-
stream.eatWhile(/[\w\\\-
|
41
|
+
stream.eatWhile(/[\w\\\-]/);
|
42
42
|
return ret("variable", "variable");
|
43
43
|
}
|
44
44
|
}
|
@@ -75,6 +75,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
75
75
|
return ret("operator", null, stream.current());
|
76
76
|
}
|
77
77
|
}
|
78
|
+
else if (ch == "#") {
|
79
|
+
stream.skipToEnd();
|
80
|
+
return ret("error", "error");
|
81
|
+
}
|
78
82
|
else if (isOperatorChar.test(ch)) {
|
79
83
|
stream.eatWhile(isOperatorChar);
|
80
84
|
return ret("operator", null, stream.current());
|
@@ -0,0 +1,42 @@
|
|
1
|
+
CodeMirror.defineMode("jinja2", function(config, parserConf) {
|
2
|
+
var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false",
|
3
|
+
"loop", "none", "self", "super", "if", "as", "not", "and",
|
4
|
+
"else", "import", "with", "without", "context"];
|
5
|
+
keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b");
|
6
|
+
|
7
|
+
function tokenBase (stream, state) {
|
8
|
+
var ch = stream.next();
|
9
|
+
if (ch == "{") {
|
10
|
+
if (ch = stream.eat(/\{|%|#/)) {
|
11
|
+
stream.eat("-");
|
12
|
+
state.tokenize = inTag(ch);
|
13
|
+
return "tag";
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
function inTag (close) {
|
18
|
+
if (close == "{") {
|
19
|
+
close = "}";
|
20
|
+
}
|
21
|
+
return function (stream, state) {
|
22
|
+
var ch = stream.next();
|
23
|
+
if ((ch == close || (ch == "-" && stream.eat(close)))
|
24
|
+
&& stream.eat("}")) {
|
25
|
+
state.tokenize = tokenBase;
|
26
|
+
return "tag";
|
27
|
+
}
|
28
|
+
if (stream.match(keywords)) {
|
29
|
+
return "keyword";
|
30
|
+
}
|
31
|
+
return close == "#" ? "comment" : "string";
|
32
|
+
};
|
33
|
+
}
|
34
|
+
return {
|
35
|
+
startState: function () {
|
36
|
+
return {tokenize: tokenBase};
|
37
|
+
},
|
38
|
+
token: function (stream, state) {
|
39
|
+
return state.tokenize(stream, state);
|
40
|
+
}
|
41
|
+
};
|
42
|
+
});
|
@@ -123,8 +123,10 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
|
|
123
123
|
else if (builtins.test(word)) style = "builtin";
|
124
124
|
else if (specials.test(word)) style = "variable-2";
|
125
125
|
}
|
126
|
-
if (
|
127
|
-
|
126
|
+
if ((style != "lua-comment") && (style != "lua-string")){
|
127
|
+
if (indentTokens.test(word)) ++state.indentDepth;
|
128
|
+
else if (dedentTokens.test(word)) --state.indentDepth;
|
129
|
+
}
|
128
130
|
return style;
|
129
131
|
},
|
130
132
|
|
@@ -0,0 +1,230 @@
|
|
1
|
+
CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
2
|
+
|
3
|
+
var htmlMode = CodeMirror.getMode(cmCfg, { name: 'xml', htmlMode: true });
|
4
|
+
|
5
|
+
var header = 'header'
|
6
|
+
, code = 'code'
|
7
|
+
, quote = 'quote'
|
8
|
+
, list = 'list'
|
9
|
+
, hr = 'hr'
|
10
|
+
, linktext = 'linktext'
|
11
|
+
, linkhref = 'linkhref'
|
12
|
+
, em = 'em'
|
13
|
+
, strong = 'strong'
|
14
|
+
, emstrong = 'emstrong';
|
15
|
+
|
16
|
+
var hrRE = /^[*-=_]/
|
17
|
+
, ulRE = /^[*-+]\s+/
|
18
|
+
, olRE = /^[0-9]\.\s+/
|
19
|
+
, headerRE = /^(?:\={3,}|-{3,})$/
|
20
|
+
, codeRE = /^(k:\t|\s{4,})/
|
21
|
+
, textRE = /^[^\[*_\\<>`]+/;
|
22
|
+
|
23
|
+
function switchInline(stream, state, f) {
|
24
|
+
state.f = state.inline = f;
|
25
|
+
return f(stream, state);
|
26
|
+
}
|
27
|
+
|
28
|
+
function switchBlock(stream, state, f) {
|
29
|
+
state.f = state.block = f;
|
30
|
+
return f(stream, state);
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
// Blocks
|
35
|
+
|
36
|
+
function blockNormal(stream, state) {
|
37
|
+
if (stream.match(codeRE)) {
|
38
|
+
stream.skipToEnd();
|
39
|
+
return code;
|
40
|
+
}
|
41
|
+
|
42
|
+
if (stream.eatSpace()) {
|
43
|
+
return null;
|
44
|
+
}
|
45
|
+
|
46
|
+
if (stream.peek() === '#' || stream.match(headerRE)) {
|
47
|
+
stream.skipToEnd();
|
48
|
+
return header;
|
49
|
+
}
|
50
|
+
if (stream.eat('>')) {
|
51
|
+
state.indentation++;
|
52
|
+
return quote;
|
53
|
+
}
|
54
|
+
if (stream.peek() === '<') {
|
55
|
+
return switchBlock(stream, state, htmlBlock);
|
56
|
+
}
|
57
|
+
if (stream.peek() === '[') {
|
58
|
+
return switchInline(stream, state, footnoteLink);
|
59
|
+
}
|
60
|
+
if (hrRE.test(stream.peek())) {
|
61
|
+
var re = new RegExp('(?:\s*['+stream.peek()+']){3,}$');
|
62
|
+
if (stream.match(re, true)) {
|
63
|
+
return hr;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
var match;
|
68
|
+
if (match = stream.match(ulRE, true) || stream.match(olRE, true)) {
|
69
|
+
state.indentation += match[0].length;
|
70
|
+
return list;
|
71
|
+
}
|
72
|
+
|
73
|
+
return switchInline(stream, state, state.inline);
|
74
|
+
}
|
75
|
+
|
76
|
+
function htmlBlock(stream, state) {
|
77
|
+
var type = htmlMode.token(stream, state.htmlState);
|
78
|
+
if (stream.eol() && !state.htmlState.context) {
|
79
|
+
state.block = blockNormal;
|
80
|
+
}
|
81
|
+
return type;
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
// Inline
|
86
|
+
|
87
|
+
function inlineNormal(stream, state) {
|
88
|
+
function getType() {
|
89
|
+
return state.strong ? (state.em ? emstrong : strong)
|
90
|
+
: (state.em ? em : null);
|
91
|
+
}
|
92
|
+
|
93
|
+
if (stream.match(textRE, true)) {
|
94
|
+
return getType();
|
95
|
+
}
|
96
|
+
|
97
|
+
var ch = stream.next();
|
98
|
+
|
99
|
+
if (ch === '\\') {
|
100
|
+
stream.next();
|
101
|
+
return getType();
|
102
|
+
}
|
103
|
+
if (ch === '`') {
|
104
|
+
return switchInline(stream, state, inlineElement(code, '`'));
|
105
|
+
}
|
106
|
+
if (ch === '<') {
|
107
|
+
return switchInline(stream, state, inlineElement(linktext, '>'));
|
108
|
+
}
|
109
|
+
if (ch === '[') {
|
110
|
+
return switchInline(stream, state, linkText);
|
111
|
+
}
|
112
|
+
|
113
|
+
var t = getType();
|
114
|
+
if (ch === '*' || ch === '_') {
|
115
|
+
if (stream.eat(ch)) {
|
116
|
+
return (state.strong = !state.strong) ? getType() : t;
|
117
|
+
}
|
118
|
+
return (state.em = !state.em) ? getType() : t;
|
119
|
+
}
|
120
|
+
|
121
|
+
return getType();
|
122
|
+
}
|
123
|
+
|
124
|
+
function linkText(stream, state) {
|
125
|
+
while (!stream.eol()) {
|
126
|
+
var ch = stream.next();
|
127
|
+
if (ch === '\\') stream.next();
|
128
|
+
if (ch === ']') {
|
129
|
+
state.inline = state.f = linkHref;
|
130
|
+
return linktext;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
return linktext;
|
134
|
+
}
|
135
|
+
|
136
|
+
function linkHref(stream, state) {
|
137
|
+
stream.eatSpace();
|
138
|
+
var ch = stream.next();
|
139
|
+
if (ch === '(' || ch === '[') {
|
140
|
+
return switchInline(stream, state, inlineElement(linkhref, ch === '(' ? ')' : ']'));
|
141
|
+
}
|
142
|
+
return 'error';
|
143
|
+
}
|
144
|
+
|
145
|
+
function footnoteLink(stream, state) {
|
146
|
+
if (stream.match(/^[^\]]*\]:/, true)) {
|
147
|
+
state.f = footnoteUrl;
|
148
|
+
return linktext;
|
149
|
+
}
|
150
|
+
return switchInline(stream, state, inlineNormal);
|
151
|
+
}
|
152
|
+
|
153
|
+
function footnoteUrl(stream, state) {
|
154
|
+
stream.eatSpace();
|
155
|
+
stream.match(/^[^\s]+/, true);
|
156
|
+
state.f = state.inline = inlineNormal;
|
157
|
+
return linkhref;
|
158
|
+
}
|
159
|
+
|
160
|
+
function inlineElement(type, endChar, next) {
|
161
|
+
next = next || inlineNormal;
|
162
|
+
return function(stream, state) {
|
163
|
+
while (!stream.eol()) {
|
164
|
+
var ch = stream.next();
|
165
|
+
if (ch === '\\') stream.next();
|
166
|
+
if (ch === endChar) {
|
167
|
+
state.inline = state.f = next;
|
168
|
+
return type;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
return type;
|
172
|
+
};
|
173
|
+
}
|
174
|
+
|
175
|
+
return {
|
176
|
+
startState: function() {
|
177
|
+
return {
|
178
|
+
f: blockNormal,
|
179
|
+
|
180
|
+
block: blockNormal,
|
181
|
+
htmlState: htmlMode.startState(),
|
182
|
+
indentation: 0,
|
183
|
+
|
184
|
+
inline: inlineNormal,
|
185
|
+
em: false,
|
186
|
+
strong: false
|
187
|
+
};
|
188
|
+
},
|
189
|
+
|
190
|
+
copyState: function(s) {
|
191
|
+
return {
|
192
|
+
f: s.f,
|
193
|
+
|
194
|
+
block: s.block,
|
195
|
+
htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
|
196
|
+
indentation: s.indentation,
|
197
|
+
|
198
|
+
inline: s.inline,
|
199
|
+
em: s.em,
|
200
|
+
strong: s.strong
|
201
|
+
};
|
202
|
+
},
|
203
|
+
|
204
|
+
token: function(stream, state) {
|
205
|
+
if (stream.sol()) {
|
206
|
+
state.f = state.block;
|
207
|
+
var previousIndentation = state.indentation
|
208
|
+
, currentIndentation = 0;
|
209
|
+
while (previousIndentation > 0) {
|
210
|
+
if (stream.eat(' ')) {
|
211
|
+
previousIndentation--;
|
212
|
+
currentIndentation++;
|
213
|
+
} else if (previousIndentation >= 4 && stream.eat('\t')) {
|
214
|
+
previousIndentation -= 4;
|
215
|
+
currentIndentation += 4;
|
216
|
+
} else {
|
217
|
+
break;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
state.indentation = currentIndentation;
|
221
|
+
|
222
|
+
if (currentIndentation > 0) return null;
|
223
|
+
}
|
224
|
+
return state.f(stream, state);
|
225
|
+
}
|
226
|
+
};
|
227
|
+
|
228
|
+
});
|
229
|
+
|
230
|
+
CodeMirror.defineMIME("text/x-markdown", "markdown");
|