diff options
author | Valerio Virgillito | 2012-05-04 15:31:40 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-05-04 15:31:40 -0700 |
commit | 3ebed34665fa73b0ce613b400f3029ebf4476439 (patch) | |
tree | 09a3c592035030bda7bb62d1f908ce263377d74c /imports/codemirror/mode/stex | |
parent | 8dcbac5d4c30e9dfbc543a5f997939111e9c9f89 (diff) | |
parent | 526e423e4a2734c2b139af23911e912452a4443f (diff) | |
download | ninja-3ebed34665fa73b0ce613b400f3029ebf4476439.tar.gz |
Merge branch 'refs/heads/master' into dom-architecture
Diffstat (limited to 'imports/codemirror/mode/stex')
-rw-r--r-- | imports/codemirror/mode/stex/stex.js | 17 | ||||
-rw-r--r-- | imports/codemirror/mode/stex/test.html | 251 |
2 files changed, 266 insertions, 2 deletions
diff --git a/imports/codemirror/mode/stex/stex.js b/imports/codemirror/mode/stex/stex.js index bb47fb45..b89e619e 100644 --- a/imports/codemirror/mode/stex/stex.js +++ b/imports/codemirror/mode/stex/stex.js | |||
@@ -82,7 +82,7 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg) | |||
82 | } | 82 | } |
83 | 83 | ||
84 | function normal(source, state) { | 84 | function normal(source, state) { |
85 | if (source.match(/^\\[a-z]+/)) { | 85 | if (source.match(/^\\[a-zA-Z@]+/)) { |
86 | var cmdName = source.current(); | 86 | var cmdName = source.current(); |
87 | cmdName = cmdName.substr(1, cmdName.length-1); | 87 | cmdName = cmdName.substr(1, cmdName.length-1); |
88 | var plug = plugins[cmdName]; | 88 | var plug = plugins[cmdName]; |
@@ -95,9 +95,22 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg) | |||
95 | return plug.style; | 95 | return plug.style; |
96 | } | 96 | } |
97 | 97 | ||
98 | // escape characters | ||
99 | if (source.match(/^\\[$&%#{}_]/)) { | ||
100 | return "tag"; | ||
101 | } | ||
102 | |||
103 | // white space control characters | ||
104 | if (source.match(/^\\[,;!\/]/)) { | ||
105 | return "tag"; | ||
106 | } | ||
107 | |||
98 | var ch = source.next(); | 108 | var ch = source.next(); |
99 | if (ch == "%") { | 109 | if (ch == "%") { |
100 | setState(state, inCComment); | 110 | // special case: % at end of its own line; stay in same state |
111 | if (!source.eol()) { | ||
112 | setState(state, inCComment); | ||
113 | } | ||
101 | return "comment"; | 114 | return "comment"; |
102 | } | 115 | } |
103 | else if (ch=='}' || ch==']') { | 116 | else if (ch=='}' || ch==']') { |
diff --git a/imports/codemirror/mode/stex/test.html b/imports/codemirror/mode/stex/test.html new file mode 100644 index 00000000..b53a6a24 --- /dev/null +++ b/imports/codemirror/mode/stex/test.html | |||
@@ -0,0 +1,251 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: sTeX mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="stex.js"></script> | ||
8 | <link rel="stylesheet" href="../../test/mode_test.css"> | ||
9 | <script src="../../test/mode_test.js"></script> | ||
10 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
11 | </head> | ||
12 | <body> | ||
13 | <h1>Tests for the sTeX Mode</h1> | ||
14 | <h2>Basics</h2> | ||
15 | <script language="javascript"> | ||
16 | MT = ModeTest; | ||
17 | |||
18 | MT.test('foo', | ||
19 | null, 'foo'); | ||
20 | |||
21 | MT.test('foo bar', | ||
22 | null, 'foo', | ||
23 | null, ' bar'); | ||
24 | </script> | ||
25 | |||
26 | <h2>Tags</h2> | ||
27 | <script language="javascript"> | ||
28 | MT.test('\\begin{document}\n\\end{document}', | ||
29 | 'tag', '\\begin', | ||
30 | 'bracket', '{', | ||
31 | 'atom', 'document', | ||
32 | 'bracket', '}', | ||
33 | 'tag', '\\end', | ||
34 | 'bracket', '{', | ||
35 | 'atom', 'document', | ||
36 | 'bracket', '}'); | ||
37 | |||
38 | MT.test('\\begin{equation}\n E=mc^2\n\\end{equation}', | ||
39 | 'tag', '\\begin', | ||
40 | 'bracket', '{', | ||
41 | 'atom', 'equation', | ||
42 | 'bracket', '}', | ||
43 | null, ' ', | ||
44 | null, ' ', | ||
45 | null, 'E', | ||
46 | null, '=mc', | ||
47 | null, '^2', | ||
48 | 'tag', '\\end', | ||
49 | 'bracket', '{', | ||
50 | 'atom', 'equation', | ||
51 | 'bracket', '}'); | ||
52 | |||
53 | MT.test('\\begin{module}[]', | ||
54 | 'tag', '\\begin', | ||
55 | 'bracket', '{', | ||
56 | 'atom', 'module', | ||
57 | 'bracket', '}', | ||
58 | 'bracket', '[', | ||
59 | 'bracket', ']'); | ||
60 | |||
61 | MT.test('\\begin{module}[id=bbt-size]', | ||
62 | 'tag', '\\begin', | ||
63 | 'bracket', '{', | ||
64 | 'atom', 'module', | ||
65 | 'bracket', '}', | ||
66 | 'bracket', '[', | ||
67 | null, 'id', | ||
68 | null, '=bbt-size', | ||
69 | 'bracket', ']'); | ||
70 | |||
71 | MT.test('\\importmodule[b-b-t]{b-b-t}', | ||
72 | 'tag', '\\importmodule', | ||
73 | 'bracket', '[', | ||
74 | 'string', 'b-b-t', | ||
75 | 'bracket', ']', | ||
76 | 'bracket', '{', | ||
77 | 'builtin', 'b-b-t', | ||
78 | 'bracket', '}'); | ||
79 | |||
80 | MT.test('\\importmodule[\\KWARCslides{dmath/en/cardinality}]{card}', | ||
81 | 'tag', '\\importmodule', | ||
82 | 'bracket', '[', | ||
83 | 'tag', '\\KWARCslides', | ||
84 | 'bracket', '{', | ||
85 | 'string', 'dmath', | ||
86 | 'string', '/en', | ||
87 | 'string', '/cardinality', | ||
88 | 'bracket', '}', | ||
89 | 'bracket', ']', | ||
90 | 'bracket', '{', | ||
91 | 'builtin', 'card', | ||
92 | 'bracket', '}'); | ||
93 | |||
94 | MT.test('\\PSforPDF[1]{#1}', // could treat #1 specially | ||
95 | 'tag', '\\PSforPDF', | ||
96 | 'bracket', '[', | ||
97 | 'atom', '1', | ||
98 | 'bracket', ']', | ||
99 | 'bracket', '{', | ||
100 | null, '#1', | ||
101 | 'bracket', '}'); | ||
102 | </script> | ||
103 | |||
104 | <h2>Comments</h2> | ||
105 | <script language="javascript"> | ||
106 | MT.test('% foo', | ||
107 | 'comment', '%', | ||
108 | 'comment', ' foo'); | ||
109 | |||
110 | MT.test('\\item% bar', | ||
111 | 'tag', '\\item', | ||
112 | 'comment', '%', | ||
113 | 'comment', ' bar'); | ||
114 | |||
115 | MT.test(' % \\item', | ||
116 | null, ' ', | ||
117 | 'comment', '%', | ||
118 | 'comment', ' \\item'); | ||
119 | |||
120 | MT.test('%\nfoo', | ||
121 | 'comment', '%', | ||
122 | null, 'foo'); | ||
123 | </script> | ||
124 | |||
125 | <h2>Errors</h2> | ||
126 | <script language="javascript"> | ||
127 | MT.test('\\begin}{', | ||
128 | 'tag', '\\begin', | ||
129 | 'error', '}', | ||
130 | 'bracket', '{'); | ||
131 | |||
132 | MT.test('\\item]{', | ||
133 | 'tag', '\\item', | ||
134 | 'error', ']', | ||
135 | 'bracket', '{'); | ||
136 | |||
137 | MT.test('% }', | ||
138 | 'comment', '%', | ||
139 | 'comment', ' }'); | ||
140 | </script> | ||
141 | |||
142 | <h2>Character Escapes</h2> | ||
143 | <script language="javascript"> | ||
144 | MT.test('the \\# key', | ||
145 | null, 'the', | ||
146 | null, ' ', | ||
147 | 'tag', '\\#', | ||
148 | null, ' key'); | ||
149 | |||
150 | MT.test('a \\$5 stetson', | ||
151 | null, 'a', | ||
152 | null, ' ', | ||
153 | 'tag', '\\$', | ||
154 | 'atom', 5, | ||
155 | null, ' stetson'); | ||
156 | |||
157 | MT.test('100\\% beef', | ||
158 | 'atom', '100', | ||
159 | 'tag', '\\%', | ||
160 | null, ' beef'); | ||
161 | |||
162 | MT.test('L \\& N', | ||
163 | null, 'L', | ||
164 | null, ' ', | ||
165 | 'tag', '\\&', | ||
166 | null, ' N'); | ||
167 | |||
168 | MT.test('foo\\_bar', | ||
169 | null, 'foo', | ||
170 | 'tag', '\\_', | ||
171 | null, 'bar'); | ||
172 | |||
173 | MT.test('\\emph{\\{}', | ||
174 | 'tag', '\\emph', | ||
175 | 'bracket','{', | ||
176 | 'tag', '\\{', | ||
177 | 'bracket','}'); | ||
178 | |||
179 | MT.test('\\emph{\\}}', | ||
180 | 'tag', '\\emph', | ||
181 | 'bracket','{', | ||
182 | 'tag', '\\}', | ||
183 | 'bracket','}'); | ||
184 | |||
185 | MT.test('section \\S1', | ||
186 | null, 'section', | ||
187 | null, ' ', | ||
188 | 'tag', '\\S', | ||
189 | 'atom', '1'); | ||
190 | |||
191 |