1
1
import * as MarkdownIt from "markdown-it" ;
2
+ import * as Token from "markdown-it/lib/token" ;
2
3
import { markdownItFancyListPlugin , MarkdownItFancyListPluginOptions } from "../src/index" ;
3
4
import { assert } from "chai" ;
4
5
import { HtmlDiffer } from "@markedjs/html-differ" ;
5
6
6
7
7
- const assertMarkdownIsConvertedTo = async ( expectedHtml : string , markdown : string , pluginOptions ?: MarkdownItFancyListPluginOptions ) => {
8
+ const assertHTML = async ( expectedHtml : string , markdown : string , pluginOptions ?: MarkdownItFancyListPluginOptions ) => {
8
9
const markdownConverter = new MarkdownIt ( "default" , {
9
10
"typographer" : true ,
10
11
} ) ;
@@ -16,6 +17,22 @@ const assertMarkdownIsConvertedTo = async (expectedHtml: string, markdown: strin
16
17
assert . isTrue ( isEqual , `Expected:\n${ expectedHtml } \n\nActual:\n${ actualOutput } ` ) ;
17
18
} ;
18
19
20
+ const assertTokens = ( expectedTokens : Partial < Token > [ ] , markdown : string , pluginOptions ?: MarkdownItFancyListPluginOptions ) => {
21
+ const markdownConverter = new MarkdownIt ( "default" , {
22
+ "typographer" : true ,
23
+ } ) ;
24
+ markdownConverter . use ( markdownItFancyListPlugin , pluginOptions ) ;
25
+ const actualTokens = markdownConverter . parse ( markdown , { } ) ;
26
+
27
+ assert . strictEqual ( actualTokens . length , expectedTokens . length ) ;
28
+ expectedTokens . map ( ( expectedToken , i ) => {
29
+ const keys = Object . keys ( expectedToken ) ;
30
+ keys . map ( ( key ) => {
31
+ assert . strictEqual ( actualTokens [ i ] [ key ] , expectedToken [ key ] , `Expected ${ key } at token ${ i } ` ) ;
32
+ } ) ;
33
+ } ) ;
34
+ } ;
35
+
19
36
20
37
21
38
describe ( "markdownFancyLists" , ( ) => {
@@ -34,7 +51,7 @@ describe("markdownFancyLists", () => {
34
51
<li>baz</li>
35
52
</ol>
36
53
` ;
37
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
54
+ await assertHTML ( expectedHtml , markdown ) ;
38
55
} ) ;
39
56
40
57
it ( "supports lowercase alphabetical numbering" , async ( ) => {
50
67
<li>baz</li>
51
68
</ol>
52
69
` ;
53
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
70
+ await assertHTML ( expectedHtml , markdown ) ;
54
71
} ) ;
55
72
56
73
it ( "supports offsets for lowercase alphabetical numbering" , async ( ) => {
66
83
<li>baz</li>
67
84
</ol>
68
85
` ;
69
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
86
+ await assertHTML ( expectedHtml , markdown ) ;
70
87
} ) ;
71
88
72
89
it ( "supports uppercase alphabetical numbering" , async ( ) => {
82
99
<li>baz</li>
83
100
</ol>
84
101
` ;
85
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
102
+ await assertHTML ( expectedHtml , markdown ) ;
86
103
} ) ;
87
104
88
105
it ( "supports offsets for uppercase alphabetical numbering" , async ( ) => {
@@ -98,7 +115,7 @@ D) baz
98
115
<li>baz</li>
99
116
</ol>
100
117
` ;
101
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
118
+ await assertHTML ( expectedHtml , markdown ) ;
102
119
} ) ;
103
120
104
121
it ( "test supports lowercase roman numbering" , async ( ) => {
@@ -114,7 +131,7 @@ iii. baz
114
131
<li>baz</li>
115
132
</ol>
116
133
` ;
117
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
134
+ await assertHTML ( expectedHtml , markdown ) ;
118
135
} ) ;
119
136
120
137
it ( "supports offsets for lowercase roman numbering" , async ( ) => {
@@ -130,7 +147,7 @@ vi. baz
130
147
<li>baz</li>
131
148
</ol>
132
149
` ;
133
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
150
+ await assertHTML ( expectedHtml , markdown ) ;
134
151
} ) ;
135
152
136
153
it ( "supports uppercase roman numbering" , async ( ) => {
@@ -146,7 +163,7 @@ III) baz
146
163
<li>baz</li>
147
164
</ol>
148
165
` ;
149
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
166
+ await assertHTML ( expectedHtml , markdown ) ;
150
167
} ) ;
151
168
152
169
it ( "supports offsets for uppercase roman numbering" , async ( ) => {
@@ -162,7 +179,7 @@ XIV. baz
162
179
<li>baz</li>
163
180
</ol>
164
181
` ;
165
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
182
+ await assertHTML ( expectedHtml , markdown ) ;
166
183
} ) ;
167
184
168
185
it ( "ignores invalid roman numerals as list marker" , async ( ) => {
@@ -176,7 +193,7 @@ VVII. baz
176
193
VVI. bar
177
194
VVII. baz</p>
178
195
` ;
179
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
196
+ await assertHTML ( expectedHtml , markdown ) ;
180
197
} ) ;
181
198
182
199
it ( "supports hash as list marker for subsequent items" , async ( ) => {
@@ -192,7 +209,7 @@ VVII. baz</p>
192
209
<li>baz</li>
193
210
</ol>
194
211
` ;
195
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
212
+ await assertHTML ( expectedHtml , markdown ) ;
196
213
} ) ;
197
214
198
215
it ( "supports hash as list marker for subsequent roman numeric marker" , async ( ) => {
@@ -208,7 +225,7 @@ i. foo
208
225
<li>baz</li>
209
226
</ol>
210
227
` ;
211
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
228
+ await assertHTML ( expectedHtml , markdown ) ;
212
229
} ) ;
213
230
214
231
it ( "supports hash as list marker for subsequent alphanumeric marker" , async ( ) => {
@@ -224,7 +241,7 @@ a. foo
224
241
<li>baz</li>
225
242
</ol>
226
243
` ;
227
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
244
+ await assertHTML ( expectedHtml , markdown ) ;
228
245
} ) ;
229
246
230
247
it ( "supports hash as list marker for initial item" , async ( ) => {
@@ -240,7 +257,7 @@ a. foo
240
257
<li>baz</li>
241
258
</ol>
242
259
` ;
243
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
260
+ await assertHTML ( expectedHtml , markdown ) ;
244
261
} ) ;
245
262
246
263
it ( "allows first numbers to interrupt paragraphs" , async ( ) => {
@@ -269,7 +286,7 @@ iii. a plane ticket
269
286
<li>a plane ticket</li>
270
287
</ol>
271
288
` ;
272
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
289
+ await assertHTML ( expectedHtml , markdown ) ;
273
290
} ) ;
274
291
275
292
it ( "does not allow subsequent numbers to interrupt paragraphs" , async ( ) => {
@@ -294,7 +311,7 @@ ii. new shoes
294
311
iii. a coat
295
312
iv. a plane ticket</p>
296
313
` ;
297
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
314
+ await assertHTML ( expectedHtml , markdown ) ;
298
315
} ) ;
299
316
300
317
it ( "supports nested lists" , async ( ) => {
@@ -319,7 +336,7 @@ iv. a plane ticket</p>
319
336
</li>
320
337
</ol>
321
338
` ;
322
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
339
+ await assertHTML ( expectedHtml , markdown ) ;
323
340
} ) ;
324
341
325
342
it ( "starts a new list when a different type of numbering is used" , async ( ) => {
@@ -341,7 +358,7 @@ ii) Second
341
358
<li>Second</li>
342
359
</ol>
343
360
` ;
344
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
361
+ await assertHTML ( expectedHtml , markdown ) ;
345
362
} ) ;
346
363
347
364
it ( "starts a new list when a sequence of letters is not a valid roman numeral" , async ( ) => {
@@ -357,7 +374,7 @@ A) First again
357
374
<li>First again</li>
358
375
</ol>
359
376
` ;
360
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
377
+ await assertHTML ( expectedHtml , markdown ) ;
361
378
} ) ;
362
379
363
380
it ( "marker is considered to be alphabetical when part of an alphabetical list" , async ( ) => {
@@ -386,7 +403,7 @@ ii) First of new list
386
403
<li>First of new list</li>
387
404
</ol>
388
405
` ;
389
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
406
+ await assertHTML ( expectedHtml , markdown ) ;
390
407
} ) ;
391
408
392
409
it ( "single letter roman numerals other than I are considered alphabetical without context" , async ( ) => {
@@ -423,7 +440,7 @@ M) foo
423
440
<li>foo</li>
424
441
</ol>
425
442
` ;
426
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
443
+ await assertHTML ( expectedHtml , markdown ) ;
427
444
} ) ;
428
445
429
446
it ( "requires two spaces after a capital letter and a period" , async ( ) => {
@@ -450,7 +467,7 @@ C. bar
450
467
<li>bar</li>
451
468
</ol>
452
469
` ;
453
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
470
+ await assertHTML ( expectedHtml , markdown ) ;
454
471
} ) ;
455
472
456
473
describe ( "support for ordinal indicator" , ( ) => {
@@ -465,7 +482,7 @@ C. bar
465
482
2º. bar
466
483
3º. baz</p>
467
484
` ;
468
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown ) ;
485
+ await assertHTML ( expectedHtml , markdown ) ;
469
486
} ) ;
470
487
471
488
it ( "supports an ordinal indicator if enabled in options" , async ( ) => {
@@ -481,7 +498,7 @@ C. bar
481
498
<li>baz</li>
482
499
</ol>
483
500
` ;
484
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown , {
501
+ await assertHTML ( expectedHtml , markdown , {
485
502
allowOrdinal : true ,
486
503
} ) ;
487
504
} ) ;
@@ -499,7 +516,7 @@ IVº. baz
499
516
<li>baz</li>
500
517
</ol>
501
518
` ;
502
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown , {
519
+ await assertHTML ( expectedHtml , markdown , {
503
520
allowOrdinal : true ,
504
521
} ) ;
505
522
} ) ;
@@ -523,7 +540,7 @@ IVº. baz
523
540
<li>Another first</li>
524
541
</ol>
525
542
` ;
526
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown , {
543
+ await assertHTML ( expectedHtml , markdown , {
527
544
allowOrdinal : true ,
528
545
} ) ;
529
546
} ) ;
@@ -543,7 +560,77 @@ IVº. baz
543
560
<li>ordinal indicator</li>
544
561
</ol>
545
562
` ;
546
- await assertMarkdownIsConvertedTo ( expectedHtml , markdown , {
563
+ await assertHTML ( expectedHtml , markdown , {
564
+ allowOrdinal : true ,
565
+ } ) ;
566
+ } ) ;
567
+
568
+ it ( "produces correct markup character regression for issue#4" , ( ) => {
569
+ const markdown = `
570
+ ### title
571
+
572
+ a. first item
573
+ #. second item
574
+
575
+ 1) first item
576
+ 2) second item
577
+
578
+ 1°. degree sign
579
+ 2˚. ring above
580
+ 3ᵒ. modifier letter small o
581
+ 4º. ordinal indicator
582
+ ` ;
583
+ assertTokens ( [
584
+ { type : "heading_open" } ,
585
+ { type : "inline" , content : "title" } ,
586
+ { type : "heading_close" } ,
587
+ { type : "ordered_list_open" } ,
588
+ { type : "list_item_open" , markup : "." } ,
589
+ { type : "paragraph_open" } ,
590
+ { type : "inline" , content : "first item" } ,
591
+ { type : "paragraph_close" } ,
592
+ { type : "list_item_close" } ,
593
+ { type : "list_item_open" , markup : "." } ,
594
+ { type : "paragraph_open" } ,
595
+ { type : "inline" , content : "second item" } ,
596
+ { type : "paragraph_close" } ,
597
+ { type : "list_item_close" } ,
598
+ { type : "ordered_list_close" } ,
599
+ { type : "ordered_list_open" } ,
600
+ { type : "list_item_open" , markup : ")" } ,
601
+ { type : "paragraph_open" } ,
602
+ { type : "inline" , content : "first item" } ,
603
+ { type : "paragraph_close" } ,
604
+ { type : "list_item_close" } ,
605
+ { type : "list_item_open" , markup : ")" } ,
606
+ { type : "paragraph_open" } ,
607
+ { type : "inline" , content : "second item" } ,
608
+ { type : "paragraph_close" } ,
609
+ { type : "list_item_close" } ,
610
+ { type : "ordered_list_close" } ,
611
+ { type : "ordered_list_open" } ,
612
+ { type : "list_item_open" , markup : "." } ,
613
+ { type : "paragraph_open" } ,
614
+ { type : "inline" , content : "degree sign" } ,
615
+ { type : "paragraph_close" } ,
616
+ { type : "list_item_close" } ,
617
+ { type : "list_item_open" , markup : "." } ,
618
+ { type : "paragraph_open" } ,
619
+ { type : "inline" , content : "ring above" } ,
620
+ { type : "paragraph_close" } ,
621
+ { type : "list_item_close" } ,
622
+ { type : "list_item_open" , markup : "." } ,
623
+ { type : "paragraph_open" } ,
624
+ { type : "inline" , content : "modifier letter small o" } ,
625
+ { type : "paragraph_close" } ,
626
+ { type : "list_item_close" } ,
627
+ { type : "list_item_open" , markup : "." } ,
628
+ { type : "paragraph_open" } ,
629
+ { type : "inline" , content : "ordinal indicator" } ,
630
+ { type : "paragraph_close" } ,
631
+ { type : "list_item_close" } ,
632
+ { type : "ordered_list_close" }
633
+ ] , markdown , {
547
634
allowOrdinal : true ,
548
635
} ) ;
549
636
} ) ;
0 commit comments