Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/markdown/test.js
1294 views
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
var modeHighlightFormatting = CodeMirror.getMode({tabSize: 4}, {name: "markdown", highlightFormatting: true});
5
function FT(name) { test.mode(name, modeHighlightFormatting, Array.prototype.slice.call(arguments, 1)); }
6
7
FT("formatting_emAsterisk",
8
"[em&formatting&formatting-em *][em foo][em&formatting&formatting-em *]");
9
10
FT("formatting_emUnderscore",
11
"[em&formatting&formatting-em _][em foo][em&formatting&formatting-em _]");
12
13
FT("formatting_strongAsterisk",
14
"[strong&formatting&formatting-strong **][strong foo][strong&formatting&formatting-strong **]");
15
16
FT("formatting_strongUnderscore",
17
"[strong&formatting&formatting-strong __][strong foo][strong&formatting&formatting-strong __]");
18
19
FT("formatting_codeBackticks",
20
"[comment&formatting&formatting-code `][comment foo][comment&formatting&formatting-code `]");
21
22
FT("formatting_doubleBackticks",
23
"[comment&formatting&formatting-code ``][comment foo ` bar][comment&formatting&formatting-code ``]");
24
25
FT("formatting_atxHeader",
26
"[header&header1&formatting&formatting-header&formatting-header1 #][header&header1 foo # bar ][header&header1&formatting&formatting-header&formatting-header1 #]");
27
28
FT("formatting_setextHeader",
29
"foo",
30
"[header&header1&formatting&formatting-header&formatting-header1 =]");
31
32
FT("formatting_blockquote",
33
"[quote&quote-1&formatting&formatting-quote&formatting-quote-1 > ][quote&quote-1 foo]");
34
35
FT("formatting_list",
36
"[variable-2&formatting&formatting-list&formatting-list-ul - ][variable-2 foo]");
37
FT("formatting_list",
38
"[variable-2&formatting&formatting-list&formatting-list-ol 1. ][variable-2 foo]");
39
40
FT("formatting_link",
41
"[link&formatting&formatting-link [][link foo][link&formatting&formatting-link ]]][string&formatting&formatting-link-string (][string http://example.com/][string&formatting&formatting-link-string )]");
42
43
FT("formatting_linkReference",
44
"[link&formatting&formatting-link [][link foo][link&formatting&formatting-link ]]][string&formatting&formatting-link-string [][string bar][string&formatting&formatting-link-string ]]]",
45
"[link&formatting&formatting-link [][link bar][link&formatting&formatting-link ]]:] [string http://example.com/]");
46
47
FT("formatting_linkWeb",
48
"[link&formatting&formatting-link <][link http://example.com/][link&formatting&formatting-link >]");
49
50
FT("formatting_linkEmail",
51
"[link&formatting&formatting-link <][link [email protected]][link&formatting&formatting-link >]");
52
53
FT("formatting_escape",
54
"[formatting&formatting-escape \\]*");
55
56
MT("plainText",
57
"foo");
58
59
// Don't style single trailing space
60
MT("trailingSpace1",
61
"foo ");
62
63
// Two or more trailing spaces should be styled with line break character
64
MT("trailingSpace2",
65
"foo[trailing-space-a ][trailing-space-new-line ]");
66
67
MT("trailingSpace3",
68
"foo[trailing-space-a ][trailing-space-b ][trailing-space-new-line ]");
69
70
MT("trailingSpace4",
71
"foo[trailing-space-a ][trailing-space-b ][trailing-space-a ][trailing-space-new-line ]");
72
73
// Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)
74
MT("codeBlocksUsing4Spaces",
75
" [comment foo]");
76
77
// Code blocks using 4 spaces with internal indentation
78
MT("codeBlocksUsing4SpacesIndentation",
79
" [comment bar]",
80
" [comment hello]",
81
" [comment world]",
82
" [comment foo]",
83
"bar");
84
85
// Code blocks using 4 spaces with internal indentation
86
MT("codeBlocksUsing4SpacesIndentation",
87
" foo",
88
" [comment bar]",
89
" [comment hello]",
90
" [comment world]");
91
92
// Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
93
MT("codeBlocksUsing1Tab",
94
"\t[comment foo]");
95
96
// Inline code using backticks
97
MT("inlineCodeUsingBackticks",
98
"foo [comment `bar`]");
99
100
// Block code using single backtick (shouldn't work)
101
MT("blockCodeSingleBacktick",
102
"[comment `]",
103
"foo",
104
"[comment `]");
105
106
// Unclosed backticks
107
// Instead of simply marking as CODE, it would be nice to have an
108
// incomplete flag for CODE, that is styled slightly different.
109
MT("unclosedBackticks",
110
"foo [comment `bar]");
111
112
// Per documentation: "To include a literal backtick character within a
113
// code span, you can use multiple backticks as the opening and closing
114
// delimiters"
115
MT("doubleBackticks",
116
"[comment ``foo ` bar``]");
117
118
// Tests based on Dingus
119
// http://daringfireball.net/projects/markdown/dingus
120
//
121
// Multiple backticks within an inline code block
122
MT("consecutiveBackticks",
123
"[comment `foo```bar`]");
124
125
// Multiple backticks within an inline code block with a second code block
126
MT("consecutiveBackticks",
127
"[comment `foo```bar`] hello [comment `world`]");
128
129
// Unclosed with several different groups of backticks
130
MT("unclosedBackticks",
131
"[comment ``foo ``` bar` hello]");
132
133
// Closed with several different groups of backticks
134
MT("closedBackticks",
135
"[comment ``foo ``` bar` hello``] world");
136
137
// atx headers
138
// http://daringfireball.net/projects/markdown/syntax#header
139
140
MT("atxH1",
141
"[header&header1 # foo]");
142
143
MT("atxH2",
144
"[header&header2 ## foo]");
145
146
MT("atxH3",
147
"[header&header3 ### foo]");
148
149
MT("atxH4",
150
"[header&header4 #### foo]");
151
152
MT("atxH5",
153
"[header&header5 ##### foo]");
154
155
MT("atxH6",
156
"[header&header6 ###### foo]");
157
158
// H6 - 7x '#' should still be H6, per Dingus
159
// http://daringfireball.net/projects/markdown/dingus
160
MT("atxH6NotH7",
161
"[header&header6 ####### foo]");
162
163
// Inline styles should be parsed inside headers
164
MT("atxH1inline",
165
"[header&header1 # foo ][header&header1&em *bar*]");
166
167
// Setext headers - H1, H2
168
// Per documentation, "Any number of underlining =’s or -’s will work."
169
// http://daringfireball.net/projects/markdown/syntax#header
170
// Ideally, the text would be marked as `header` as well, but this is
171
// not really feasible at the moment. So, instead, we're testing against
172
// what works today, to avoid any regressions.
173
//
174
// Check if single underlining = works
175
MT("setextH1",
176
"foo",
177
"[header&header1 =]");
178
179
// Check if 3+ ='s work
180
MT("setextH1",
181
"foo",
182
"[header&header1 ===]");
183
184
// Check if single underlining - works
185
MT("setextH2",
186
"foo",
187
"[header&header2 -]");
188
189
// Check if 3+ -'s work
190
MT("setextH2",
191
"foo",
192
"[header&header2 ---]");
193
194
// Single-line blockquote with trailing space
195
MT("blockquoteSpace",
196
"[quote&quote-1 > foo]");
197
198
// Single-line blockquote
199
MT("blockquoteNoSpace",
200
"[quote&quote-1 >foo]");
201
202
// No blank line before blockquote
203
MT("blockquoteNoBlankLine",
204
"foo",
205
"[quote&quote-1 > bar]");
206
207
// Nested blockquote
208
MT("blockquoteSpace",
209
"[quote&quote-1 > foo]",
210
"[quote&quote-1 >][quote&quote-2 > foo]",
211
"[quote&quote-1 >][quote&quote-2 >][quote&quote-3 > foo]");
212
213
// Single-line blockquote followed by normal paragraph
214
MT("blockquoteThenParagraph",
215
"[quote&quote-1 >foo]",
216
"",
217
"bar");
218
219
// Multi-line blockquote (lazy mode)
220
MT("multiBlockquoteLazy",
221
"[quote&quote-1 >foo]",
222
"[quote&quote-1 bar]");
223
224
// Multi-line blockquote followed by normal paragraph (lazy mode)
225
MT("multiBlockquoteLazyThenParagraph",
226
"[quote&quote-1 >foo]",
227
"[quote&quote-1 bar]",
228
"",
229
"hello");
230
231
// Multi-line blockquote (non-lazy mode)
232
MT("multiBlockquote",
233
"[quote&quote-1 >foo]",
234
"[quote&quote-1 >bar]");
235
236
// Multi-line blockquote followed by normal paragraph (non-lazy mode)
237
MT("multiBlockquoteThenParagraph",
238
"[quote&quote-1 >foo]",
239
"[quote&quote-1 >bar]",
240
"",
241
"hello");
242
243
// Check list types
244
245
MT("listAsterisk",
246
"foo",
247
"bar",
248
"",
249
"[variable-2 * foo]",
250
"[variable-2 * bar]");
251
252
MT("listPlus",
253
"foo",
254
"bar",
255
"",
256
"[variable-2 + foo]",
257
"[variable-2 + bar]");
258
259
MT("listDash",
260
"foo",
261
"bar",
262
"",
263
"[variable-2 - foo]",
264
"[variable-2 - bar]");
265
266
MT("listNumber",
267
"foo",
268
"bar",
269
"",
270
"[variable-2 1. foo]",
271
"[variable-2 2. bar]");
272
273
// Lists require a preceding blank line (per Dingus)
274
MT("listBogus",
275
"foo",
276
"1. bar",
277
"2. hello");
278
279
// List after header
280
MT("listAfterHeader",
281
"[header&header1 # foo]",
282
"[variable-2 - bar]");
283
284
// Formatting in lists (*)
285
MT("listAsteriskFormatting",
286
"[variable-2 * ][variable-2&em *foo*][variable-2 bar]",
287
"[variable-2 * ][variable-2&strong **foo**][variable-2 bar]",
288
"[variable-2 * ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
289
"[variable-2 * ][variable-2&comment `foo`][variable-2 bar]");
290
291
// Formatting in lists (+)
292
MT("listPlusFormatting",
293
"[variable-2 + ][variable-2&em *foo*][variable-2 bar]",
294
"[variable-2 + ][variable-2&strong **foo**][variable-2 bar]",
295
"[variable-2 + ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
296
"[variable-2 + ][variable-2&comment `foo`][variable-2 bar]");
297
298
// Formatting in lists (-)
299
MT("listDashFormatting",
300
"[variable-2 - ][variable-2&em *foo*][variable-2 bar]",
301
"[variable-2 - ][variable-2&strong **foo**][variable-2 bar]",
302
"[variable-2 - ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
303
"[variable-2 - ][variable-2&comment `foo`][variable-2 bar]");
304
305
// Formatting in lists (1.)
306
MT("listNumberFormatting",
307
"[variable-2 1. ][variable-2&em *foo*][variable-2 bar]",
308
"[variable-2 2. ][variable-2&strong **foo**][variable-2 bar]",
309
"[variable-2 3. ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
310
"[variable-2 4. ][variable-2&comment `foo`][variable-2 bar]");
311
312
// Paragraph lists
313
MT("listParagraph",
314
"[variable-2 * foo]",
315
"",
316
"[variable-2 * bar]");
317
318
// Multi-paragraph lists
319
//
320
// 4 spaces
321
MT("listMultiParagraph",
322
"[variable-2 * foo]",
323
"",
324
"[variable-2 * bar]",
325
"",
326
" [variable-2 hello]");
327
328
// 4 spaces, extra blank lines (should still be list, per Dingus)
329
MT("listMultiParagraphExtra",
330
"[variable-2 * foo]",
331
"",
332
"[variable-2 * bar]",
333
"",
334
"",
335
" [variable-2 hello]");
336
337
// 4 spaces, plus 1 space (should still be list, per Dingus)
338
MT("listMultiParagraphExtraSpace",
339
"[variable-2 * foo]",
340
"",
341
"[variable-2 * bar]",
342
"",
343
" [variable-2 hello]",
344
"",
345
" [variable-2 world]");
346
347
// 1 tab
348
MT("listTab",
349
"[variable-2 * foo]",
350
"",
351
"[variable-2 * bar]",
352
"",
353
"\t[variable-2 hello]");
354
355
// No indent
356
MT("listNoIndent",
357
"[variable-2 * foo]",
358
"",
359
"[variable-2 * bar]",
360
"",
361
"hello");
362
363
// Blockquote
364
MT("blockquote",
365
"[variable-2 * foo]",
366
"",
367
"[variable-2 * bar]",
368
"",
369
" [variable-2&quote&quote-1 > hello]");
370
371
// Code block
372
MT("blockquoteCode",
373
"[variable-2 * foo]",
374
"",
375
"[variable-2 * bar]",
376
"",
377
" [comment > hello]",
378
"",
379
" [variable-2 world]");
380
381
// Code block followed by text
382
MT("blockquoteCodeText",
383
"[variable-2 * foo]",
384
"",
385
" [variable-2 bar]",
386
"",
387
" [comment hello]",
388
"",
389
" [variable-2 world]");
390
391
// Nested list
392
393
MT("listAsteriskNested",
394
"[variable-2 * foo]",
395
"",
396
" [variable-3 * bar]");
397
398
MT("listPlusNested",
399
"[variable-2 + foo]",
400
"",
401
" [variable-3 + bar]");
402
403
MT("listDashNested",
404
"[variable-2 - foo]",
405
"",
406
" [variable-3 - bar]");
407
408
MT("listNumberNested",
409
"[variable-2 1. foo]",
410
"",
411
" [variable-3 2. bar]");
412
413
MT("listMixed",
414
"[variable-2 * foo]",
415
"",
416
" [variable-3 + bar]",
417
"",
418
" [keyword - hello]",
419
"",
420
" [variable-2 1. world]");
421
422
MT("listBlockquote",
423
"[variable-2 * foo]",
424
"",
425
" [variable-3 + bar]",
426
"",
427
" [quote&quote-1&variable-3 > hello]");
428
429
MT("listCode",
430
"[variable-2 * foo]",
431
"",
432
" [variable-3 + bar]",
433
"",
434
" [comment hello]");
435
436
// Code with internal indentation
437
MT("listCodeIndentation",
438
"[variable-2 * foo]",
439
"",
440
" [comment bar]",
441
" [comment hello]",
442
" [comment world]",
443
" [comment foo]",
444
" [variable-2 bar]");
445
446
// List nesting edge cases
447
MT("listNested",
448
"[variable-2 * foo]",
449
"",
450
" [variable-3 * bar]",
451
"",
452
" [variable-2 hello]"
453
);
454
MT("listNested",
455
"[variable-2 * foo]",
456
"",
457
" [variable-3 * bar]",
458
"",
459
" [variable-3 * foo]"
460
);
461
462
// Code followed by text
463
MT("listCodeText",
464
"[variable-2 * foo]",
465
"",
466
" [comment bar]",
467
"",
468
"hello");
469
470
// Following tests directly from official Markdown documentation
471
// http://daringfireball.net/projects/markdown/syntax#hr
472
473
MT("hrSpace",
474
"[hr * * *]");
475
476
MT("hr",
477
"[hr ***]");
478
479
MT("hrLong",
480
"[hr *****]");
481
482
MT("hrSpaceDash",
483
"[hr - - -]");
484
485
MT("hrDashLong",
486
"[hr ---------------------------------------]");
487
488
// Inline link with title
489
MT("linkTitle",
490
"[link [[foo]]][string (http://example.com/ \"bar\")] hello");
491
492
// Inline link without title
493
MT("linkNoTitle",
494
"[link [[foo]]][string (http://example.com/)] bar");
495
496
// Inline link with image
497
MT("linkImage",
498
"[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar");
499
500
// Inline link with Em
501
MT("linkEm",
502
"[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar");
503
504
// Inline link with Strong
505
MT("linkStrong",
506
"[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar");
507
508
// Inline link with EmStrong
509
MT("linkEmStrong",
510
"[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string (http://example.com/)] bar");
511
512
// Image with title
513
MT("imageTitle",
514
"[tag ![[foo]]][string (http://example.com/ \"bar\")] hello");
515
516
// Image without title
517
MT("imageNoTitle",
518
"[tag ![[foo]]][string (http://example.com/)] bar");
519
520
// Image with asterisks
521
MT("imageAsterisks",
522
"[tag ![[*foo*]]][string (http://example.com/)] bar");
523
524
// Not a link. Should be normal text due to square brackets being used
525
// regularly in text, especially in quoted material, and no space is allowed
526
// between square brackets and parentheses (per Dingus).
527
MT("notALink",
528
"[[foo]] (bar)");
529
530
// Reference-style links
531
MT("linkReference",
532
"[link [[foo]]][string [[bar]]] hello");
533
534
// Reference-style links with Em
535
MT("linkReferenceEm",
536
"[link [[][link&em *foo*][link ]]][string [[bar]]] hello");
537
538
// Reference-style links with Strong
539
MT("linkReferenceStrong",
540
"[link [[][link&strong **foo**][link ]]][string [[bar]]] hello");
541
542
// Reference-style links with EmStrong
543
MT("linkReferenceEmStrong",
544
"[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string [[bar]]] hello");
545
546
// Reference-style links with optional space separator (per docuentation)
547
// "You can optionally use a space to separate the sets of brackets"
548
MT("linkReferenceSpace",
549
"[link [[foo]]] [string [[bar]]] hello");
550
551
// Should only allow a single space ("...use *a* space...")
552
MT("linkReferenceDoubleSpace",
553
"[[foo]] [[bar]] hello");
554
555
// Reference-style links with implicit link name
556
MT("linkImplicit",
557
"[link [[foo]]][string [[]]] hello");
558
559
// @todo It would be nice if, at some point, the document was actually
560
// checked to see if the referenced link exists
561
562
// Link label, for reference-style links (taken from documentation)
563
564
MT("labelNoTitle",
565
"[link [[foo]]:] [string http://example.com/]");
566
567
MT("labelIndented",
568
" [link [[foo]]:] [string http://example.com/]");
569
570
MT("labelSpaceTitle",
571
"[link [[foo bar]]:] [string http://example.com/ \"hello\"]");
572
573
MT("labelDoubleTitle",
574
"[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\"");
575
576
MT("labelTitleDoubleQuotes",
577
"[link [[foo]]:] [string http://example.com/ \"bar\"]");
578
579
MT("labelTitleSingleQuotes",
580
"[link [[foo]]:] [string http://example.com/ 'bar']");
581
582
MT("labelTitleParenthese",
583
"[link [[foo]]:] [string http://example.com/ (bar)]");
584
585
MT("labelTitleInvalid",
586
"[link [[foo]]:] [string http://example.com/] bar");
587
588
MT("labelLinkAngleBrackets",
589
"[link [[foo]]:] [string <http://example.com/> \"bar\"]");
590
591
MT("labelTitleNextDoubleQuotes",
592
"[link [[foo]]:] [string http://example.com/]",
593
"[string \"bar\"] hello");
594
595
MT("labelTitleNextSingleQuotes",
596
"[link [[foo]]:] [string http://example.com/]",
597
"[string 'bar'] hello");
598
599
MT("labelTitleNextParenthese",
600
"[link [[foo]]:] [string http://example.com/]",
601
"[string (bar)] hello");
602
603
MT("labelTitleNextMixed",
604
"[link [[foo]]:] [string http://example.com/]",
605
"(bar\" hello");
606
607
MT("linkWeb",
608
"[link <http://example.com/>] foo");
609
610
MT("linkWebDouble",
611
"[link <http://example.com/>] foo [link <http://example.com/>]");
612
613
MT("linkEmail",
614
"[link <[email protected]>] foo");
615
616
MT("linkEmailDouble",
617
"[link <[email protected]>] foo [link <[email protected]>]");
618
619
MT("emAsterisk",
620
"[em *foo*] bar");
621
622
MT("emUnderscore",
623
"[em _foo_] bar");
624
625
MT("emInWordAsterisk",
626
"foo[em *bar*]hello");
627
628
MT("emInWordUnderscore",
629
"foo[em _bar_]hello");
630
631
// Per documentation: "...surround an * or _ with spaces, it’ll be
632
// treated as a literal asterisk or underscore."
633
634
MT("emEscapedBySpaceIn",
635
"foo [em _bar _ hello_] world");
636
637
MT("emEscapedBySpaceOut",
638
"foo _ bar[em _hello_]world");
639
640
MT("emEscapedByNewline",
641
"foo",
642
"_ bar[em _hello_]world");
643
644
// Unclosed emphasis characters
645
// Instead of simply marking as EM / STRONG, it would be nice to have an
646
// incomplete flag for EM and STRONG, that is styled slightly different.
647
MT("emIncompleteAsterisk",
648
"foo [em *bar]");
649
650
MT("emIncompleteUnderscore",
651
"foo [em _bar]");
652
653
MT("strongAsterisk",
654
"[strong **foo**] bar");
655
656
MT("strongUnderscore",
657
"[strong __foo__] bar");
658
659
MT("emStrongAsterisk",
660
"[em *foo][em&strong **bar*][strong hello**] world");
661
662
MT("emStrongUnderscore",
663
"[em _foo][em&strong __bar_][strong hello__] world");
664
665
// "...same character must be used to open and close an emphasis span.""
666
MT("emStrongMixed",
667
"[em _foo][em&strong **bar*hello__ world]");
668
669
MT("emStrongMixed",
670
"[em *foo][em&strong __bar_hello** world]");
671
672
// These characters should be escaped:
673
// \ backslash
674
// ` backtick
675
// * asterisk
676
// _ underscore
677
// {} curly braces
678
// [] square brackets
679
// () parentheses
680
// # hash mark
681
// + plus sign
682
// - minus sign (hyphen)
683
// . dot
684
// ! exclamation mark
685
686
MT("escapeBacktick",
687
"foo \\`bar\\`");
688
689
MT("doubleEscapeBacktick",
690
"foo \\\\[comment `bar\\\\`]");
691
692
MT("escapeAsterisk",
693
"foo \\*bar\\*");
694
695
MT("doubleEscapeAsterisk",
696
"foo \\\\[em *bar\\\\*]");
697
698
MT("escapeUnderscore",
699
"foo \\_bar\\_");
700
701
MT("doubleEscapeUnderscore",
702
"foo \\\\[em _bar\\\\_]");
703
704
MT("escapeHash",
705
"\\# foo");
706
707
MT("doubleEscapeHash",
708
"\\\\# foo");
709
710
MT("escapeNewline",
711
"\\",
712
"[em *foo*]");
713
714
715
// Tests to make sure GFM-specific things aren't getting through
716
717
MT("taskList",
718
"[variable-2 * [ ]] bar]");
719
720
MT("fencedCodeBlocks",
721
"[comment ```]",
722
"foo",
723
"[comment ```]");
724
})();
725
726