swagr 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/Rakefile +20 -0
  2. data/bin/swagr +37 -9
  3. data/examples/examples01/app.rb +5 -1
  4. data/examples/examples01/views/edit.slim +31 -0
  5. data/examples/examples01/views/footer.slim +1 -1
  6. data/examples/examples01/views/layout.slim +23 -5
  7. data/examples/examples01/views/navbar.slim +17 -16
  8. data/lib/swagr/version.rb +3 -1
  9. data/templates/app.rb +5 -1
  10. data/templates/static/js/codemirror/keymap/vim.js +279 -66
  11. data/templates/static/js/codemirror/lib/codemirror.css +10 -9
  12. data/templates/static/js/codemirror/lib/codemirror.js +385 -152
  13. data/templates/static/js/codemirror/mode/apl/apl.js +160 -0
  14. data/templates/static/js/codemirror/mode/apl/index.html +61 -0
  15. data/templates/static/js/codemirror/mode/asterisk/asterisk.js +183 -0
  16. data/templates/static/js/codemirror/mode/asterisk/index.html +142 -0
  17. data/templates/static/js/codemirror/mode/clike/clike.js +2 -0
  18. data/templates/static/js/codemirror/mode/clike/index.html +1 -1
  19. data/templates/static/js/codemirror/mode/clike/scala.html +1 -1
  20. data/templates/static/js/codemirror/mode/clojure/clojure.js +3 -3
  21. data/templates/static/js/codemirror/mode/css/css.js +2 -2
  22. data/templates/static/js/codemirror/mode/css/test.js +76 -471
  23. data/templates/static/js/codemirror/mode/d/d.js +205 -0
  24. data/templates/static/js/codemirror/mode/d/index.html +262 -0
  25. data/templates/static/js/codemirror/mode/erlang/index.html +1 -1
  26. data/templates/static/js/codemirror/mode/gfm/gfm.js +2 -1
  27. data/templates/static/js/codemirror/mode/gfm/index.html +1 -2
  28. data/templates/static/js/codemirror/mode/gfm/test.js +84 -225
  29. data/templates/static/js/codemirror/mode/go/index.html +1 -1
  30. data/templates/static/js/codemirror/mode/groovy/index.html +1 -1
  31. data/templates/static/js/codemirror/mode/haskell/index.html +1 -1
  32. data/templates/static/js/codemirror/mode/javascript/index.html +2 -2
  33. data/templates/static/js/codemirror/mode/javascript/javascript.js +13 -2
  34. data/templates/static/js/codemirror/mode/less/index.html +1 -1
  35. data/templates/static/js/codemirror/mode/lua/index.html +1 -1
  36. data/templates/static/js/codemirror/mode/markdown/index.html +1 -1
  37. data/templates/static/js/codemirror/mode/markdown/markdown.js +8 -7
  38. data/templates/static/js/codemirror/mode/markdown/test.js +579 -1266
  39. data/templates/static/js/codemirror/mode/meta.js +71 -0
  40. data/templates/static/js/codemirror/mode/mysql/index.html +2 -0
  41. data/templates/static/js/codemirror/mode/ocaml/index.html +1 -1
  42. data/templates/static/js/codemirror/mode/php/index.html +1 -1
  43. data/templates/static/js/codemirror/mode/plsql/index.html +2 -0
  44. data/templates/static/js/codemirror/mode/python/index.html +1 -1
  45. data/templates/static/js/codemirror/mode/ruby/index.html +1 -1
  46. data/templates/static/js/codemirror/mode/sass/index.html +54 -0
  47. data/templates/static/js/codemirror/mode/sass/sass.js +349 -0
  48. data/templates/static/js/codemirror/mode/shell/index.html +1 -1
  49. data/templates/static/js/codemirror/mode/sieve/LICENSE +0 -4
  50. data/templates/static/js/codemirror/mode/sieve/sieve.js +37 -10
  51. data/templates/static/js/codemirror/mode/smalltalk/index.html +1 -1
  52. data/templates/static/js/codemirror/mode/sparql/index.html +1 -1
  53. data/templates/static/js/codemirror/mode/sql/index.html +68 -0
  54. data/templates/static/js/codemirror/mode/sql/sql.js +268 -0
  55. data/templates/static/js/codemirror/mode/stex/test.js +104 -343
  56. data/templates/static/js/codemirror/mode/tiddlywiki/index.html +1 -1
  57. data/templates/static/js/codemirror/mode/vb/index.html +1 -1
  58. data/templates/static/js/codemirror/mode/xquery/test.js +54 -67
  59. data/templates/static/js/codemirror/mode/xquery/xquery.js +8 -8
  60. data/templates/static/js/crossfilter.min.js +1 -0
  61. data/templates/views/edit.slim +31 -0
  62. data/templates/views/footer.slim +1 -1
  63. data/templates/views/layout.slim +23 -5
  64. data/templates/views/navbar.slim +17 -16
  65. metadata +16 -30
  66. data/examples/examples01/static/css/codemirror.css +0 -1247
  67. data/examples/examples01/static/js/codemirror-compressed-3-0.js +0 -5
  68. data/examples/examples01/views/about.slim +0 -15
  69. data/examples/examples01/views/application.slim +0 -0
  70. data/examples/examples01/views/layout_cm.slim +0 -17
  71. data/templates/static/js/codemirror/lib/util/closetag.js +0 -85
  72. data/templates/static/js/codemirror/lib/util/colorize.js +0 -29
  73. data/templates/static/js/codemirror/lib/util/continuecomment.js +0 -36
  74. data/templates/static/js/codemirror/lib/util/continuelist.js +0 -28
  75. data/templates/static/js/codemirror/lib/util/dialog.css +0 -32
  76. data/templates/static/js/codemirror/lib/util/dialog.js +0 -75
  77. data/templates/static/js/codemirror/lib/util/foldcode.js +0 -182
  78. data/templates/static/js/codemirror/lib/util/formatting.js +0 -108
  79. data/templates/static/js/codemirror/lib/util/javascript-hint.js +0 -137
  80. data/templates/static/js/codemirror/lib/util/loadmode.js +0 -51
  81. data/templates/static/js/codemirror/lib/util/match-highlighter.js +0 -46
  82. data/templates/static/js/codemirror/lib/util/matchbrackets.js +0 -63
  83. data/templates/static/js/codemirror/lib/util/multiplex.js +0 -95
  84. data/templates/static/js/codemirror/lib/util/overlay.js +0 -59
  85. data/templates/static/js/codemirror/lib/util/pig-hint.js +0 -117
  86. data/templates/static/js/codemirror/lib/util/runmode-standalone.js +0 -90
  87. data/templates/static/js/codemirror/lib/util/runmode.js +0 -52
  88. data/templates/static/js/codemirror/lib/util/search.js +0 -119
  89. data/templates/static/js/codemirror/lib/util/searchcursor.js +0 -119
  90. data/templates/static/js/codemirror/lib/util/simple-hint.css +0 -16
  91. data/templates/static/js/codemirror/lib/util/simple-hint.js +0 -102
  92. data/templates/static/js/codemirror/lib/util/xml-hint.js +0 -131
  93. data/templates/views/about.slim +0 -15
@@ -5,7 +5,7 @@
5
5
  <title>CodeMirror: Markdown mode</title>
6
6
  <link rel="stylesheet" href="../../lib/codemirror.css">
7
7
  <script src="../../lib/codemirror.js"></script>
8
- <script src="../../lib/util/continuelist.js"></script>
8
+ <script src="../../addon/edit/continuelist.js"></script>
9
9
  <script src="../xml/xml.js"></script>
10
10
  <script src="markdown.js"></script>
11
11
  <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
@@ -10,7 +10,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
10
10
  "c++": "text/x-c++src",
11
11
  java: "text/x-java",
12
12
  csharp: "text/x-csharp",
13
- "c#": "text/x-csharp"
13
+ "c#": "text/x-csharp",
14
+ scala: "text/x-scala"
14
15
  };
15
16
 
16
17
  var getMode = (function () {
@@ -246,8 +247,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
246
247
  return getType(state);
247
248
  }
248
249
 
249
- if (ch === '!' && stream.match(/\[.*\] ?(?:\(|\[)/, false)) {
250
- stream.match(/\[.*\]/);
250
+ if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
251
+ stream.match(/\[[^\]]*\]/);
251
252
  state.inline = state.f = linkHref;
252
253
  return image;
253
254
  }
@@ -456,10 +457,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
456
457
  var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
457
458
  var difference = Math.floor((indentation - state.indentation) / 4) * 4;
458
459
  if (difference > 4) difference = 4;
459
- indentation = state.indentation + difference;
460
- state.indentationDiff = indentation - state.indentation;
461
- state.indentation = indentation;
462
- if (indentation > 0) { return null; }
460
+ var adjustedIndentation = state.indentation + difference;
461
+ state.indentationDiff = adjustedIndentation - state.indentation;
462
+ state.indentation = adjustedIndentation;
463
+ if (indentation > 0) return null;
463
464
  }
464
465
  return state.f(stream, state);
465
466
  },
@@ -1,1266 +1,579 @@
1
- // Initiate ModeTest and set defaults
2
- var MT = ModeTest;
3
- MT.modeName = 'markdown';
4
- MT.modeOptions = {};
5
-
6
- MT.testMode(
7
- 'plainText',
8
- 'foo',
9
- [
10
- null, 'foo'
11
- ]
12
- );
13
-
14
- // Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)
15
- MT.testMode(
16
- 'codeBlocksUsing4Spaces',
17
- ' foo',
18
- [
19
- null, ' ',
20
- 'comment', 'foo'
21
- ]
22
- );
23
- // Code blocks using 4 spaces with internal indentation
24
- MT.testMode(
25
- 'codeBlocksUsing4SpacesIndentation',
26
- ' bar\n hello\n world\n foo\nbar',
27
- [
28
- null, ' ',
29
- 'comment', 'bar',
30
- null, ' ',
31
- 'comment', 'hello',
32
- null, ' ',
33
- 'comment', 'world',
34
- null, ' ',
35
- 'comment', 'foo',
36
- null, 'bar'
37
- ]
38
- );
39
- // Code blocks using 4 spaces with internal indentation
40
- MT.testMode(
41
- 'codeBlocksUsing4SpacesIndentation',
42
- ' foo\n bar\n hello\n world',
43
- [
44
- null, ' foo',
45
- null, ' ',
46
- 'comment', 'bar',
47
- null, ' ',
48
- 'comment', 'hello',
49
- null, ' ',
50
- 'comment', 'world'
51
- ]
52
- );
53
-
54
- // Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
55
- MT.testMode(
56
- 'codeBlocksUsing1Tab',
57
- '\tfoo',
58
- [
59
- null, '\t',
60
- 'comment', 'foo'
61
- ]
62
- );
63
-
64
- // Inline code using backticks
65
- MT.testMode(
66
- 'inlineCodeUsingBackticks',
67
- 'foo `bar`',
68
- [
69
- null, 'foo ',
70
- 'comment', '`bar`'
71
- ]
72
- );
73
-
74
- // Block code using single backtick (shouldn't work)
75
- MT.testMode(
76
- 'blockCodeSingleBacktick',
77
- '`\nfoo\n`',
78
- [
79
- 'comment', '`',
80
- null, 'foo',
81
- 'comment', '`'
82
- ]
83
- );
84
-
85
- // Unclosed backticks
86
- // Instead of simply marking as CODE, it would be nice to have an
87
- // incomplete flag for CODE, that is styled slightly different.
88
- MT.testMode(
89
- 'unclosedBackticks',
90
- 'foo `bar',
91
- [
92
- null, 'foo ',
93
- 'comment', '`bar'
94
- ]
95
- );
96
-
97
- // Per documentation: "To include a literal backtick character within a
98
- // code span, you can use multiple backticks as the opening and closing
99
- // delimiters"
100
- MT.testMode(
101
- 'doubleBackticks',
102
- '``foo ` bar``',
103
- [
104
- 'comment', '``foo ` bar``'
105
- ]
106
- );
107
-
108
- // Tests based on Dingus
109
- // http://daringfireball.net/projects/markdown/dingus
110
- //
111
- // Multiple backticks within an inline code block
112
- MT.testMode(
113
- 'consecutiveBackticks',
114
- '`foo```bar`',
115
- [
116
- 'comment', '`foo```bar`'
117
- ]
118
- );
119
- // Multiple backticks within an inline code block with a second code block
120
- MT.testMode(
121
- 'consecutiveBackticks',
122
- '`foo```bar` hello `world`',
123
- [
124
- 'comment', '`foo```bar`',
125
- null, ' hello ',
126
- 'comment', '`world`'
127
- ]
128
- );
129
- // Unclosed with several different groups of backticks
130
- MT.testMode(
131
- 'unclosedBackticks',
132
- '``foo ``` bar` hello',
133
- [
134
- 'comment', '``foo ``` bar` hello'
135
- ]
136
- );
137
- // Closed with several different groups of backticks
138
- MT.testMode(
139
- 'closedBackticks',
140
- '``foo ``` bar` hello`` world',
141
- [
142
- 'comment', '``foo ``` bar` hello``',
143
- null, ' world'
144
- ]
145
- );
146
-
147
- // atx headers
148
- // http://daringfireball.net/projects/markdown/syntax#header
149
- //
150
- // H1
151
- MT.testMode(
152
- 'atxH1',
153
- '# foo',
154
- [
155
- 'header', '# foo'
156
- ]
157
- );
158
- // H2
159
- MT.testMode(
160
- 'atxH2',
161
- '## foo',
162
- [
163
- 'header', '## foo'
164
- ]
165
- );
166
- // H3
167
- MT.testMode(
168
- 'atxH3',
169
- '### foo',
170
- [
171
- 'header', '### foo'
172
- ]
173
- );
174
- // H4
175
- MT.testMode(
176
- 'atxH4',
177
- '#### foo',
178
- [
179
- 'header', '#### foo'
180
- ]
181
- );
182
- // H5
183
- MT.testMode(
184
- 'atxH5',
185
- '##### foo',
186
- [
187
- 'header', '##### foo'
188
- ]
189
- );
190
- // H6
191
- MT.testMode(
192
- 'atxH6',
193
- '###### foo',
194
- [
195
- 'header', '###### foo'
196
- ]
197
- );
198
- // H6 - 7x '#' should still be H6, per Dingus
199
- // http://daringfireball.net/projects/markdown/dingus
200
- MT.testMode(
201
- 'atxH6NotH7',
202
- '####### foo',
203
- [
204
- 'header', '####### foo'
205
- ]
206
- );
207
-
208
- // Setext headers - H1, H2
209
- // Per documentation, "Any number of underlining =’s or -’s will work."
210
- // http://daringfireball.net/projects/markdown/syntax#header
211
- // Ideally, the text would be marked as `header` as well, but this is
212
- // not really feasible at the moment. So, instead, we're testing against
213
- // what works today, to avoid any regressions.
214
- //
215
- // Check if single underlining = works
216
- MT.testMode(
217
- 'setextH1',
218
- 'foo\n=',
219
- [
220
- null, 'foo',
221
- 'header', '='
222
- ]
223
- );
224
- // Check if 3+ ='s work
225
- MT.testMode(
226
- 'setextH1',
227
- 'foo\n===',
228
- [
229
- null, 'foo',
230
- 'header', '==='
231
- ]
232
- );
233
- // Check if single underlining - works
234
- MT.testMode(
235
- 'setextH2',
236
- 'foo\n-',
237
- [
238
- null, 'foo',
239
- 'header', '-'
240
- ]
241
- );
242
- // Check if 3+ -'s work
243
- MT.testMode(
244
- 'setextH2',
245
- 'foo\n---',
246
- [
247
- null, 'foo',
248
- 'header', '---'
249
- ]
250
- );
251
-
252
- // Single-line blockquote with trailing space
253
- MT.testMode(
254
- 'blockquoteSpace',
255
- '> foo',
256
- [
257
- 'quote', '> foo'
258
- ]
259
- );
260
-
261
- // Single-line blockquote
262
- MT.testMode(
263
- 'blockquoteNoSpace',
264
- '>foo',
265
- [
266
- 'quote', '>foo'
267
- ]
268
- );
269
-
270
- // Single-line blockquote followed by normal paragraph
271
- MT.testMode(
272
- 'blockquoteThenParagraph',
273
- '>foo\n\nbar',
274
- [
275
- 'quote', '>foo',
276
- null, 'bar'
277
- ]
278
- );
279
-
280
- // Multi-line blockquote (lazy mode)
281
- MT.testMode(
282
- 'multiBlockquoteLazy',
283
- '>foo\nbar',
284
- [
285
- 'quote', '>foo',
286
- 'quote', 'bar'
287
- ]
288
- );
289
-
290
- // Multi-line blockquote followed by normal paragraph (lazy mode)
291
- MT.testMode(
292
- 'multiBlockquoteLazyThenParagraph',
293
- '>foo\nbar\n\nhello',
294
- [
295
- 'quote', '>foo',
296
- 'quote', 'bar',
297
- null, 'hello'
298
- ]
299
- );
300
-
301
- // Multi-line blockquote (non-lazy mode)
302
- MT.testMode(
303
- 'multiBlockquote',
304
- '>foo\n>bar',
305
- [
306
- 'quote', '>foo',
307
- 'quote', '>bar'
308
- ]
309
- );
310
-
311
- // Multi-line blockquote followed by normal paragraph (non-lazy mode)
312
- MT.testMode(
313
- 'multiBlockquoteThenParagraph',
314
- '>foo\n>bar\n\nhello',
315
- [
316
- 'quote', '>foo',
317
- 'quote', '>bar',
318
- null, 'hello'
319
- ]
320
- );
321
-
322
- // Check list types
323
- MT.testMode(
324
- 'listAsterisk',
325
- '* foo\n* bar',
326
- [
327
- 'string', '* foo',
328
- 'string', '* bar'
329
- ]
330
- );
331
- MT.testMode(
332
- 'listPlus',
333
- '+ foo\n+ bar',
334
- [
335
- 'string', '+ foo',
336
- 'string', '+ bar'
337
- ]
338
- );
339
- MT.testMode(
340
- 'listDash',
341
- '- foo\n- bar',
342
- [
343
- 'string', '- foo',
344
- 'string', '- bar'
345
- ]
346
- );
347
- MT.testMode(
348
- 'listNumber',
349
- '1. foo\n2. bar',
350
- [
351
- 'string', '1. foo',
352
- 'string', '2. bar'
353
- ]
354
- );
355
-
356
- // Formatting in lists (*)
357
- MT.testMode(
358
- 'listAsteriskFormatting',
359
- '* *foo* bar\n\n* **foo** bar\n\n* ***foo*** bar\n\n* `foo` bar',
360
- [
361
- 'string', '* ',
362
- 'string em', '*foo*',
363
- 'string', ' bar',
364
- 'string', '* ',
365
- 'string strong', '**foo**',
366
- 'string', ' bar',
367
- 'string', '* ',
368
- 'string strong', '**',
369
- 'string emstrong', '*foo**',
370
- 'string em', '*',
371
- 'string', ' bar',
372
- 'string', '* ',
373
- 'string comment', '`foo`',
374
- 'string', ' bar'
375
- ]
376
- );
377
- // Formatting in lists (+)
378
- MT.testMode(
379
- 'listPlusFormatting',
380
- '+ *foo* bar\n\n+ **foo** bar\n\n+ ***foo*** bar\n\n+ `foo` bar',
381
- [
382
- 'string', '+ ',
383
- 'string em', '*foo*',
384
- 'string', ' bar',
385
- 'string', '+ ',
386
- 'string strong', '**foo**',
387
- 'string', ' bar',
388
- 'string', '+ ',
389
- 'string strong', '**',
390
- 'string emstrong', '*foo**',
391
- 'string em', '*',
392
- 'string', ' bar',
393
- 'string', '+ ',
394
- 'string comment', '`foo`',
395
- 'string', ' bar'
396
- ]
397
- );
398
- // Formatting in lists (-)
399
- MT.testMode(
400
- 'listDashFormatting',
401
- '- *foo* bar\n\n- **foo** bar\n\n- ***foo*** bar\n\n- `foo` bar',
402
- [
403
- 'string', '- ',
404
- 'string em', '*foo*',
405
- 'string', ' bar',
406
- 'string', '- ',
407
- 'string strong', '**foo**',
408
- 'string', ' bar',
409
- 'string', '- ',
410
- 'string strong', '**',
411
- 'string emstrong', '*foo**',
412
- 'string em', '*',
413
- 'string', ' bar',
414
- 'string', '- ',
415
- 'string comment', '`foo`',
416
- 'string', ' bar'
417
- ]
418
- );
419
- // Formatting in lists (1.)
420
- MT.testMode(
421
- 'listNumberFormatting',
422
- '1. *foo* bar\n\n2. **foo** bar\n\n3. ***foo*** bar\n\n4. `foo` bar',
423
- [
424
- 'string', '1. ',
425
- 'string em', '*foo*',
426
- 'string', ' bar',
427
- 'string', '2. ',
428
- 'string strong', '**foo**',
429
- 'string', ' bar',
430
- 'string', '3. ',
431
- 'string strong', '**',
432
- 'string emstrong', '*foo**',
433
- 'string em', '*',
434
- 'string', ' bar',
435
- 'string', '4. ',
436
- 'string comment', '`foo`',
437
- 'string', ' bar'
438
- ]
439
- );
440
-
441
- // Paragraph lists
442
- MT.testMode(
443
- 'listParagraph',
444
- '* foo\n\n* bar',
445
- [
446
- 'string', '* foo',
447
- 'string', '* bar'
448
- ]
449
- );
450
-
451
- // Multi-paragraph lists
452
- //
453
- // 4 spaces
454
- MT.testMode(
455
- 'listMultiParagraph',
456
- '* foo\n\n* bar\n\n hello',
457
- [
458
- 'string', '* foo',
459
- 'string', '* bar',
460
- null, ' ',
461
- 'string', 'hello'
462
- ]
463
- );
464
- // 4 spaces, extra blank lines (should still be list, per Dingus)
465
- MT.testMode(
466
- 'listMultiParagraphExtra',
467
- '* foo\n\n* bar\n\n\n hello',
468
- [
469
- 'string', '* foo',
470
- 'string', '* bar',
471
- null, ' ',
472
- 'string', 'hello'
473
- ]
474
- );
475
- // 4 spaces, plus 1 space (should still be list, per Dingus)
476
- MT.testMode(
477
- 'listMultiParagraphExtraSpace',
478
- '* foo\n\n* bar\n\n hello\n\n world',
479
- [
480
- 'string', '* foo',
481
- 'string', '* bar',
482
- null, ' ',
483
- 'string', 'hello',
484
- null, ' ',
485
- 'string', 'world'
486
- ]
487
- );
488
- // 1 tab
489
- MT.testMode(
490
- 'listTab',
491
- '* foo\n\n* bar\n\n\thello',
492
- [
493
- 'string', '* foo',
494
- 'string', '* bar',
495
- null, '\t',
496
- 'string', 'hello'
497
- ]
498
- );
499
- // No indent
500
- MT.testMode(
501
- 'listNoIndent',
502
- '* foo\n\n* bar\n\nhello',
503
- [
504
- 'string', '* foo',
505
- 'string', '* bar',
506
- null, 'hello'
507
- ]
508
- );
509
- // Blockquote
510
- MT.testMode(
511
- 'blockquote',
512
- '* foo\n\n* bar\n\n > hello',
513
- [
514
- 'string', '* foo',
515
- 'string', '* bar',
516
- null, ' ',
517
- 'string quote', '> hello'
518
- ]
519
- );
520
- // Code block
521
- MT.testMode(
522
- 'blockquoteCode',
523
- '* foo\n\n* bar\n\n > hello\n\n world',
524
- [
525
- 'string', '* foo',
526
- 'string', '* bar',
527
- null, ' ',
528
- 'comment', '> hello',
529
- null, ' ',
530
- 'string', 'world'
531
- ]
532
- );
533
- // Code block followed by text
534
- MT.testMode(
535
- 'blockquoteCodeText',
536
- '* foo\n\n bar\n\n hello\n\n world',
537
- [
538
- 'string', '* foo',
539
- null, ' ',
540
- 'string', 'bar',
541
- null, ' ',
542
- 'comment', 'hello',
543
- null, ' ',
544
- 'string', 'world'
545
- ]
546
- );
547
-
548
- // Nested list
549
- //
550
- // *
551
- MT.testMode(
552
- 'listAsteriskNested',
553
- '* foo\n\n * bar',
554
- [
555
- 'string', '* foo',
556
- null, ' ',
557
- 'string', '* bar'
558
- ]
559
- );
560
- // +
561
- MT.testMode(
562
- 'listPlusNested',
563
- '+ foo\n\n + bar',
564
- [
565
- 'string', '+ foo',
566
- null, ' ',
567
- 'string', '+ bar'
568
- ]
569
- );
570
- // -
571
- MT.testMode(
572
- 'listDashNested',
573
- '- foo\n\n - bar',
574
- [
575
- 'string', '- foo',
576
- null, ' ',
577
- 'string', '- bar'
578
- ]
579
- );
580
- // 1.
581
- MT.testMode(
582
- 'listNumberNested',
583
- '1. foo\n\n 2. bar',
584
- [
585
- 'string', '1. foo',
586
- null, ' ',
587
- 'string', '2. bar'
588
- ]
589
- );
590
- // Mixed
591
- MT.testMode(
592
- 'listMixed',
593
- '* foo\n\n + bar\n\n - hello\n\n 1. world',
594
- [
595
- 'string', '* foo',
596
- null, ' ',
597
- 'string', '+ bar',
598
- null, ' ',
599
- 'string', '- hello',
600
- null, ' ',
601
- 'string', '1. world'
602
- ]
603
- );
604
- // Blockquote
605
- MT.testMode(
606
- 'listBlockquote',
607
- '* foo\n\n + bar\n\n > hello',
608
- [
609
- 'string', '* foo',
610
- null, ' ',
611
- 'string', '+ bar',
612
- null, ' ',
613
- 'quote string', '> hello'
614
- ]
615
- );
616
- // Code
617
- MT.testMode(
618
- 'listCode',
619
- '* foo\n\n + bar\n\n hello',
620
- [
621
- 'string', '* foo',
622
- null, ' ',
623
- 'string', '+ bar',
624
- null, ' ',
625
- 'comment', 'hello'
626
- ]
627
- );
628
- // Code with internal indentation
629
- MT.testMode(
630
- 'listCodeIndentation',
631
- '* foo\n\n bar\n hello\n world\n foo\n bar',
632
- [
633
- 'string', '* foo',
634
- null, ' ',
635
- 'comment', 'bar',
636
- null, ' ',
637
- 'comment', 'hello',
638
- null, ' ',
639
- 'comment', 'world',
640
- null, ' ',
641
- 'comment', 'foo',
642
- null, ' ',
643
- 'string', 'bar'
644
- ]
645
- );
646
- // Code followed by text
647
- MT.testMode(
648
- 'listCodeText',
649
- '* foo\n\n bar\n\nhello',
650
- [
651
- 'string', '* foo',
652
- null, ' ',
653
- 'comment', 'bar',
654
- null, 'hello'
655
- ]
656
- );
657
-
658
- // Following tests directly from official Markdown documentation
659
- // http://daringfireball.net/projects/markdown/syntax#hr
660
- MT.testMode(
661
- 'hrSpace',
662
- '* * *',
663
- [
664
- 'hr', '* * *'
665
- ]
666
- );
667
-
668
- MT.testMode(
669
- 'hr',
670
- '***',
671
- [
672
- 'hr', '***'
673
- ]
674
- );
675
-
676
- MT.testMode(
677
- 'hrLong',
678
- '*****',
679
- [
680
- 'hr', '*****'
681
- ]
682
- );
683
-
684
- MT.testMode(
685
- 'hrSpaceDash',
686
- '- - -',
687
- [
688
- 'hr', '- - -'
689
- ]
690
- );
691
-
692
- MT.testMode(
693
- 'hrDashLong',
694
- '---------------------------------------',
695
- [
696
- 'hr', '---------------------------------------'
697
- ]
698
- );
699
-
700
- // Inline link with title
701
- MT.testMode(
702
- 'linkTitle',
703
- '[foo](http://example.com/ "bar") hello',
704
- [
705
- 'link', '[foo]',
706
- 'string', '(http://example.com/ "bar")',
707
- null, ' hello'
708
- ]
709
- );
710
-
711
- // Inline link without title
712
- MT.testMode(
713
- 'linkNoTitle',
714
- '[foo](http://example.com/) bar',
715
- [
716
- 'link', '[foo]',
717
- 'string', '(http://example.com/)',
718
- null, ' bar'
719
- ]
720
- );
721
-
722
- // Inline link with Em
723
- MT.testMode(
724
- 'linkEm',
725
- '[*foo*](http://example.com/) bar',
726
- [
727
- 'link', '[',
728
- 'link em', '*foo*',
729
- 'link', ']',
730
- 'string', '(http://example.com/)',
731
- null, ' bar'
732
- ]
733
- );
734
-
735
- // Inline link with Strong
736
- MT.testMode(
737
- 'linkStrong',
738
- '[**foo**](http://example.com/) bar',
739
- [
740
- 'link', '[',
741
- 'link strong', '**foo**',
742
- 'link', ']',
743
- 'string', '(http://example.com/)',
744
- null, ' bar'
745
- ]
746
- );
747
-
748
- // Inline link with EmStrong
749
- MT.testMode(
750
- 'linkEmStrong',
751
- '[***foo***](http://example.com/) bar',
752
- [
753
- 'link', '[',
754
- 'link strong', '**',
755
- 'link emstrong', '*foo**',
756
- 'link em', '*',
757
- 'link', ']',
758
- 'string', '(http://example.com/)',
759
- null, ' bar'
760
- ]
761
- );
762
-
763
- // Image with title
764
- MT.testMode(
765
- 'imageTitle',
766
- '![foo](http://example.com/ "bar") hello',
767
- [
768
- 'tag', '![foo]',
769
- 'string', '(http://example.com/ "bar")',
770
- null, ' hello'
771
- ]
772
- );
773
-
774
- // Image without title
775
- MT.testMode(
776
- 'imageNoTitle',
777
- '![foo](http://example.com/) bar',
778
- [
779
- 'tag', '![foo]',
780
- 'string', '(http://example.com/)',
781
- null, ' bar'
782
- ]
783
- );
784
-
785
- // Image with asterisks
786
- MT.testMode(
787
- 'imageAsterisks',
788
- '![*foo*](http://example.com/) bar',
789
- [
790
- 'tag', '![*foo*]',
791
- 'string', '(http://example.com/)',
792
- null, ' bar'
793
- ]
794
- );
795
-
796
- // Not a link. Should be normal text due to square brackets being used
797
- // regularly in text, especially in quoted material, and no space is allowed
798
- // between square brackets and parentheses (per Dingus).
799
- MT.testMode(
800
- 'notALink',
801
- '[foo] (bar)',
802
- [
803
- null, '[foo] (bar)'
804
- ]
805
- );
806
-
807
- // Reference-style links
808
- MT.testMode(
809
- 'linkReference',
810
- '[foo][bar] hello',
811
- [
812
- 'link', '[foo]',
813
- 'string', '[bar]',
814
- null, ' hello'
815
- ]
816
- );
817
- // Reference-style links with Em
818
- MT.testMode(
819
- 'linkReferenceEm',
820
- '[*foo*][bar] hello',
821
- [
822
- 'link', '[',
823
- 'link em', '*foo*',
824
- 'link', ']',
825
- 'string', '[bar]',
826
- null, ' hello'
827
- ]
828
- );
829
- // Reference-style links with Strong
830
- MT.testMode(
831
- 'linkReferenceStrong',
832
- '[**foo**][bar] hello',
833
- [
834
- 'link', '[',
835
- 'link strong', '**foo**',
836
- 'link', ']',
837
- 'string', '[bar]',
838
- null, ' hello'
839
- ]
840
- );
841
- // Reference-style links with EmStrong
842
- MT.testMode(
843
- 'linkReferenceEmStrong',
844
- '[***foo***][bar] hello',
845
- [
846
- 'link', '[',
847
- 'link strong', '**',
848
- 'link emstrong', '*foo**',
849
- 'link em', '*',
850
- 'link', ']',
851
- 'string', '[bar]',
852
- null, ' hello'
853
- ]
854
- );
855
-
856
- // Reference-style links with optional space separator (per docuentation)
857
- // "You can optionally use a space to separate the sets of brackets"
858
- MT.testMode(
859
- 'linkReferenceSpace',
860
- '[foo] [bar] hello',
861
- [
862
- 'link', '[foo]',
863
- null, ' ',
864
- 'string', '[bar]',
865
- null, ' hello'
866
- ]
867
- );
868
- // Should only allow a single space ("...use *a* space...")
869
- MT.testMode(
870
- 'linkReferenceDoubleSpace',
871
- '[foo] [bar] hello',
872
- [
873
- null, '[foo] [bar] hello'
874
- ]
875
- );
876
-
877
- // Reference-style links with implicit link name
878
- MT.testMode(
879
- 'linkImplicit',
880
- '[foo][] hello',
881
- [
882
- 'link', '[foo]',
883
- 'string', '[]',
884
- null, ' hello'
885
- ]
886
- );
887
-
888
- // @todo It would be nice if, at some point, the document was actually
889
- // checked to see if the referenced link exists
890
-
891
- // Link label, for reference-style links (taken from documentation)
892
- //
893
- // No title
894
- MT.testMode(
895
- 'labelNoTitle',
896
- '[foo]: http://example.com/',
897
- [
898
- 'link', '[foo]:',
899
- null, ' ',
900
- 'string', 'http://example.com/'
901
- ]
902
- );
903
- // Space in ID and title
904
- MT.testMode(
905
- 'labelSpaceTitle',
906
- '[foo bar]: http://example.com/ "hello"',
907
- [
908
- 'link', '[foo bar]:',
909
- null, ' ',
910
- 'string', 'http://example.com/ "hello"'
911
- ]
912
- );
913
- // Double title
914
- MT.testMode(
915
- 'labelDoubleTitle',
916
- '[foo bar]: http://example.com/ "hello" "world"',
917
- [
918
- 'link', '[foo bar]:',
919
- null, ' ',
920
- 'string', 'http://example.com/ "hello"',
921
- null, ' "world"'
922
- ]
923
- );
924
- // Double quotes around title
925
- MT.testMode(
926
- 'labelTitleDoubleQuotes',
927
- '[foo]: http://example.com/ "bar"',
928
- [
929
- 'link', '[foo]:',
930
- null, ' ',
931
- 'string', 'http://example.com/ "bar"'
932
- ]
933
- );
934
- // Single quotes around title
935
- MT.testMode(
936
- 'labelTitleSingleQuotes',
937
- '[foo]: http://example.com/ \'bar\'',
938
- [
939
- 'link', '[foo]:',
940
- null, ' ',
941
- 'string', 'http://example.com/ \'bar\''
942
- ]
943
- );
944
- // Parentheses around title
945
- MT.testMode(
946
- 'labelTitleParenthese',
947
- '[foo]: http://example.com/ (bar)',
948
- [
949
- 'link', '[foo]:',
950
- null, ' ',
951
- 'string', 'http://example.com/ (bar)'
952
- ]
953
- );
954
- // Invalid title
955
- MT.testMode(
956
- 'labelTitleInvalid',
957
- '[foo]: http://example.com/ bar',
958
- [
959
- 'link', '[foo]:',
960
- null, ' ',
961
- 'string', 'http://example.com/',
962
- null, ' bar'
963
- ]
964
- );
965
- // Angle brackets around URL
966
- MT.testMode(
967
- 'labelLinkAngleBrackets',
968
- '[foo]: <http://example.com/> "bar"',
969
- [
970
- 'link', '[foo]:',
971
- null, ' ',
972
- 'string', '<http://example.com/> "bar"'
973
- ]
974
- );
975
- // Title on next line per documentation (double quotes)
976
- MT.testMode(
977
- 'labelTitleNextDoubleQuotes',
978
- '[foo]: http://example.com/\n"bar" hello',
979
- [
980
- 'link', '[foo]:',
981
- null, ' ',
982
- 'string', 'http://example.com/',
983
- 'string', '"bar"',
984
- null, ' hello'
985
- ]
986
- );
987
- // Title on next line per documentation (single quotes)
988
- MT.testMode(
989
- 'labelTitleNextSingleQuotes',
990
- '[foo]: http://example.com/\n\'bar\' hello',
991
- [
992
- 'link', '[foo]:',
993
- null, ' ',
994
- 'string', 'http://example.com/',
995
- 'string', '\'bar\'',
996
- null, ' hello'
997
- ]
998
- );
999
- // Title on next line per documentation (parentheses)
1000
- MT.testMode(
1001
- 'labelTitleNextParenthese',
1002
- '[foo]: http://example.com/\n(bar) hello',
1003
- [
1004
- 'link', '[foo]:',
1005
- null, ' ',
1006
- 'string', 'http://example.com/',
1007
- 'string', '(bar)',
1008
- null, ' hello'
1009
- ]
1010
- );
1011
- // Title on next line per documentation (mixed)
1012
- MT.testMode(
1013
- 'labelTitleNextMixed',
1014
- '[foo]: http://example.com/\n(bar" hello',
1015
- [
1016
- 'link', '[foo]:',
1017
- null, ' ',
1018
- 'string', 'http://example.com/',
1019
- null, '(bar" hello'
1020
- ]
1021
- );
1022
-
1023
- // Automatic links
1024
- MT.testMode(
1025
- 'linkWeb',
1026
- '<http://example.com/> foo',
1027
- [
1028
- 'link', '<http://example.com/>',
1029
- null, ' foo'
1030
- ]
1031
- );
1032
-
1033
- // Automatic email links
1034
- MT.testMode(
1035
- 'linkEmail',
1036
- '<user@example.com> foo',
1037
- [
1038
- 'link', '<user@example.com>',
1039
- null, ' foo'
1040
- ]
1041
- );
1042
-
1043
- // Single asterisk
1044
- MT.testMode(
1045
- 'emAsterisk',
1046
- '*foo* bar',
1047
- [
1048
- 'em', '*foo*',
1049
- null, ' bar'
1050
- ]
1051
- );
1052
-
1053
- // Single underscore
1054
- MT.testMode(
1055
- 'emUnderscore',
1056
- '_foo_ bar',
1057
- [
1058
- 'em', '_foo_',
1059
- null, ' bar'
1060
- ]
1061
- );
1062
-
1063
- // Emphasis characters within a word
1064
- MT.testMode(
1065
- 'emInWordAsterisk',
1066
- 'foo*bar*hello',
1067
- [
1068
- null, 'foo',
1069
- 'em', '*bar*',
1070
- null, 'hello'
1071
- ]
1072
- );
1073
- MT.testMode(
1074
- 'emInWordUnderscore',
1075
- 'foo_bar_hello',
1076
- [
1077
- null, 'foo',
1078
- 'em', '_bar_',
1079
- null, 'hello'
1080
- ]
1081
- );
1082
- // Per documentation: "...surround an * or _ with spaces, it’ll be
1083
- // treated as a literal asterisk or underscore."
1084
- //
1085
- // Inside EM
1086
- MT.testMode(
1087
- 'emEscapedBySpaceIn',
1088
- 'foo _bar _ hello_ world',
1089
- [
1090
- null, 'foo ',
1091
- 'em', '_bar _ hello_',
1092
- null, ' world'
1093
- ]
1094
- );
1095
- // Outside EM
1096
- MT.testMode(
1097
- 'emEscapedBySpaceOut',
1098
- 'foo _ bar_hello_world',
1099
- [
1100
- null, 'foo _ bar',
1101
- 'em', '_hello_',
1102
- null, 'world'
1103
- ]
1104
- );
1105
-
1106
- // Unclosed emphasis characters
1107
- // Instead of simply marking as EM / STRONG, it would be nice to have an
1108
- // incomplete flag for EM and STRONG, that is styled slightly different.
1109
- MT.testMode(
1110
- 'emIncompleteAsterisk',
1111
- 'foo *bar',
1112
- [
1113
- null, 'foo ',
1114
- 'em', '*bar'
1115
- ]
1116
- );
1117
- MT.testMode(
1118
- 'emIncompleteUnderscore',
1119
- 'foo _bar',
1120
- [
1121
- null, 'foo ',
1122
- 'em', '_bar'
1123
- ]
1124
- );
1125
-
1126
- // Double asterisk
1127
- MT.testMode(
1128
- 'strongAsterisk',
1129
- '**foo** bar',
1130
- [
1131
- 'strong', '**foo**',
1132
- null, ' bar'
1133
- ]
1134
- );
1135
-
1136
- // Double underscore
1137
- MT.testMode(
1138
- 'strongUnderscore',
1139
- '__foo__ bar',
1140
- [
1141
- 'strong', '__foo__',
1142
- null, ' bar'
1143
- ]
1144
- );
1145
-
1146
- // Triple asterisk
1147
- MT.testMode(
1148
- 'emStrongAsterisk',
1149
- '*foo**bar*hello** world',
1150
- [
1151
- 'em', '*foo',
1152
- 'emstrong', '**bar*',
1153
- 'strong', 'hello**',
1154
- null, ' world'
1155
- ]
1156
- );
1157
-
1158
- // Triple underscore
1159
- MT.testMode(
1160
- 'emStrongUnderscore',
1161
- '_foo__bar_hello__ world',
1162
- [
1163
- 'em', '_foo',
1164
- 'emstrong', '__bar_',
1165
- 'strong', 'hello__',
1166
- null, ' world'
1167
- ]
1168
- );
1169
-
1170
- // Triple mixed
1171
- // "...same character must be used to open and close an emphasis span.""
1172
- MT.testMode(
1173
- 'emStrongMixed',
1174
- '_foo**bar*hello__ world',
1175
- [
1176
- 'em', '_foo',
1177
- 'emstrong', '**bar*hello__ world'
1178
- ]
1179
- );
1180
-
1181
- MT.testMode(
1182
- 'emStrongMixed',
1183
- '*foo__bar_hello** world',
1184
- [
1185
- 'em', '*foo',
1186
- 'emstrong', '__bar_hello** world'
1187
- ]
1188
- );
1189
-
1190
- // These characters should be escaped:
1191
- // \ backslash
1192
- // ` backtick
1193
- // * asterisk
1194
- // _ underscore
1195
- // {} curly braces
1196
- // [] square brackets
1197
- // () parentheses
1198
- // # hash mark
1199
- // + plus sign
1200
- // - minus sign (hyphen)
1201
- // . dot
1202
- // ! exclamation mark
1203
- //
1204
- // Backtick (code)
1205
- MT.testMode(
1206
- 'escapeBacktick',
1207
- 'foo \\`bar\\`',
1208
- [
1209
- null, 'foo \\`bar\\`'
1210
- ]
1211
- );
1212
- MT.testMode(
1213
- 'doubleEscapeBacktick',
1214
- 'foo \\\\`bar\\\\`',
1215
- [
1216
- null, 'foo \\\\',
1217
- 'comment', '`bar\\\\`'
1218
- ]
1219
- );
1220
- // Asterisk (em)
1221
- MT.testMode(
1222
- 'escapeAsterisk',
1223
- 'foo \\*bar\\*',
1224
- [
1225
- null, 'foo \\*bar\\*'
1226
- ]
1227
- );
1228
- MT.testMode(
1229
- 'doubleEscapeAsterisk',
1230
- 'foo \\\\*bar\\\\*',
1231
- [
1232
- null, 'foo \\\\',
1233
- 'em', '*bar\\\\*'
1234
- ]
1235
- );
1236
- // Underscore (em)
1237
- MT.testMode(
1238
- 'escapeUnderscore',
1239
- 'foo \\_bar\\_',
1240
- [
1241
- null, 'foo \\_bar\\_'
1242
- ]
1243
- );
1244
- MT.testMode(
1245
- 'doubleEscapeUnderscore',
1246
- 'foo \\\\_bar\\\\_',
1247
- [
1248
- null, 'foo \\\\',
1249
- 'em', '_bar\\\\_'
1250
- ]
1251
- );
1252
- // Hash mark (headers)
1253
- MT.testMode(
1254
- 'escapeHash',
1255
- '\\# foo',
1256
- [
1257
- null, '\\# foo'
1258
- ]
1259
- );
1260
- MT.testMode(
1261
- 'doubleEscapeHash',
1262
- '\\\\# foo',
1263
- [
1264
- null, '\\\\# foo'
1265
- ]
1266
- );
1
+ (function() {
2
+ var mode = CodeMirror.getMode({tabSize: 4}, "markdown");
3
+ function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
4
+
5
+ MT("plainText",
6
+ "foo");
7
+
8
+ // Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)
9
+ MT("codeBlocksUsing4Spaces",
10
+ " [comment foo]");
11
+
12
+ // Code blocks using 4 spaces with internal indentation
13
+ MT("codeBlocksUsing4SpacesIndentation",
14
+ " [comment bar]",
15
+ " [comment hello]",
16
+ " [comment world]",
17
+ " [comment foo]",
18
+ "bar");
19
+
20
+ // Code blocks using 4 spaces with internal indentation
21
+ MT("codeBlocksUsing4SpacesIndentation",
22
+ " foo",
23
+ " [comment bar]",
24
+ " [comment hello]",
25
+ " [comment world]");
26
+
27
+ // Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
28
+ MT("codeBlocksUsing1Tab",
29
+ "\t[comment foo]");
30
+
31
+ // Inline code using backticks
32
+ MT("inlineCodeUsingBackticks",
33
+ "foo [comment `bar`]");
34
+
35
+ // Block code using single backtick (shouldn't work)
36
+ MT("blockCodeSingleBacktick",
37
+ "[comment `]",
38
+ "foo",
39
+ "[comment `]");
40
+
41
+ // Unclosed backticks
42
+ // Instead of simply marking as CODE, it would be nice to have an
43
+ // incomplete flag for CODE, that is styled slightly different.
44
+ MT("unclosedBackticks",
45
+ "foo [comment `bar]");
46
+
47
+ // Per documentation: "To include a literal backtick character within a
48
+ // code span, you can use multiple backticks as the opening and closing
49
+ // delimiters"
50
+ MT("doubleBackticks",
51
+ "[comment ``foo ` bar``]");
52
+
53
+ // Tests based on Dingus
54
+ // http://daringfireball.net/projects/markdown/dingus
55
+ //
56
+ // Multiple backticks within an inline code block
57
+ MT("consecutiveBackticks",
58
+ "[comment `foo```bar`]");
59
+
60
+ // Multiple backticks within an inline code block with a second code block
61
+ MT("consecutiveBackticks",
62
+ "[comment `foo```bar`] hello [comment `world`]");
63
+
64
+ // Unclosed with several different groups of backticks
65
+ MT("unclosedBackticks",
66
+ "[comment ``foo ``` bar` hello]");
67
+
68
+ // Closed with several different groups of backticks
69
+ MT("closedBackticks",
70
+ "[comment ``foo ``` bar` hello``] world");
71
+
72
+ // atx headers
73
+ // http://daringfireball.net/projects/markdown/syntax#header
74
+
75
+ MT("atxH1",
76
+ "[header # foo]");
77
+
78
+ MT("atxH2",
79
+ "[header ## foo]");
80
+
81
+ MT("atxH3",
82
+ "[header ### foo]");
83
+
84
+ MT("atxH4",
85
+ "[header #### foo]");
86
+
87
+ MT("atxH5",
88
+ "[header ##### foo]");
89
+
90
+ MT("atxH6",
91
+ "[header ###### foo]");
92
+
93
+ // H6 - 7x '#' should still be H6, per Dingus
94
+ // http://daringfireball.net/projects/markdown/dingus
95
+ MT("atxH6NotH7",
96
+ "[header ####### foo]");
97
+
98
+ // Setext headers - H1, H2
99
+ // Per documentation, "Any number of underlining =’s or -’s will work."
100
+ // http://daringfireball.net/projects/markdown/syntax#header
101
+ // Ideally, the text would be marked as `header` as well, but this is
102
+ // not really feasible at the moment. So, instead, we're testing against
103
+ // what works today, to avoid any regressions.
104
+ //
105
+ // Check if single underlining = works
106
+ MT("setextH1",
107
+ "foo",
108
+ "[header =]");
109
+
110
+ // Check if 3+ ='s work
111
+ MT("setextH1",
112
+ "foo",
113
+ "[header ===]");
114
+
115
+ // Check if single underlining - works
116
+ MT("setextH2",
117
+ "foo",
118
+ "[header -]");
119
+
120
+ // Check if 3+ -'s work
121
+ MT("setextH2",
122
+ "foo",
123
+ "[header ---]");
124
+
125
+ // Single-line blockquote with trailing space
126
+ MT("blockquoteSpace",
127
+ "[quote > foo]");
128
+
129
+ // Single-line blockquote
130
+ MT("blockquoteNoSpace",
131
+ "[quote >foo]");
132
+
133
+ // Single-line blockquote followed by normal paragraph
134
+ MT("blockquoteThenParagraph",
135
+ "[quote >foo]",
136
+ "",
137
+ "bar");
138
+
139
+ // Multi-line blockquote (lazy mode)
140
+ MT("multiBlockquoteLazy",
141
+ "[quote >foo]",
142
+ "[quote bar]");
143
+
144
+ // Multi-line blockquote followed by normal paragraph (lazy mode)
145
+ MT("multiBlockquoteLazyThenParagraph",
146
+ "[quote >foo]",
147
+ "[quote bar]",
148
+ "",
149
+ "hello");
150
+
151
+ // Multi-line blockquote (non-lazy mode)
152
+ MT("multiBlockquote",
153
+ "[quote >foo]",
154
+ "[quote >bar]");
155
+
156
+ // Multi-line blockquote followed by normal paragraph (non-lazy mode)
157
+ MT("multiBlockquoteThenParagraph",
158
+ "[quote >foo]",
159
+ "[quote >bar]",
160
+ "",
161
+ "hello");
162
+
163
+ // Check list types
164
+
165
+ MT("listAsterisk",
166
+ "[string * foo]",
167
+ "[string * bar]");
168
+
169
+ MT("listPlus",
170
+ "[string + foo]",
171
+ "[string + bar]");
172
+
173
+ MT("listDash",
174
+ "[string - foo]",
175
+ "[string - bar]");
176
+
177
+ MT("listNumber",
178
+ "[string 1. foo]",
179
+ "[string 2. bar]");
180
+
181
+ // Formatting in lists (*)
182
+ MT("listAsteriskFormatting",
183
+ "[string * ][string&em *foo*][string bar]",
184
+ "[string * ][string&strong **foo**][string bar]",
185
+ "[string * ][string&strong **][string&emstrong *foo**][string&em *][string bar]",
186
+ "[string * ][string&comment `foo`][string bar]");
187
+
188
+ // Formatting in lists (+)
189
+ MT("listPlusFormatting",
190
+ "[string + ][string&em *foo*][string bar]",
191
+ "[string + ][string&strong **foo**][string bar]",
192
+ "[string + ][string&strong **][string&emstrong *foo**][string&em *][string bar]",
193
+ "[string + ][string&comment `foo`][string bar]");
194
+
195
+ // Formatting in lists (-)
196
+ MT("listDashFormatting",
197
+ "[string - ][string&em *foo*][string bar]",
198
+ "[string - ][string&strong **foo**][string bar]",
199
+ "[string - ][string&strong **][string&emstrong *foo**][string&em *][string bar]",
200
+ "[string - ][string&comment `foo`][string bar]");
201
+
202
+ // Formatting in lists (1.)
203
+ MT("listNumberFormatting",
204
+ "[string 1. ][string&em *foo*][string bar]",
205
+ "[string 2. ][string&strong **foo**][string bar]",
206
+ "[string 3. ][string&strong **][string&emstrong *foo**][string&em *][string bar]",
207
+ "[string 4. ][string&comment `foo`][string bar]");
208
+
209
+ // Paragraph lists
210
+ MT("listParagraph",
211
+ "[string * foo]",
212
+ "",
213
+ "[string * bar]");
214
+
215
+ // Multi-paragraph lists
216
+ //
217
+ // 4 spaces
218
+ MT("listMultiParagraph",
219
+ "[string * foo]",
220
+ "",
221
+ "[string * bar]",
222
+ "",
223
+ " [string hello]");
224
+
225
+ // 4 spaces, extra blank lines (should still be list, per Dingus)
226
+ MT("listMultiParagraphExtra",
227
+ "[string * foo]",
228
+ "",
229
+ "[string * bar]",
230
+ "",
231
+ " [string hello]");
232
+
233
+ // 4 spaces, plus 1 space (should still be list, per Dingus)
234
+ MT("listMultiParagraphExtraSpace",
235
+ "[string * foo]",
236
+ "",
237
+ "[string * bar]",
238
+ "",
239
+ " [string hello]",
240
+ "",
241
+ " [string world]");
242
+
243
+ // 1 tab
244
+ MT("listTab",
245
+ "[string * foo]",
246
+ "",
247
+ "[string * bar]",
248
+ "",
249
+ "\t[string hello]");
250
+
251
+ // No indent
252
+ MT("listNoIndent",
253
+ "[string * foo]",
254
+ "",
255
+ "[string * bar]",
256
+ "",
257
+ "hello");
258
+
259
+ // Blockquote
260
+ MT("blockquote",
261
+ "[string * foo]",
262
+ "",
263
+ "[string * bar]",
264
+ "",
265
+ " [string&quote > hello]");
266
+
267
+ // Code block
268
+ MT("blockquoteCode",
269
+ "[string * foo]",
270
+ "",
271
+ "[string * bar]",
272
+ "",
273
+ " [comment > hello]",
274
+ "",
275
+ " [string world]");
276
+
277
+ // Code block followed by text
278
+ MT("blockquoteCodeText",
279
+ "[string * foo]",
280
+ "",
281
+ " [string bar]",
282
+ "",
283
+ " [comment hello]",
284
+ "",
285
+ " [string world]");
286
+
287
+ // Nested list
288
+
289
+ MT("listAsteriskNested",
290
+ "[string * foo]",
291
+ "",
292
+ " [string * bar]");
293
+
294
+ MT("listPlusNested",
295
+ "[string + foo]",
296
+ "",
297
+ " [string + bar]");
298
+
299
+ MT("listDashNested",
300
+ "[string - foo]",
301
+ "",
302
+ " [string - bar]");
303
+
304
+ MT("listNumberNested",
305
+ "[string 1. foo]",
306
+ "",
307
+ " [string 2. bar]");
308
+
309
+ MT("listMixed",
310
+ "[string * foo]",
311
+ "",
312
+ " [string + bar]",
313
+ "",
314
+ " [string - hello]",
315
+ "",
316
+ " [string 1. world]");
317
+
318
+ MT("listBlockquote",
319
+ "[string * foo]",
320
+ "",
321
+ " [string + bar]",
322
+ "",
323
+ " [quote&string > hello]");
324
+
325
+ MT("listCode",
326
+ "[string * foo]",
327
+ "",
328
+ " [string + bar]",
329
+ "",
330
+ " [comment hello]");
331
+
332
+ // Code with internal indentation
333
+ MT("listCodeIndentation",
334
+ "[string * foo]",
335
+ "",
336
+ " [comment bar]",
337
+ " [comment hello]",
338
+ " [comment world]",
339
+ " [comment foo]",
340
+ " [string bar]");
341
+
342
+ // Code followed by text
343
+ MT("listCodeText",
344
+ "[string * foo]",
345
+ "",
346
+ " [comment bar]",
347
+ "",
348
+ "hello");
349
+
350
+ // Following tests directly from official Markdown documentation
351
+ // http://daringfireball.net/projects/markdown/syntax#hr
352
+
353
+ MT("hrSpace",
354
+ "[hr * * *]");
355
+
356
+ MT("hr",
357
+ "[hr ***]");
358
+
359
+ MT("hrLong",
360
+ "[hr *****]");
361
+
362
+ MT("hrSpaceDash",
363
+ "[hr - - -]");
364
+
365
+ MT("hrDashLong",
366
+ "[hr ---------------------------------------]");
367
+
368
+ // Inline link with title
369
+ MT("linkTitle",
370
+ "[link [[foo]]][string (http://example.com/ \"bar\")] hello");
371
+
372
+ // Inline link without title
373
+ MT("linkNoTitle",
374
+ "[link [[foo]]][string (http://example.com/)] bar");
375
+
376
+ // Inline link with image
377
+ MT("linkImage",
378
+ "[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar");
379
+
380
+ // Inline link with Em
381
+ MT("linkEm",
382
+ "[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar");
383
+
384
+ // Inline link with Strong
385
+ MT("linkStrong",
386
+ "[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar");
387
+
388
+ // Inline link with EmStrong
389
+ MT("linkEmStrong",
390
+ "[link [[][link&strong **][link&emstrong *foo**][link&em *][link ]]][string (http://example.com/)] bar");
391
+
392
+ // Image with title
393
+ MT("imageTitle",
394
+ "[tag ![[foo]]][string (http://example.com/ \"bar\")] hello");
395
+
396
+ // Image without title
397
+ MT("imageNoTitle",
398
+ "[tag ![[foo]]][string (http://example.com/)] bar");
399
+
400
+ // Image with asterisks
401
+ MT("imageAsterisks",
402
+ "[tag ![[*foo*]]][string (http://example.com/)] bar");
403
+
404
+ // Not a link. Should be normal text due to square brackets being used
405
+ // regularly in text, especially in quoted material, and no space is allowed
406
+ // between square brackets and parentheses (per Dingus).
407
+ MT("notALink",
408
+ "[[foo]] (bar)");
409
+
410
+ // Reference-style links
411
+ MT("linkReference",
412
+ "[link [[foo]]][string [[bar]]] hello");
413
+
414
+ // Reference-style links with Em
415
+ MT("linkReferenceEm",
416
+ "[link [[][link&em *foo*][link ]]][string [[bar]]] hello");
417
+
418
+ // Reference-style links with Strong
419
+ MT("linkReferenceStrong",
420
+ "[link [[][link&strong **foo**][link ]]][string [[bar]]] hello");
421
+
422
+ // Reference-style links with EmStrong
423
+ MT("linkReferenceEmStrong",
424
+ "[link [[][link&strong **][link&emstrong *foo**][link&em *][link ]]][string [[bar]]] hello");
425
+
426
+ // Reference-style links with optional space separator (per docuentation)
427
+ // "You can optionally use a space to separate the sets of brackets"
428
+ MT("linkReferenceSpace",
429
+ "[link [[foo]]] [string [[bar]]] hello");
430
+
431
+ // Should only allow a single space ("...use *a* space...")
432
+ MT("linkReferenceDoubleSpace",
433
+ "[[foo]] [[bar]] hello");
434
+
435
+ // Reference-style links with implicit link name
436
+ MT("linkImplicit",
437
+ "[link [[foo]]][string [[]]] hello");
438
+
439
+ // @todo It would be nice if, at some point, the document was actually
440
+ // checked to see if the referenced link exists
441
+
442
+ // Link label, for reference-style links (taken from documentation)
443
+
444
+ MT("labelNoTitle",
445
+ "[link [[foo]]:] [string http://example.com/]");
446
+
447
+ MT("labelIndented",
448
+ " [link [[foo]]:] [string http://example.com/]");
449
+
450
+ MT("labelSpaceTitle",
451
+ "[link [[foo bar]]:] [string http://example.com/ \"hello\"]");
452
+
453
+ MT("labelDoubleTitle",
454
+ "[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\"");
455
+
456
+ MT("labelTitleDoubleQuotes",
457
+ "[link [[foo]]:] [string http://example.com/ \"bar\"]");
458
+
459
+ MT("labelTitleSingleQuotes",
460
+ "[link [[foo]]:] [string http://example.com/ 'bar']");
461
+
462
+ MT("labelTitleParenthese",
463
+ "[link [[foo]]:] [string http://example.com/ (bar)]");
464
+
465
+ MT("labelTitleInvalid",
466
+ "[link [[foo]]:] [string http://example.com/] bar");
467
+
468
+ MT("labelLinkAngleBrackets",
469
+ "[link [[foo]]:] [string <http://example.com/> \"bar\"]");
470
+
471
+ MT("labelTitleNextDoubleQuotes",
472
+ "[link [[foo]]:] [string http://example.com/]",
473
+ "[string \"bar\"] hello");
474
+
475
+ MT("labelTitleNextSingleQuotes",
476
+ "[link [[foo]]:] [string http://example.com/]",
477
+ "[string 'bar'] hello");
478
+
479
+ MT("labelTitleNextParenthese",
480
+ "[link [[foo]]:] [string http://example.com/]",
481
+ "[string (bar)] hello");
482
+
483
+ MT("labelTitleNextMixed",
484
+ "[link [[foo]]:] [string http://example.com/]",
485
+ "(bar\" hello");
486
+
487
+ MT("linkWeb",
488
+ "[link <http://example.com/>] foo");
489
+
490
+ MT("linkEmail",
491
+ "[link <user@example.com>] foo");
492
+
493
+ MT("emAsterisk",
494
+ "[em *foo*] bar");
495
+
496
+ MT("emUnderscore",
497
+ "[em _foo_] bar");
498
+
499
+ MT("emInWordAsterisk",
500
+ "foo[em *bar*]hello");
501
+
502
+ MT("emInWordUnderscore",
503
+ "foo[em _bar_]hello");
504
+
505
+ // Per documentation: "...surround an * or _ with spaces, it’ll be
506
+ // treated as a literal asterisk or underscore."
507
+
508
+ MT("emEscapedBySpaceIn",
509
+ "foo [em _bar _ hello_] world");
510
+
511
+ MT("emEscapedBySpaceOut",
512
+ "foo _ bar[em _hello_]world");
513
+
514
+ // Unclosed emphasis characters
515
+ // Instead of simply marking as EM / STRONG, it would be nice to have an
516
+ // incomplete flag for EM and STRONG, that is styled slightly different.
517
+ MT("emIncompleteAsterisk",
518
+ "foo [em *bar]");
519
+
520
+ MT("emIncompleteUnderscore",
521
+ "foo [em _bar]");
522
+
523
+ MT("strongAsterisk",
524
+ "[strong **foo**] bar");
525
+
526
+ MT("strongUnderscore",
527
+ "[strong __foo__] bar");
528
+
529
+ MT("emStrongAsterisk",
530
+ "[em *foo][emstrong **bar*][strong hello**] world");
531
+
532
+ MT("emStrongUnderscore",
533
+ "[em _foo][emstrong __bar_][strong hello__] world");
534
+
535
+ // "...same character must be used to open and close an emphasis span.""
536
+ MT("emStrongMixed",
537
+ "[em _foo][emstrong **bar*hello__ world]");
538
+
539
+ MT("emStrongMixed",
540
+ "[em *foo][emstrong __bar_hello** world]");
541
+
542
+ // These characters should be escaped:
543
+ // \ backslash
544
+ // ` backtick
545
+ // * asterisk
546
+ // _ underscore
547
+ // {} curly braces
548
+ // [] square brackets
549
+ // () parentheses
550
+ // # hash mark
551
+ // + plus sign
552
+ // - minus sign (hyphen)
553
+ // . dot
554
+ // ! exclamation mark
555
+
556
+ MT("escapeBacktick",
557
+ "foo \\`bar\\`");
558
+
559
+ MT("doubleEscapeBacktick",
560
+ "foo \\\\[comment `bar\\\\`]");
561
+
562
+ MT("escapeAsterisk",
563
+ "foo \\*bar\\*");
564
+
565
+ MT("doubleEscapeAsterisk",
566
+ "foo \\\\[em *bar\\\\*]");
567
+
568
+ MT("escapeUnderscore",
569
+ "foo \\_bar\\_");
570
+
571
+ MT("doubleEscapeUnderscore",
572
+ "foo \\\\[em _bar\\\\_]");
573
+
574
+ MT("escapeHash",
575
+ "\\# foo");
576
+
577
+ MT("doubleEscapeHash",
578
+ "\\\\# foo");
579
+ })();