codemirror-rails 3.02 → 3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/codemirror-rails.gemspec +1 -0
- data/doc/CodeMirror-LICENSE +5 -1
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror/{utils → addons/dialog}/dialog.js +4 -0
- data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +54 -0
- data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +54 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/closetag.js +9 -8
- data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/continuecomment.js +12 -4
- data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/matchbrackets.js +30 -11
- data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +31 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +32 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +11 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +64 -0
- data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +582 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/javascript-hint.js +15 -11
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/pig-hint.js +19 -19
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/python-hint.js +2 -2
- data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +180 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/xml-hint.js +5 -18
- data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +127 -0
- data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +14 -0
- data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +197 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/loadmode.js +0 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/multiplex.js +2 -2
- data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/overlay.js +2 -2
- data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/colorize.js +0 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode-standalone.js +2 -3
- data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode.js +0 -0
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +89 -0
- data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +60 -0
- data/vendor/assets/javascripts/codemirror/{utils → addons/search}/search.js +5 -5
- data/vendor/assets/javascripts/codemirror/{utils → addons/search}/searchcursor.js +37 -30
- data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +39 -0
- data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +34 -0
- data/vendor/assets/javascripts/codemirror/keymaps/vim.js +721 -188
- data/vendor/assets/javascripts/codemirror/modes/asterisk.js +6 -6
- data/vendor/assets/javascripts/codemirror/modes/clike.js +14 -14
- data/vendor/assets/javascripts/codemirror/modes/clojure.js +23 -7
- data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/css.js +337 -235
- data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -12
- data/vendor/assets/javascripts/codemirror/modes/erlang.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/gas.js +326 -0
- data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -0
- data/vendor/assets/javascripts/codemirror/modes/haskell.js +26 -26
- data/vendor/assets/javascripts/codemirror/modes/haxe.js +17 -17
- data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +6 -6
- data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +43 -23
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +78 -33
- data/vendor/assets/javascripts/codemirror/modes/jinja2.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/less.js +38 -38
- data/vendor/assets/javascripts/codemirror/modes/livescript.js +267 -0
- data/vendor/assets/javascripts/codemirror/modes/lua.js +7 -7
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +108 -57
- data/vendor/assets/javascripts/codemirror/modes/mirc.js +177 -0
- data/vendor/assets/javascripts/codemirror/modes/ntriples.js +22 -22
- data/vendor/assets/javascripts/codemirror/modes/ocaml.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/perl.js +791 -791
- data/vendor/assets/javascripts/codemirror/modes/php.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/pig.js +163 -163
- data/vendor/assets/javascripts/codemirror/modes/python.js +31 -31
- data/vendor/assets/javascripts/codemirror/modes/q.js +124 -0
- data/vendor/assets/javascripts/codemirror/modes/rst.js +486 -250
- data/vendor/assets/javascripts/codemirror/modes/sass.js +3 -3
- data/vendor/assets/javascripts/codemirror/modes/scss_test.js +80 -0
- data/vendor/assets/javascripts/codemirror/modes/shell.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/sieve.js +10 -10
- data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +129 -129
- data/vendor/assets/javascripts/codemirror/modes/smarty.js +3 -3
- data/vendor/assets/javascripts/codemirror/modes/sparql.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/sql.js +23 -23
- data/vendor/assets/javascripts/codemirror/modes/stex.js +192 -121
- data/vendor/assets/javascripts/codemirror/modes/tcl.js +131 -0
- data/vendor/assets/javascripts/codemirror/modes/test.js +64 -0
- data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +345 -345
- data/vendor/assets/javascripts/codemirror/modes/tiki.js +297 -298
- data/vendor/assets/javascripts/codemirror/modes/turtle.js +145 -0
- data/vendor/assets/javascripts/codemirror/modes/vb.js +31 -32
- data/vendor/assets/javascripts/codemirror/modes/vbscript.js +4 -4
- data/vendor/assets/javascripts/codemirror/modes/xml.js +10 -6
- data/vendor/assets/javascripts/codemirror/modes/xquery.js +55 -55
- data/vendor/assets/javascripts/codemirror/modes/yaml.js +90 -90
- data/vendor/assets/javascripts/codemirror/modes/z80.js +82 -110
- data/vendor/assets/javascripts/codemirror.js +1914 -1115
- data/vendor/assets/stylesheets/codemirror/{utils → addons/dialog}/dialog.css +0 -0
- data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +38 -0
- data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +96 -0
- data/vendor/assets/stylesheets/codemirror/modes/tiki.css +2 -2
- data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +0 -1
- data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +0 -1
- data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +2 -2
- data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +5 -5
- data/vendor/assets/stylesheets/codemirror/themes/midnight.css +52 -0
- data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
- data/vendor/assets/stylesheets/codemirror.css +16 -10
- metadata +60 -52
- data/vendor/assets/javascripts/codemirror/modes/mysql.js +0 -203
- data/vendor/assets/javascripts/codemirror/modes/plsql.js +0 -216
- data/vendor/assets/javascripts/codemirror/utils/collapserange.js +0 -68
- data/vendor/assets/javascripts/codemirror/utils/continuelist.js +0 -28
- data/vendor/assets/javascripts/codemirror/utils/foldcode.js +0 -183
- data/vendor/assets/javascripts/codemirror/utils/formatting.js +0 -114
- data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +0 -46
- data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +0 -102
- data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +0 -16
@@ -1,314 +1,550 @@
|
|
1
|
-
CodeMirror.defineMode('rst', function(config
|
2
|
-
function setState(state, fn, ctx) {
|
3
|
-
state.fn = fn;
|
4
|
-
setCtx(state, ctx);
|
5
|
-
}
|
6
|
-
|
7
|
-
function setCtx(state, ctx) {
|
8
|
-
state.ctx = ctx || {};
|
9
|
-
}
|
1
|
+
CodeMirror.defineMode('rst-base', function (config) {
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
var str = ch.current();
|
14
|
-
ch = str[str.length-1];
|
15
|
-
}
|
3
|
+
///////////////////////////////////////////////////////////////////////////
|
4
|
+
///////////////////////////////////////////////////////////////////////////
|
16
5
|
|
17
|
-
|
6
|
+
function format(string) {
|
7
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
8
|
+
return string.replace(/{(\d+)}/g, function (match, n) {
|
9
|
+
return typeof args[n] != 'undefined' ? args[n] : match;
|
10
|
+
});
|
18
11
|
}
|
19
12
|
|
20
|
-
function
|
21
|
-
|
13
|
+
function AssertException(message) {
|
14
|
+
this.message = message;
|
22
15
|
}
|
23
16
|
|
24
|
-
function
|
25
|
-
|
26
|
-
|
27
|
-
} else {
|
28
|
-
return null;
|
29
|
-
}
|
30
|
-
}
|
17
|
+
AssertException.prototype.toString = function () {
|
18
|
+
return 'AssertException: ' + this.message;
|
19
|
+
};
|
31
20
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
var reDirective = /^\s*\w([-:.\w]*\w)?::(\s|$)/;
|
37
|
-
var reHyperlink = /^\s*_[\w-]+:(\s|$)/;
|
38
|
-
var reFootnote = /^\s*\[(\d+|#)\](\s|$)/;
|
39
|
-
var reCitation = /^\s*\[[A-Za-z][\w-]*\](\s|$)/;
|
40
|
-
var reFootnoteRef = /^\[(\d+|#)\]_/;
|
41
|
-
var reCitationRef = /^\[[A-Za-z][\w-]*\]_/;
|
42
|
-
var reDirectiveMarker = /^\.\.(\s|$)/;
|
43
|
-
var reVerbatimMarker = /^::\s*$/;
|
44
|
-
var rePreInline = /^[-\s"([{</:]/;
|
45
|
-
var rePostInline = /^[-\s`'")\]}>/:.,;!?\\_]/;
|
46
|
-
var reExamples = /^\s+(>>>|In \[\d+\]:)\s/;
|
47
|
-
|
48
|
-
function normal(stream, state) {
|
49
|
-
var ch, sol, i;
|
50
|
-
|
51
|
-
if (stream.eat(/\\/)) {
|
52
|
-
ch = stream.next();
|
53
|
-
setNormal(state, ch);
|
54
|
-
return null;
|
55
|
-
}
|
21
|
+
function assert(expression, message) {
|
22
|
+
if (!expression) throw new AssertException(message);
|
23
|
+
return expression;
|
24
|
+
}
|
56
25
|
|
57
|
-
|
26
|
+
///////////////////////////////////////////////////////////////////////////
|
27
|
+
///////////////////////////////////////////////////////////////////////////
|
28
|
+
|
29
|
+
var mode_python = CodeMirror.getMode(config, 'python');
|
30
|
+
var mode_stex = CodeMirror.getMode(config, 'stex');
|
31
|
+
|
32
|
+
///////////////////////////////////////////////////////////////////////////
|
33
|
+
///////////////////////////////////////////////////////////////////////////
|
34
|
+
|
35
|
+
var SEPA = "\\s+";
|
36
|
+
var TAIL = "(?:\\s*|\\W|$)",
|
37
|
+
rx_TAIL = new RegExp(format('^{0}', TAIL));
|
38
|
+
|
39
|
+
var NAME = "(?:[^\\W\\d_](?:[\\w\\+\\.\\-:]*[^\\W_])?)",
|
40
|
+
rx_NAME = new RegExp(format('^{0}', NAME));
|
41
|
+
var NAME_WWS = "(?:[^\\W\\d_](?:[\\w\\s\\+\\.\\-:]*[^\\W_])?)";
|
42
|
+
var REF_NAME = format('(?:{0}|`{1}`)', NAME, NAME_WWS);
|
43
|
+
|
44
|
+
var TEXT1 = "(?:[^\\s\\|](?:[^\\|]*[^\\s\\|])?)";
|
45
|
+
var TEXT2 = "(?:[^\\`]+)",
|
46
|
+
rx_TEXT2 = new RegExp(format('^{0}', TEXT2));
|
47
|
+
|
48
|
+
var rx_section = new RegExp(
|
49
|
+
"^([!'#$%&\"()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~])\\1{3,}\\s*$");
|
50
|
+
var rx_explicit = new RegExp(
|
51
|
+
format('^\\.\\.{0}', SEPA));
|
52
|
+
var rx_link = new RegExp(
|
53
|
+
format('^_{0}:{1}|^__:{1}', REF_NAME, TAIL));
|
54
|
+
var rx_directive = new RegExp(
|
55
|
+
format('^{0}::{1}', REF_NAME, TAIL));
|
56
|
+
var rx_substitution = new RegExp(
|
57
|
+
format('^\\|{0}\\|{1}{2}::{3}', TEXT1, SEPA, REF_NAME, TAIL));
|
58
|
+
var rx_footnote = new RegExp(
|
59
|
+
format('^\\[(?:\\d+|#{0}?|\\*)]{1}', REF_NAME, TAIL));
|
60
|
+
var rx_citation = new RegExp(
|
61
|
+
format('^\\[{0}\\]{1}', REF_NAME, TAIL));
|
62
|
+
|
63
|
+
var rx_substitution_ref = new RegExp(
|
64
|
+
format('^\\|{0}\\|', TEXT1));
|
65
|
+
var rx_footnote_ref = new RegExp(
|
66
|
+
format('^\\[(?:\\d+|#{0}?|\\*)]_', REF_NAME));
|
67
|
+
var rx_citation_ref = new RegExp(
|
68
|
+
format('^\\[{0}\\]_', REF_NAME));
|
69
|
+
var rx_link_ref1 = new RegExp(
|
70
|
+
format('^{0}__?', REF_NAME));
|
71
|
+
var rx_link_ref2 = new RegExp(
|
72
|
+
format('^`{0}`_', TEXT2));
|
73
|
+
|
74
|
+
var rx_role_pre = new RegExp(
|
75
|
+
format('^:{0}:`{1}`{2}', NAME, TEXT2, TAIL));
|
76
|
+
var rx_role_suf = new RegExp(
|
77
|
+
format('^`{1}`:{0}:{2}', NAME, TEXT2, TAIL));
|
78
|
+
var rx_role = new RegExp(
|
79
|
+
format('^:{0}:{1}', NAME, TAIL));
|
80
|
+
|
81
|
+
var rx_directive_name = new RegExp(format('^{0}', REF_NAME));
|
82
|
+
var rx_directive_tail = new RegExp(format('^::{0}', TAIL));
|
83
|
+
var rx_substitution_text = new RegExp(format('^\\|{0}\\|', TEXT1));
|
84
|
+
var rx_substitution_sepa = new RegExp(format('^{0}', SEPA));
|
85
|
+
var rx_substitution_name = new RegExp(format('^{0}', REF_NAME));
|
86
|
+
var rx_substitution_tail = new RegExp(format('^::{0}', TAIL));
|
87
|
+
var rx_link_head = new RegExp("^_");
|
88
|
+
var rx_link_name = new RegExp(format('^{0}|_', REF_NAME));
|
89
|
+
var rx_link_tail = new RegExp(format('^:{0}', TAIL));
|
90
|
+
|
91
|
+
var rx_verbatim = new RegExp('^::\\s*$');
|
92
|
+
var rx_examples = new RegExp('^\\s+(?:>>>|In \\[\\d+\\]:)\\s');
|
93
|
+
|
94
|
+
///////////////////////////////////////////////////////////////////////////
|
95
|
+
///////////////////////////////////////////////////////////////////////////
|
96
|
+
|
97
|
+
function to_normal(stream, state) {
|
98
|
+
var token = null;
|
58
99
|
|
59
|
-
if (sol &&
|
60
|
-
|
100
|
+
if (stream.sol() && stream.match(rx_examples, false)) {
|
101
|
+
change(state, to_mode, {
|
102
|
+
mode: mode_python, local: mode_python.startState()
|
103
|
+
});
|
104
|
+
} else if (stream.sol() && stream.match(rx_explicit)) {
|
105
|
+
change(state, to_explicit);
|
106
|
+
token = 'meta';
|
107
|
+
} else if (stream.sol() && stream.match(rx_section)) {
|
108
|
+
change(state, to_normal);
|
109
|
+
token = 'header';
|
110
|
+
} else if (phase(state) == rx_role_pre ||
|
111
|
+
stream.match(rx_role_pre, false)) {
|
112
|
+
|
113
|
+
switch (stage(state)) {
|
114
|
+
case 0:
|
115
|
+
change(state, to_normal, context(rx_role_pre, 1));
|
116
|
+
assert(stream.match(/^:/));
|
117
|
+
token = 'meta';
|
118
|
+
break;
|
119
|
+
case 1:
|
120
|
+
change(state, to_normal, context(rx_role_pre, 2));
|
121
|
+
assert(stream.match(rx_NAME));
|
122
|
+
token = 'keyword';
|
123
|
+
|
124
|
+
if (stream.current().match(/^(?:math|latex)/)) {
|
125
|
+
state.tmp = {
|
126
|
+
mode: mode_stex, local: mode_stex.startState()
|
127
|
+
};
|
128
|
+
}
|
129
|
+
break;
|
130
|
+
case 2:
|
131
|
+
change(state, to_normal, context(rx_role_pre, 3));
|
132
|
+
assert(stream.match(/^:`/));
|
133
|
+
token = 'meta';
|
134
|
+
break;
|
135
|
+
case 3:
|
136
|
+
if (state.tmp) {
|
137
|
+
if (stream.peek() == '`') {
|
138
|
+
change(state, to_normal, context(rx_role_pre, 4));
|
139
|
+
state.tmp = undefined;
|
140
|
+
break;
|
141
|
+
}
|
142
|
+
|
143
|
+
token = state.tmp.mode.token(stream, state.tmp.local);
|
144
|
+
break;
|
145
|
+
}
|
61
146
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
147
|
+
change(state, to_normal, context(rx_role_pre, 4));
|
148
|
+
assert(stream.match(rx_TEXT2));
|
149
|
+
token = 'string';
|
150
|
+
break;
|
151
|
+
case 4:
|
152
|
+
change(state, to_normal, context(rx_role_pre, 5));
|
153
|
+
assert(stream.match(/^`/));
|
154
|
+
token = 'meta';
|
155
|
+
break;
|
156
|
+
case 5:
|
157
|
+
change(state, to_normal, context(rx_role_pre, 6));
|
158
|
+
assert(stream.match(rx_TAIL));
|
159
|
+
break;
|
160
|
+
default:
|
161
|
+
change(state, to_normal);
|
162
|
+
assert(stream.current() == '');
|
67
163
|
}
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
164
|
+
} else if (phase(state) == rx_role_suf ||
|
165
|
+
stream.match(rx_role_suf, false)) {
|
166
|
+
|
167
|
+
switch (stage(state)) {
|
168
|
+
case 0:
|
169
|
+
change(state, to_normal, context(rx_role_suf, 1));
|
170
|
+
assert(stream.match(/^`/));
|
171
|
+
token = 'meta';
|
172
|
+
break;
|
173
|
+
case 1:
|
174
|
+
change(state, to_normal, context(rx_role_suf, 2));
|
175
|
+
assert(stream.match(rx_TEXT2));
|
176
|
+
token = 'string';
|
177
|
+
break;
|
178
|
+
case 2:
|
179
|
+
change(state, to_normal, context(rx_role_suf, 3));
|
180
|
+
assert(stream.match(/^`:/));
|
181
|
+
token = 'meta';
|
182
|
+
break;
|
183
|
+
case 3:
|
184
|
+
change(state, to_normal, context(rx_role_suf, 4));
|
185
|
+
assert(stream.match(rx_NAME));
|
186
|
+
token = 'keyword';
|
187
|
+
break;
|
188
|
+
case 4:
|
189
|
+
change(state, to_normal, context(rx_role_suf, 5));
|
190
|
+
assert(stream.match(/^:/));
|
191
|
+
token = 'meta';
|
192
|
+
break;
|
193
|
+
case 5:
|
194
|
+
change(state, to_normal, context(rx_role_suf, 6));
|
195
|
+
assert(stream.match(rx_TAIL));
|
196
|
+
break;
|
197
|
+
default:
|
198
|
+
change(state, to_normal);
|
199
|
+
assert(stream.current() == '');
|
73
200
|
}
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
201
|
+
} else if (phase(state) == rx_role || stream.match(rx_role, false)) {
|
202
|
+
|
203
|
+
switch (stage(state)) {
|
204
|
+
case 0:
|
205
|
+
change(state, to_normal, context(rx_role, 1));
|
206
|
+
assert(stream.match(/^:/));
|
207
|
+
token = 'meta';
|
208
|
+
break;
|
209
|
+
case 1:
|
210
|
+
change(state, to_normal, context(rx_role, 2));
|
211
|
+
assert(stream.match(rx_NAME));
|
212
|
+
token = 'keyword';
|
213
|
+
break;
|
214
|
+
case 2:
|
215
|
+
change(state, to_normal, context(rx_role, 3));
|
216
|
+
assert(stream.match(/^:/));
|
217
|
+
token = 'meta';
|
218
|
+
break;
|
219
|
+
case 3:
|
220
|
+
change(state, to_normal, context(rx_role, 4));
|
221
|
+
assert(stream.match(rx_TAIL));
|
222
|
+
break;
|
223
|
+
default:
|
224
|
+
change(state, to_normal);
|
225
|
+
assert(stream.current() == '');
|
87
226
|
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
227
|
+
} else if (phase(state) == rx_substitution_ref ||
|
228
|
+
stream.match(rx_substitution_ref, false)) {
|
229
|
+
|
230
|
+
switch (stage(state)) {
|
231
|
+
case 0:
|
232
|
+
change(state, to_normal, context(rx_substitution_ref, 1));
|
233
|
+
assert(stream.match(rx_substitution_text));
|
234
|
+
token = 'variable-2';
|
235
|
+
break;
|
236
|
+
case 1:
|
237
|
+
change(state, to_normal, context(rx_substitution_ref, 2));
|
238
|
+
if (stream.match(/^_?_?/)) token = 'link';
|
239
|
+
break;
|
240
|
+
default:
|
241
|
+
change(state, to_normal);
|
242
|
+
assert(stream.current() == '');
|
104
243
|
}
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
function testInline(re) {
|
116
|
-
return stream.match(re) && testBackward(/\W/) && testForward(/\W/);
|
117
|
-
}
|
118
|
-
|
119
|
-
if (testInline(reFootnoteRef)) {
|
120
|
-
setNormal(state, stream);
|
121
|
-
return 'footnote';
|
122
|
-
}
|
123
|
-
|
124
|
-
if (testInline(reCitationRef)) {
|
125
|
-
setNormal(state, stream);
|
126
|
-
return 'citation';
|
127
|
-
}
|
128
|
-
|
129
|
-
ch = stream.next();
|
130
|
-
|
131
|
-
if (testBackward(rePreInline)) {
|
132
|
-
if ((ch === ':' || ch === '|') && stream.eat(/\S/)) {
|
133
|
-
var token;
|
134
|
-
|
135
|
-
if (ch === ':') {
|
136
|
-
token = 'builtin';
|
137
|
-
} else {
|
138
|
-
token = 'atom';
|
139
|
-
}
|
140
|
-
|
141
|
-
setState(state, inline, {
|
142
|
-
ch: ch,
|
143
|
-
wide: false,
|
144
|
-
prev: null,
|
145
|
-
token: token
|
146
|
-
});
|
147
|
-
|
148
|
-
return token;
|
244
|
+
} else if (stream.match(rx_footnote_ref)) {
|
245
|
+
change(state, to_normal);
|
246
|
+
token = 'quote';
|
247
|
+
} else if (stream.match(rx_citation_ref)) {
|
248
|
+
change(state, to_normal);
|
249
|
+
token = 'quote';
|
250
|
+
} else if (stream.match(rx_link_ref1)) {
|
251
|
+
change(state, to_normal);
|
252
|
+
if (!stream.peek() || stream.peek().match(/^\W$/)) {
|
253
|
+
token = 'link';
|
149
254
|
}
|
255
|
+
} else if (phase(state) == rx_link_ref2 ||
|
256
|
+
stream.match(rx_link_ref2, false)) {
|
150
257
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
ch = stream.next();
|
156
|
-
|
157
|
-
if (ch == orig) {
|
158
|
-
wide = true;
|
159
|
-
ch = stream.next();
|
160
|
-
}
|
161
|
-
|
162
|
-
if (ch && !/\s/.test(ch)) {
|
163
|
-
var token;
|
164
|
-
|
165
|
-
if (orig === '*') {
|
166
|
-
token = wide ? 'strong' : 'em';
|
258
|
+
switch (stage(state)) {
|
259
|
+
case 0:
|
260
|
+
if (!stream.peek() || stream.peek().match(/^\W$/)) {
|
261
|
+
change(state, to_normal, context(rx_link_ref2, 1));
|
167
262
|
} else {
|
168
|
-
|
263
|
+
stream.match(rx_link_ref2);
|
169
264
|
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
265
|
+
break;
|
266
|
+
case 1:
|
267
|
+
change(state, to_normal, context(rx_link_ref2, 2));
|
268
|
+
assert(stream.match(/^`/));
|
269
|
+
token = 'link';
|
270
|
+
break;
|
271
|
+
case 2:
|
272
|
+
change(state, to_normal, context(rx_link_ref2, 3));
|
273
|
+
assert(stream.match(rx_TEXT2));
|
274
|
+
break;
|
275
|
+
case 3:
|
276
|
+
change(state, to_normal, context(rx_link_ref2, 4));
|
277
|
+
assert(stream.match(/^`_/));
|
278
|
+
token = 'link';
|
279
|
+
break;
|
280
|
+
default:
|
281
|
+
change(state, to_normal);
|
282
|
+
assert(stream.current() == '');
|
180
283
|
}
|
284
|
+
} else if (stream.match(rx_verbatim)) {
|
285
|
+
change(state, to_verbatim);
|
181
286
|
}
|
182
287
|
|
183
|
-
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
function inline(stream, state) {
|
188
|
-
var ch = stream.next(),
|
189
|
-
token = state.ctx.token;
|
190
|
-
|
191
|
-
function finish(ch) {
|
192
|
-
state.ctx.prev = ch;
|
193
|
-
return token;
|
288
|
+
else {
|
289
|
+
if (stream.next()) change(state, to_normal);
|
194
290
|
}
|
195
291
|
|
196
|
-
|
197
|
-
|
198
|
-
}
|
292
|
+
return token;
|
293
|
+
}
|
199
294
|
|
200
|
-
|
201
|
-
|
202
|
-
}
|
295
|
+
///////////////////////////////////////////////////////////////////////////
|
296
|
+
///////////////////////////////////////////////////////////////////////////
|
203
297
|
|
204
|
-
|
205
|
-
|
298
|
+
function to_explicit(stream, state) {
|
299
|
+
var token = null;
|
206
300
|
|
207
|
-
|
208
|
-
|
301
|
+
if (phase(state) == rx_substitution ||
|
302
|
+
stream.match(rx_substitution, false)) {
|
303
|
+
|
304
|
+
switch (stage(state)) {
|
305
|
+
case 0:
|
306
|
+
change(state, to_explicit, context(rx_substitution, 1));
|
307
|
+
assert(stream.match(rx_substitution_text));
|
308
|
+
token = 'variable-2';
|
309
|
+
break;
|
310
|
+
case 1:
|
311
|
+
change(state, to_explicit, context(rx_substitution, 2));
|
312
|
+
assert(stream.match(rx_substitution_sepa));
|
313
|
+
break;
|
314
|
+
case 2:
|
315
|
+
change(state, to_explicit, context(rx_substitution, 3));
|
316
|
+
assert(stream.match(rx_substitution_name));
|
317
|
+
token = 'keyword';
|
318
|
+
break;
|
319
|
+
case 3:
|
320
|
+
change(state, to_explicit, context(rx_substitution, 4));
|
321
|
+
assert(stream.match(rx_substitution_tail));
|
322
|
+
token = 'meta';
|
323
|
+
break;
|
324
|
+
default:
|
325
|
+
change(state, to_normal);
|
326
|
+
assert(stream.current() == '');
|
209
327
|
}
|
210
|
-
}
|
328
|
+
} else if (phase(state) == rx_directive ||
|
329
|
+
stream.match(rx_directive, false)) {
|
330
|
+
|
331
|
+
switch (stage(state)) {
|
332
|
+
case 0:
|
333
|
+
change(state, to_explicit, context(rx_directive, 1));
|
334
|
+
assert(stream.match(rx_directive_name));
|
335
|
+
token = 'keyword';
|
336
|
+
|
337
|
+
if (stream.current().match(/^(?:math|latex)/))
|
338
|
+
state.tmp_stex = true;
|
339
|
+
else if (stream.current().match(/^python/))
|
340
|
+
state.tmp_py = true;
|
341
|
+
break;
|
342
|
+
case 1:
|
343
|
+
change(state, to_explicit, context(rx_directive, 2));
|
344
|
+
assert(stream.match(rx_directive_tail));
|
345
|
+
token = 'meta';
|
346
|
+
break;
|
347
|
+
default:
|
348
|
+
if (stream.match(/^latex\s*$/) || state.tmp_stex) {
|
349
|
+
state.tmp_stex = undefined;
|
350
|
+
change(state, to_mode, {
|
351
|
+
mode: mode_stex, local: mode_stex.startState()
|
352
|
+
});
|
353
|
+
} else if (stream.match(/^python\s*$/) || state.tmp_py) {
|
354
|
+
state.tmp_py = undefined;
|
355
|
+
change(state, to_mode, {
|
356
|
+
mode: mode_python, local: mode_python.startState()
|
357
|
+
});
|
358
|
+
}
|
211
359
|
|
212
|
-
|
213
|
-
|
214
|
-
|
360
|
+
else {
|
361
|
+
change(state, to_normal);
|
362
|
+
assert(stream.current() == '');
|
363
|
+
}
|
215
364
|
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
365
|
+
} else if (phase(state) == rx_link || stream.match(rx_link, false)) {
|
366
|
+
|
367
|
+
switch (stage(state)) {
|
368
|
+
case 0:
|
369
|
+
change(state, to_explicit, context(rx_link, 1));
|
370
|
+
assert(stream.match(rx_link_head));
|
371
|
+
assert(stream.match(rx_link_name));
|
372
|
+
token = 'link';
|
373
|
+
break;
|
374
|
+
case 1:
|
375
|
+
change(state, to_explicit, context(rx_link, 2));
|
376
|
+
assert(stream.match(rx_link_tail));
|
377
|
+
token = 'meta';
|
378
|
+
break;
|
379
|
+
default:
|
380
|
+
change(state, to_normal);
|
381
|
+
assert(stream.current() == '');
|
382
|
+
}
|
383
|
+
} else if (stream.match(rx_footnote)) {
|
384
|
+
change(state, to_normal);
|
234
385
|
token = 'quote';
|
235
|
-
} else if (stream.match(
|
386
|
+
} else if (stream.match(rx_citation)) {
|
387
|
+
change(state, to_normal);
|
236
388
|
token = 'quote';
|
237
|
-
}
|
238
|
-
stream.eatSpace();
|
389
|
+
}
|
239
390
|
|
391
|
+
else {
|
392
|
+
stream.eatSpace();
|
240
393
|
if (stream.eol()) {
|
241
|
-
|
242
|
-
return null;
|
394
|
+
change(state, to_normal);
|
243
395
|
} else {
|
244
396
|
stream.skipToEnd();
|
245
|
-
|
246
|
-
|
397
|
+
change(state, to_comment);
|
398
|
+
token = 'comment';
|
247
399
|
}
|
248
400
|
}
|
249
401
|
|
250
|
-
// FIXME this is unreachable
|
251
|
-
setState(state, body, {start: true});
|
252
402
|
return token;
|
253
403
|
}
|
254
404
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
if (!state.ctx.start || stream.sol()) {
|
259
|
-
return block(stream, state, token);
|
260
|
-
}
|
261
|
-
|
262
|
-
stream.skipToEnd();
|
263
|
-
setCtx(state);
|
405
|
+
///////////////////////////////////////////////////////////////////////////
|
406
|
+
///////////////////////////////////////////////////////////////////////////
|
264
407
|
|
265
|
-
|
408
|
+
function to_comment(stream, state) {
|
409
|
+
return as_block(stream, state, 'comment');
|
266
410
|
}
|
267
411
|
|
268
|
-
function
|
269
|
-
return
|
412
|
+
function to_verbatim(stream, state) {
|
413
|
+
return as_block(stream, state, 'meta');
|
270
414
|
}
|
271
415
|
|
272
|
-
function
|
273
|
-
if (
|
274
|
-
|
416
|
+
function as_block(stream, state, token) {
|
417
|
+
if (stream.eol() || stream.eatSpace()) {
|
418
|
+
stream.skipToEnd();
|
419
|
+
return token;
|
275
420
|
} else {
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
421
|
+
change(state, to_normal);
|
422
|
+
return null;
|
423
|
+
}
|
424
|
+
}
|
280
425
|
|
426
|
+
///////////////////////////////////////////////////////////////////////////
|
427
|
+
///////////////////////////////////////////////////////////////////////////
|
428
|
+
|
429
|
+
function to_mode(stream, state) {
|
430
|
+
|
431
|
+
if (state.ctx.mode && state.ctx.local) {
|
432
|
+
|
433
|
+
if (stream.sol()) {
|
434
|
+
if (!stream.eatSpace()) change(state, to_normal);
|
281
435
|
return null;
|
282
436
|
}
|
283
437
|
|
284
|
-
|
438
|
+
try {
|
439
|
+
return state.ctx.mode.token(stream, state.ctx.local);
|
440
|
+
} catch (ex) {
|
441
|
+
change(state, to_normal);
|
442
|
+
return null;
|
443
|
+
}
|
285
444
|
}
|
445
|
+
|
446
|
+
change(state, to_normal);
|
447
|
+
return null;
|
286
448
|
}
|
287
449
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
450
|
+
///////////////////////////////////////////////////////////////////////////
|
451
|
+
///////////////////////////////////////////////////////////////////////////
|
452
|
+
|
453
|
+
function context(phase, stage, mode, local) {
|
454
|
+
return {phase: phase, stage: stage, mode: mode, local: local};
|
455
|
+
}
|
456
|
+
|
457
|
+
function change(state, tok, ctx) {
|
458
|
+
state.tok = tok;
|
459
|
+
state.ctx = ctx || {};
|
460
|
+
}
|
461
|
+
|
462
|
+
function stage(state) {
|
463
|
+
return state.ctx.stage || 0;
|
296
464
|
}
|
297
465
|
|
466
|
+
function phase(state) {
|
467
|
+
return state.ctx.phase;
|
468
|
+
}
|
469
|
+
|
470
|
+
///////////////////////////////////////////////////////////////////////////
|
471
|
+
///////////////////////////////////////////////////////////////////////////
|
472
|
+
|
298
473
|
return {
|
299
|
-
startState: function() {
|
300
|
-
return {
|
474
|
+
startState: function () {
|
475
|
+
return {tok: to_normal, ctx: context(undefined, 0)};
|
301
476
|
},
|
302
477
|
|
303
|
-
copyState: function(state) {
|
304
|
-
return {
|
478
|
+
copyState: function (state) {
|
479
|
+
return {tok: state.tok, ctx: state.ctx};
|
305
480
|
},
|
306
481
|
|
307
|
-
|
308
|
-
|
309
|
-
|
482
|
+
innerMode: function (state) {
|
483
|
+
return {state: state.ctx.local, mode: state.ctx.mode};
|
484
|
+
},
|
485
|
+
|
486
|
+
token: function (stream, state) {
|
487
|
+
return state.tok(stream, state);
|
310
488
|
}
|
311
489
|
};
|
312
|
-
},
|
490
|
+
}, 'python', 'stex');
|
491
|
+
|
492
|
+
///////////////////////////////////////////////////////////////////////////////
|
493
|
+
///////////////////////////////////////////////////////////////////////////////
|
494
|
+
|
495
|
+
CodeMirror.defineMode('rst', function (config, options) {
|
496
|
+
|
497
|
+
var rx_uri_protocol = "[Hh][Tt][Tt][Pp][Ss]?://";
|
498
|
+
var rx_uri_domain = "(?:[\\d\\w.-]+)\\.(?:\\w{2,6})";
|
499
|
+
var rx_uri_path = "(?:/[\\d\\w\\#\\%\\&\\-\\.\\,\\/\\:\\=\\?\\~]+)*";
|
500
|
+
var rx_uri = new RegExp("^" +
|
501
|
+
rx_uri_protocol + rx_uri_domain + rx_uri_path
|
502
|
+
);
|
503
|
+
|
504
|
+
var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*(\s+|$)/;
|
505
|
+
var rx_emphasis = /^[^\*]\*[^\*\s](?:[^\*]*[^\*\s])?\*(\s+|$)/;
|
506
|
+
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``(\s+|$)/;
|
507
|
+
|
508
|
+
var rx_number = /^(?:[\d]+(?:[\.,]\d+)*)/;
|
509
|
+
var rx_positive = /^(?:\s\+[\d]+(?:[\.,]\d+)*)/;
|
510
|
+
var rx_negative = /^(?:\s\-[\d]+(?:[\.,]\d+)*)/;
|
511
|
+
|
512
|
+
var overlay = {
|
513
|
+
token: function (stream) {
|
514
|
+
|
515
|
+
if (stream.match(rx_uri)) return 'link';
|
516
|
+
if (stream.match(rx_strong)) return 'strong';
|
517
|
+
if (stream.match(rx_emphasis)) return 'em';
|
518
|
+
if (stream.match(rx_literal)) return 'string-2';
|
519
|
+
if (stream.match(rx_number)) return 'number';
|
520
|
+
if (stream.match(rx_positive)) return 'positive';
|
521
|
+
if (stream.match(rx_negative)) return 'negative';
|
522
|
+
|
523
|
+
while (stream.next() != null) {
|
524
|
+
if (stream.match(rx_uri, false)) break;
|
525
|
+
if (stream.match(rx_strong, false)) break;
|
526
|
+
if (stream.match(rx_emphasis, false)) break;
|
527
|
+
if (stream.match(rx_literal, false)) break;
|
528
|
+
if (stream.match(rx_number, false)) break;
|
529
|
+
if (stream.match(rx_positive, false)) break;
|
530
|
+
if (stream.match(rx_negative, false)) break;
|
531
|
+
}
|
532
|
+
|
533
|
+
return null;
|
534
|
+
}
|
535
|
+
};
|
536
|
+
|
537
|
+
var mode = CodeMirror.getMode(
|
538
|
+
config, options.backdrop || 'rst-base'
|
539
|
+
);
|
540
|
+
|
541
|
+
return CodeMirror.overlayMode(mode, overlay, true); // combine
|
542
|
+
}, 'python', 'stex');
|
543
|
+
|
544
|
+
///////////////////////////////////////////////////////////////////////////////
|
545
|
+
///////////////////////////////////////////////////////////////////////////////
|
546
|
+
|
547
|
+
CodeMirror.defineMIME('text/x-rst', 'rst');
|
313
548
|
|
314
|
-
|
549
|
+
///////////////////////////////////////////////////////////////////////////////
|
550
|
+
///////////////////////////////////////////////////////////////////////////////
|