Markdown parser fork with extended syntax for personal use.
1use markdown::{
2 mdast::{Emphasis, Node, Paragraph, Root, Strong, Text},
3 message, to_html, to_html_with_options, to_mdast,
4 unist::Position,
5 CompileOptions, Constructs, Options, ParseOptions,
6};
7use pretty_assertions::assert_eq;
8
9#[test]
10fn attention() -> Result<(), message::Message> {
11 let danger = Options {
12 compile: CompileOptions {
13 allow_dangerous_html: true,
14 allow_dangerous_protocol: true,
15 ..Default::default()
16 },
17 ..Default::default()
18 };
19
20 // Rule 1.
21 assert_eq!(
22 to_html("*foo bar*"),
23 "<p><em>foo bar</em></p>",
24 "should support emphasis w/ `*`"
25 );
26
27 assert_eq!(
28 to_html("a * foo bar*"),
29 "<p>a * foo bar*</p>",
30 "should not support emphasis if the opening is not left flanking (1)"
31 );
32
33 assert_eq!(
34 to_html("a*\"foo\"*"),
35 "<p>a*"foo"*</p>",
36 "should not support emphasis if the opening is not left flanking (2b)"
37 );
38
39 assert_eq!(
40 to_html("* a *"),
41 "<p>* a *</p>",
42 "should not support emphasis unicode whitespace either"
43 );
44
45 assert_eq!(
46 to_html("foo*bar*"),
47 "<p>foo<em>bar</em></p>",
48 "should support intraword emphasis w/ `*` (1)"
49 );
50
51 assert_eq!(
52 to_html("5*6*78"),
53 "<p>5<em>6</em>78</p>",
54 "should support intraword emphasis w/ `*` (2)"
55 );
56
57 // Rule 2.
58 assert_eq!(
59 to_html("_foo bar_"),
60 "<p><em>foo bar</em></p>",
61 "should support emphasis w/ `_`"
62 );
63
64 assert_eq!(
65 to_html("_ foo bar_"),
66 "<p>_ foo bar_</p>",
67 "should not support emphasis if the opening is followed by whitespace"
68 );
69
70 assert_eq!(
71 to_html("a_\"foo\"_"),
72 "<p>a_"foo"_</p>",
73 "should not support emphasis if the opening is preceded by something else and followed by punctuation"
74 );
75
76 assert_eq!(
77 to_html("foo_bar_"),
78 "<p>foo_bar_</p>",
79 "should not support intraword emphasis (1)"
80 );
81
82 assert_eq!(
83 to_html("5_6_78"),
84 "<p>5_6_78</p>",
85 "should not support intraword emphasis (2)"
86 );
87
88 assert_eq!(
89 to_html("пристаням_стремятся_"),
90 "<p>пристаням_стремятся_</p>",
91 "should not support intraword emphasis (3)"
92 );
93
94 assert_eq!(
95 to_html("aa_\"bb\"_cc"),
96 "<p>aa_"bb"_cc</p>",
97 "should not support emphasis if the opening is right flanking and the closing is left flanking"
98 );
99
100 assert_eq!(
101 to_html("foo-_(bar)_"),
102 "<p>foo-<em>(bar)</em></p>",
103 "should support emphasis if the opening is both left and right flanking, if it’s preceded by punctuation"
104 );
105
106 // Rule 3.
107 assert_eq!(
108 to_html("_foo*"),
109 "<p>_foo*</p>",
110 "should not support emphasis if opening and closing markers don’t match"
111 );
112
113 assert_eq!(
114 to_html("*foo bar *"),
115 "<p>*foo bar *</p>",
116 "should not support emphasis w/ `*` if the closing markers are preceded by whitespace"
117 );
118
119 assert_eq!(
120 to_html("*foo bar\n*"),
121 "<p>*foo bar\n*</p>",
122 "should not support emphasis w/ `*` if the closing markers are preceded by a line break (also whitespace)"
123 );
124
125 assert_eq!(
126 to_html("*(*foo)"),
127 "<p>*(*foo)</p>",
128 "should not support emphasis w/ `*` if the closing markers are not right flanking"
129 );
130
131 assert_eq!(
132 to_html("*(*foo*)*"),
133 "<p><em>(<em>foo</em>)</em></p>",
134 "should support nested emphasis"
135 );
136
137 // Rule 4.
138 assert_eq!(
139 to_html("_foo bar _"),
140 "<p>_foo bar _</p>",
141 "should not support emphasis if the closing `_` is preceded by whitespace"
142 );
143
144 assert_eq!(
145 to_html("_(_foo)"),
146 "<p>_(_foo)</p>",
147 "should not support emphasis w/ `_` if the closing markers are not right flanking"
148 );
149
150 assert_eq!(
151 to_html("_(_foo_)_"),
152 "<p><em>(<em>foo</em>)</em></p>",
153 "should support nested emphasis w/ `_`"
154 );
155
156 assert_eq!(
157 to_html("_foo_bar"),
158 "<p>_foo_bar</p>",
159 "should not support intraword emphasis w/ `_` (1)"
160 );
161
162 assert_eq!(
163 to_html("_пристаням_стремятся"),
164 "<p>_пристаням_стремятся</p>",
165 "should not support intraword emphasis w/ `_` (2)"
166 );
167
168 assert_eq!(
169 to_html("_foo_bar_baz_"),
170 "<p><em>foo_bar_baz</em></p>",
171 "should not support intraword emphasis w/ `_` (3)"
172 );
173
174 assert_eq!(
175 to_html("_(bar)_."),
176 "<p><em>(bar)</em>.</p>",
177 "should support emphasis if the opening is both left and right flanking, if it’s followed by punctuation"
178 );
179
180 // Rule 5.
181 assert_eq!(
182 to_html("**foo bar**"),
183 "<p><strong>foo bar</strong></p>",
184 "should support strong emphasis"
185 );
186
187 assert_eq!(
188 to_html("** foo bar**"),
189 "<p>** foo bar**</p>",
190 "should not support strong emphasis if the opening is followed by whitespace"
191 );
192
193 assert_eq!(
194 to_html("a**\"foo\"**"),
195 "<p>a**"foo"**</p>",
196 "should not support strong emphasis if the opening is preceded by something else and followed by punctuation"
197 );
198
199 assert_eq!(
200 to_html("foo**bar**"),
201 "<p>foo<strong>bar</strong></p>",
202 "should support strong intraword emphasis"
203 );
204
205 // Rule 6.
206 assert_eq!(
207 to_html("__foo bar__"),
208 "<p><strong>foo bar</strong></p>",
209 "should support strong emphasis w/ `_`"
210 );
211
212 assert_eq!(
213 to_html("__ foo bar__"),
214 "<p>__ foo bar__</p>",
215 "should not support strong emphasis if the opening is followed by whitespace"
216 );
217
218 assert_eq!(
219 to_html("__\nfoo bar__"),
220 "<p>__\nfoo bar__</p>",
221 "should not support strong emphasis if the opening is followed by a line ending (also whitespace)"
222 );
223
224 assert_eq!(
225 to_html("a__\"foo\"__"),
226 "<p>a__"foo"__</p>",
227 "should not support strong emphasis if the opening is preceded by something else and followed by punctuation"
228 );
229
230 assert_eq!(
231 to_html("foo__bar__"),
232 "<p>foo__bar__</p>",
233 "should not support strong intraword emphasis w/ `_` (1)"
234 );
235
236 assert_eq!(
237 to_html("5__6__78"),
238 "<p>5__6__78</p>",
239 "should not support strong intraword emphasis w/ `_` (2)"
240 );
241
242 assert_eq!(
243 to_html("пристаням__стремятся__"),
244 "<p>пристаням__стремятся__</p>",
245 "should not support strong intraword emphasis w/ `_` (3)"
246 );
247
248 assert_eq!(
249 to_html("__foo, __bar__, baz__"),
250 "<p><strong>foo, <strong>bar</strong>, baz</strong></p>",
251 "should support nested strong emphasis"
252 );
253
254 assert_eq!(
255 to_html("foo-__(bar)__"),
256 "<p>foo-<strong>(bar)</strong></p>",
257 "should support strong emphasis if the opening is both left and right flanking, if it’s preceded by punctuation"
258 );
259
260 // Rule 7.
261 assert_eq!(
262 to_html("**foo bar **"),
263 "<p>**foo bar **</p>",
264 "should not support strong emphasis w/ `*` if the closing is preceded by whitespace"
265 );
266
267 assert_eq!(
268 to_html("**(**foo)"),
269 "<p>**(**foo)</p>",
270 "should not support strong emphasis w/ `*` if the closing is preceded by punctuation and followed by something else"
271 );
272
273 assert_eq!(
274 to_html("*(**foo**)*"),
275 "<p><em>(<strong>foo</strong>)</em></p>",
276 "should support strong emphasis in emphasis"
277 );
278
279 assert_eq!(
280 to_html(
281 "**Gomphocarpus (*Gomphocarpus physocarpus*, syn.\n*Asclepias physocarpa*)**"
282 ),
283 "<p><strong>Gomphocarpus (<em>Gomphocarpus physocarpus</em>, syn.\n<em>Asclepias physocarpa</em>)</strong></p>",
284 "should support emphasis in strong emphasis (1)"
285 );
286
287 assert_eq!(
288 to_html("**foo \"*bar*\" foo**"),
289 "<p><strong>foo "<em>bar</em>" foo</strong></p>",
290 "should support emphasis in strong emphasis (2)"
291 );
292
293 assert_eq!(
294 to_html("**foo**bar"),
295 "<p><strong>foo</strong>bar</p>",
296 "should support strong intraword emphasis"
297 );
298
299 // Rule 8.
300 assert_eq!(
301 to_html("__foo bar __"),
302 "<p>__foo bar __</p>",
303 "should not support strong emphasis w/ `_` if the closing is preceded by whitespace"
304 );
305
306 assert_eq!(
307 to_html("__(__foo)"),
308 "<p>__(__foo)</p>",
309 "should not support strong emphasis w/ `_` if the closing is preceded by punctuation and followed by something else"
310 );
311
312 assert_eq!(
313 to_html("_(__foo__)_"),
314 "<p><em>(<strong>foo</strong>)</em></p>",
315 "should support strong emphasis w/ `_` in emphasis"
316 );
317
318 assert_eq!(
319 to_html("__foo__bar"),
320 "<p>__foo__bar</p>",
321 "should not support strong intraword emphasis w/ `_` (1)"
322 );
323
324 assert_eq!(
325 to_html("__пристаням__стремятся"),
326 "<p>__пристаням__стремятся</p>",
327 "should not support strong intraword emphasis w/ `_` (2)"
328 );
329
330 assert_eq!(
331 to_html("__foo__bar__baz__"),
332 "<p><strong>foo__bar__baz</strong></p>",
333 "should not support strong intraword emphasis w/ `_` (3)"
334 );
335
336 assert_eq!(
337 to_html("__(bar)__."),
338 "<p><strong>(bar)</strong>.</p>",
339 "should support strong emphasis if the opening is both left and right flanking, if it’s followed by punctuation"
340 );
341
342 // Rule 9.
343 assert_eq!(
344 to_html("*foo [bar](/url)*"),
345 "<p><em>foo <a href=\"/url\">bar</a></em></p>",
346 "should support content in emphasis"
347 );
348
349 assert_eq!(
350 to_html("*foo\nbar*"),
351 "<p><em>foo\nbar</em></p>",
352 "should support line endings in emphasis"
353 );
354
355 assert_eq!(
356 to_html("_foo __bar__ baz_"),
357 "<p><em>foo <strong>bar</strong> baz</em></p>",
358 "should support nesting emphasis and strong (1)"
359 );
360
361 assert_eq!(
362 to_html("_foo _bar_ baz_"),
363 "<p><em>foo <em>bar</em> baz</em></p>",
364 "should support nesting emphasis and strong (2)"
365 );
366
367 assert_eq!(
368 to_html("__foo_ bar_"),
369 "<p><em><em>foo</em> bar</em></p>",
370 "should support nesting emphasis and strong (3)"
371 );
372
373 assert_eq!(
374 to_html("*foo *bar**"),
375 "<p><em>foo <em>bar</em></em></p>",
376 "should support nesting emphasis and strong (4)"
377 );
378
379 assert_eq!(
380 to_html("*foo **bar** baz*"),
381 "<p><em>foo <strong>bar</strong> baz</em></p>",
382 "should support nesting emphasis and strong (5)"
383 );
384
385 assert_eq!(
386 to_html("*foo**bar**baz*"),
387 "<p><em>foo<strong>bar</strong>baz</em></p>",
388 "should support nesting emphasis and strong (6)"
389 );
390
391 assert_eq!(
392 to_html("*foo**bar*"),
393 "<p><em>foo**bar</em></p>",
394 "should not support adjacent emphasis in certain cases"
395 );
396
397 assert_eq!(
398 to_html("***foo** bar*"),
399 "<p><em><strong>foo</strong> bar</em></p>",
400 "complex (1)"
401 );
402 assert_eq!(
403 to_html("*foo **bar***"),
404 "<p><em>foo <strong>bar</strong></em></p>",
405 "complex (2)"
406 );
407 assert_eq!(
408 to_html("*foo**bar***"),
409 "<p><em>foo<strong>bar</strong></em></p>",
410 "complex (3)"
411 );
412
413 assert_eq!(
414 to_html("foo***bar***baz"),
415 "<p>foo<em><strong>bar</strong></em>baz</p>",
416 "complex (a)"
417 );
418 assert_eq!(
419 to_html("foo******bar*********baz"),
420 "<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>",
421 "complex (b)"
422 );
423
424 assert_eq!(
425 to_html("*foo **bar *baz* bim** bop*"),
426 "<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p>",
427 "should support indefinite nesting of emphasis (1)"
428 );
429
430 assert_eq!(
431 to_html("*foo [*bar*](/url)*"),
432 "<p><em>foo <a href=\"/url\"><em>bar</em></a></em></p>",
433 "should support indefinite nesting of emphasis (2)"
434 );
435
436 assert_eq!(
437 to_html("** is not an empty emphasis"),
438 "<p>** is not an empty emphasis</p>",
439 "should not support empty emphasis"
440 );
441
442 assert_eq!(
443 to_html("**** is not an empty emphasis"),
444 "<p>**** is not an empty emphasis</p>",
445 "should not support empty strong emphasis"
446 );
447
448 // Rule 10.
449 assert_eq!(
450 to_html("**foo [bar](/url)**"),
451 "<p><strong>foo <a href=\"/url\">bar</a></strong></p>",
452 "should support content in strong emphasis"
453 );
454
455 assert_eq!(
456 to_html("**foo\nbar**"),
457 "<p><strong>foo\nbar</strong></p>",
458 "should support line endings in emphasis"
459 );
460
461 assert_eq!(
462 to_html("__foo _bar_ baz__"),
463 "<p><strong>foo <em>bar</em> baz</strong></p>",
464 "should support nesting emphasis and strong (1)"
465 );
466
467 assert_eq!(
468 to_html("__foo __bar__ baz__"),
469 "<p><strong>foo <strong>bar</strong> baz</strong></p>",
470 "should support nesting emphasis and strong (2)"
471 );
472
473 assert_eq!(
474 to_html("____foo__ bar__"),
475 "<p><strong><strong>foo</strong> bar</strong></p>",
476 "should support nesting emphasis and strong (3)"
477 );
478
479 assert_eq!(
480 to_html("**foo **bar****"),
481 "<p><strong>foo <strong>bar</strong></strong></p>",
482 "should support nesting emphasis and strong (4)"
483 );
484
485 assert_eq!(
486 to_html("**foo *bar* baz**"),
487 "<p><strong>foo <em>bar</em> baz</strong></p>",
488 "should support nesting emphasis and strong (5)"
489 );
490
491 assert_eq!(
492 to_html("**foo*bar*baz**"),
493 "<p><strong>foo<em>bar</em>baz</strong></p>",
494 "should support nesting emphasis and strong (6)"
495 );
496
497 assert_eq!(
498 to_html("***foo* bar**"),
499 "<p><strong><em>foo</em> bar</strong></p>",
500 "should support nesting emphasis and strong (7)"
501 );
502
503 assert_eq!(
504 to_html("**foo *bar***"),
505 "<p><strong>foo <em>bar</em></strong></p>",
506 "should support nesting emphasis and strong (8)"
507 );
508
509 assert_eq!(
510 to_html("**foo *bar **baz**\nbim* bop**"),
511 "<p><strong>foo <em>bar <strong>baz</strong>\nbim</em> bop</strong></p>",
512 "should support indefinite nesting of emphasis (1)"
513 );
514
515 assert_eq!(
516 to_html("**foo [*bar*](/url)**"),
517 "<p><strong>foo <a href=\"/url\"><em>bar</em></a></strong></p>",
518 "should support indefinite nesting of emphasis (2)"
519 );
520
521 assert_eq!(
522 to_html("__ is not an empty emphasis"),
523 "<p>__ is not an empty emphasis</p>",
524 "should not support empty emphasis"
525 );
526
527 assert_eq!(
528 to_html("____ is not an empty emphasis"),
529 "<p>____ is not an empty emphasis</p>",
530 "should not support empty strong emphasis"
531 );
532
533 // Rule 11.
534 assert_eq!(
535 to_html("foo ***"),
536 "<p>foo ***</p>",
537 "should not support emphasis around the same marker"
538 );
539
540 assert_eq!(
541 to_html("foo *\\**"),
542 "<p>foo <em>*</em></p>",
543 "should support emphasis around an escaped marker"
544 );
545
546 assert_eq!(
547 to_html("foo *_*"),
548 "<p>foo <em>_</em></p>",
549 "should support emphasis around the other marker"
550 );
551
552 assert_eq!(
553 to_html("foo *****"),
554 "<p>foo *****</p>",
555 "should not support strong emphasis around the same marker"
556 );
557
558 assert_eq!(
559 to_html("foo **\\***"),
560 "<p>foo <strong>*</strong></p>",
561 "should support strong emphasis around an escaped marker"
562 );
563
564 assert_eq!(
565 to_html("foo **_**"),
566 "<p>foo <strong>_</strong></p>",
567 "should support strong emphasis around the other marker"
568 );
569
570 assert_eq!(
571 to_html("**foo*"),
572 "<p>*<em>foo</em></p>",
573 "should support a superfluous marker at the start of emphasis"
574 );
575
576 assert_eq!(
577 to_html("*foo**"),
578 "<p><em>foo</em>*</p>",
579 "should support a superfluous marker at the end of emphasis"
580 );
581
582 assert_eq!(
583 to_html("***foo**"),
584 "<p>*<strong>foo</strong></p>",
585 "should support a superfluous marker at the start of strong"
586 );
587
588 assert_eq!(
589 to_html("****foo*"),
590 "<p>***<em>foo</em></p>",
591 "should support multiple superfluous markers at the start of strong"
592 );
593
594 assert_eq!(
595 to_html("**foo***"),
596 "<p><strong>foo</strong>*</p>",
597 "should support a superfluous marker at the end of strong"
598 );
599
600 assert_eq!(
601 to_html("*foo****"),
602 "<p><em>foo</em>***</p>",
603 "should support multiple superfluous markers at the end of strong"
604 );
605
606 // Rule 12.
607 assert_eq!(
608 to_html("foo ___"),
609 "<p>foo ___</p>",
610 "should not support emphasis around the same marker"
611 );
612
613 assert_eq!(
614 to_html("foo _\\__"),
615 "<p>foo <em>_</em></p>",
616 "should support emphasis around an escaped marker"
617 );
618
619 assert_eq!(
620 to_html("foo _X_"),
621 "<p>foo <em>X</em></p>",
622 "should support emphasis around the other marker"
623 );
624
625 assert_eq!(
626 to_html("foo _____"),
627 "<p>foo _____</p>",
628 "should not support strong emphasis around the same marker"
629 );
630
631 assert_eq!(
632 to_html("foo __\\___"),
633 "<p>foo <strong>_</strong></p>",
634 "should support strong emphasis around an escaped marker"
635 );
636
637 assert_eq!(
638 to_html("foo __X__"),
639 "<p>foo <strong>X</strong></p>",
640 "should support strong emphasis around the other marker"
641 );
642
643 assert_eq!(
644 to_html("__foo_"),
645 "<p>_<em>foo</em></p>",
646 "should support a superfluous marker at the start of emphasis"
647 );
648
649 assert_eq!(
650 to_html("_foo__"),
651 "<p><em>foo</em>_</p>",
652 "should support a superfluous marker at the end of emphasis"
653 );
654
655 assert_eq!(
656 to_html("___foo__"),
657 "<p>_<strong>foo</strong></p>",
658 "should support a superfluous marker at the start of strong"
659 );
660
661 assert_eq!(
662 to_html("____foo_"),
663 "<p>___<em>foo</em></p>",
664 "should support multiple superfluous markers at the start of strong"
665 );
666
667 assert_eq!(
668 to_html("__foo___"),
669 "<p><strong>foo</strong>_</p>",
670 "should support a superfluous marker at the end of strong"
671 );
672
673 assert_eq!(
674 to_html("_foo____"),
675 "<p><em>foo</em>___</p>",
676 "should support multiple superfluous markers at the end of strong"
677 );
678
679 // Rule 13.
680 assert_eq!(
681 to_html("**foo**"),
682 "<p><strong>foo</strong></p>",
683 "should support strong w/ `*`"
684 );
685
686 assert_eq!(
687 to_html("*_foo_*"),
688 "<p><em><em>foo</em></em></p>",
689 "should support emphasis directly in emphasis w/ `_` in `*`"
690 );
691
692 assert_eq!(
693 to_html("__foo__"),
694 "<p><strong>foo</strong></p>",
695 "should support strong w/ `_`"
696 );
697
698 assert_eq!(
699 to_html("_*foo*_"),
700 "<p><em><em>foo</em></em></p>",
701 "should support emphasis directly in emphasis w/ `*` in `_`"
702 );
703
704 assert_eq!(
705 to_html("****foo****"),
706 "<p><strong><strong>foo</strong></strong></p>",
707 "should support strong emphasis directly in strong emphasis w/ `*`"
708 );
709
710 assert_eq!(
711 to_html("____foo____"),
712 "<p><strong><strong>foo</strong></strong></p>",
713 "should support strong emphasis directly in strong emphasis w/ `_`"
714 );
715
716 assert_eq!(
717 to_html("******foo******"),
718 "<p><strong><strong><strong>foo</strong></strong></strong></p>",
719 "should support indefinite strong emphasis"
720 );
721
722 // Rule 14.
723 assert_eq!(
724 to_html("***foo***"),
725 "<p><em><strong>foo</strong></em></p>",
726 "should support strong directly in emphasis w/ `*`"
727 );
728
729 assert_eq!(
730 to_html("___foo___"),
731 "<p><em><strong>foo</strong></em></p>",
732 "should support strong directly in emphasis w/ `_`"
733 );
734
735 // Rule 15.
736 assert_eq!(
737 to_html("*foo _bar* baz_"),
738 "<p><em>foo _bar</em> baz_</p>",
739 "should not support mismatched emphasis"
740 );
741
742 assert_eq!(
743 to_html("*foo __bar *baz bim__ bam*"),
744 "<p><em>foo <strong>bar *baz bim</strong> bam</em></p>",
745 "should not support mismatched strong emphasis"
746 );
747
748 // Rule 16.
749 assert_eq!(
750 to_html("**foo **bar baz**"),
751 "<p>**foo <strong>bar baz</strong></p>",
752 "should not shortest strong possible"
753 );
754
755 assert_eq!(
756 to_html("*foo *bar baz*"),
757 "<p>*foo <em>bar baz</em></p>",
758 "should not shortest emphasis possible"
759 );
760
761 // Rule 17.
762 assert_eq!(
763 to_html("*[bar*](/url)"),
764 "<p>*<a href=\"/url\">bar*</a></p>",
765 "should not mismatch inside links (1)"
766 );
767
768 assert_eq!(
769 to_html("_[bar_](/url)"),
770 "<p>_<a href=\"/url\">bar_</a></p>",
771 "should not mismatch inside links (1)"
772 );
773
774 assert_eq!(
775 to_html_with_options("*<img src=\"foo\" title=\"*\"/>", &danger)?,
776 "<p>*<img src=\"foo\" title=\"*\"/></p>",
777 "should not end inside HTML"
778 );
779
780 assert_eq!(
781 to_html_with_options("*<img src=\"foo\" title=\"*\"/>", &danger)?,
782 "<p>*<img src=\"foo\" title=\"*\"/></p>",
783 "should not end emphasis inside HTML"
784 );
785
786 assert_eq!(
787 to_html_with_options("**<a href=\"**\">", &danger)?,
788 "<p>**<a href=\"**\"></p>",
789 "should not end strong inside HTML (1)"
790 );
791
792 assert_eq!(
793 to_html_with_options("__<a href=\"__\">", &danger)?,
794 "<p>__<a href=\"__\"></p>",
795 "should not end strong inside HTML (2)"
796 );
797
798 assert_eq!(
799 to_html("*a `*`*"),
800 "<p><em>a <code>*</code></em></p>",
801 "should not end emphasis inside code (1)"
802 );
803
804 assert_eq!(
805 to_html("_a `_`_"),
806 "<p><em>a <code>_</code></em></p>",
807 "should not end emphasis inside code (2)"
808 );
809
810 assert_eq!(
811 to_html("**a<http://foo.bar/?q=**>"),
812 "<p>**a<a href=\"http://foo.bar/?q=**\">http://foo.bar/?q=**</a></p>",
813 "should not end strong emphasis inside autolinks (1)"
814 );
815
816 assert_eq!(
817 to_html("__a<http://foo.bar/?q=__>"),
818 "<p>__a<a href=\"http://foo.bar/?q=__\">http://foo.bar/?q=__</a></p>",
819 "should not end strong emphasis inside autolinks (2)"
820 );
821
822 assert_eq!(
823 to_html_with_options(
824 "*a*",
825 &Options {
826 parse: ParseOptions {
827 constructs: Constructs {
828 attention: false,
829 ..Default::default()
830 },
831 ..Default::default()
832 },
833 ..Default::default()
834 }
835 )?,
836 "<p>*a*</p>",
837 "should support turning off attention"
838 );
839
840 assert_eq!(
841 to_mdast("a *alpha* b **bravo** c.", &Default::default())?,
842 Node::Root(Root {
843 children: vec![Node::Paragraph(Paragraph {
844 children: vec![
845 Node::Text(Text {
846 value: "a ".into(),
847 position: Some(Position::new(1, 1, 0, 1, 3, 2))
848 }),
849 Node::Emphasis(Emphasis {
850 children: vec![Node::Text(Text {
851 value: "alpha".into(),
852 position: Some(Position::new(1, 4, 3, 1, 9, 8))
853 }),],
854 position: Some(Position::new(1, 3, 2, 1, 10, 9))
855 }),
856 Node::Text(Text {
857 value: " b ".into(),
858 position: Some(Position::new(1, 10, 9, 1, 13, 12))
859 }),
860 Node::Strong(Strong {
861 children: vec![Node::Text(Text {
862 value: "bravo".into(),
863 position: Some(Position::new(1, 15, 14, 1, 20, 19))
864 }),],
865 position: Some(Position::new(1, 13, 12, 1, 22, 21))
866 }),
867 Node::Text(Text {
868 value: " c.".into(),
869 position: Some(Position::new(1, 22, 21, 1, 25, 24))
870 })
871 ],
872 position: Some(Position::new(1, 1, 0, 1, 25, 24))
873 })],
874 position: Some(Position::new(1, 1, 0, 1, 25, 24))
875 }),
876 "should support attention as `Emphasis`, `Strong`s in mdast"
877 );
878
879 Ok(())
880}