unitrun.sh: do not crash when no time.out file
[nit.git] / lib / markdown / test_markdown.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Test suites for module `markdown`
16 module test_markdown is test_suite
17
18 import test_suite
19 intrude import markdown
20
21 class TestMarkdownProcessor
22 super TestSuite
23
24 fun test_process_empty do
25 var test = ""
26 var exp = ""
27 var res = test.md_to_html.write_to_string
28 assert res == exp
29 end
30
31 fun test_process_tabs do
32 var test = """
33 some code
34 """
35 var exp = """<pre><code>some code
36 </code></pre>
37 """
38 var res = test.md_to_html.write_to_string
39 assert res == exp
40 end
41
42
43 fun test_process_par1 do
44 var test = "test"
45 var exp = "<p>test</p>\n"
46 var res = test.md_to_html.write_to_string
47 assert res == exp
48 end
49
50 fun test_process_par2 do
51 var test = """
52 line1
53 line2
54
55 line3 line4
56
57 line5"""
58 var exp = """
59 <p>line1
60 line2</p>
61 <p>line3 line4</p>
62 <p>line5</p>
63 """
64 var res = test.md_to_html.write_to_string
65 assert res == exp
66 end
67
68 fun test_process_par3 do
69 var test = """
70 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
71 Aliquam hendrerit mi posuere lectus.
72 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
73
74 Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
75 id sem consectetuer libero luctus adipiscing.
76 """
77 var exp = """
78 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
79 Aliquam hendrerit mi posuere lectus.
80 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
81 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
82 id sem consectetuer libero luctus adipiscing.</p>
83 """
84 var res = test.md_to_html.write_to_string
85 assert res == exp
86 end
87
88 fun test_process_headings_1 do
89 var test = """
90 This is a H1
91 =============
92
93 This is a H2
94 -------------
95 """
96 var exp = """
97 <h1 id="This_is_a_H1">This is a H1</h1>
98 <h2 id="This_is_a_H2">This is a H2</h2>
99 """
100 var res = test.md_to_html.write_to_string
101 assert res == exp
102 end
103
104 fun test_process_headings_2 do
105 var test = """
106 # This is a H1
107
108 ## This is a H2
109 ###### This is a H6
110 """
111 var exp = """
112 <h1 id="This_is_a_H1">This is a H1</h1>
113 <h2 id="This_is_a_H2">This is a H2</h2>
114 <h6 id="This_is_a_H6">This is a H6</h6>
115 """
116 var res = test.md_to_html.write_to_string
117 assert res == exp
118 end
119
120 fun test_process_headings_3 do
121 var test = """
122 # This is a H1 #
123
124 ## This is a H2 ##
125
126 ### This is a H3 ######
127 """
128 var exp = """
129 <h1 id="This_is_a_H1">This is a H1</h1>
130 <h2 id="This_is_a_H2">This is a H2</h2>
131 <h3 id="This_is_a_H3">This is a H3</h3>
132 """
133 var res = test.md_to_html.write_to_string
134 assert res == exp
135 end
136
137 fun test_process_hr do
138 var test = """
139 * * *
140
141 ***
142
143 *****
144
145 - - -
146
147 ---------------------------------------
148 """
149 var exp = "<hr/>\n<hr/>\n<hr/>\n<hr/>\n<hr/>\n"
150 var res = test.md_to_html.write_to_string
151 assert res == exp
152 end
153
154 fun test_process_bquote1 do
155 var test = """
156 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
157 > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
158 > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
159 >
160 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
161 > id sem consectetuer libero luctus adipiscing.
162 """
163 var exp = """<blockquote>
164 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
165 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
166 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
167 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
168 id sem consectetuer libero luctus adipiscing.</p>
169 </blockquote>
170 """
171 var res = test.md_to_html.write_to_string
172 assert res == exp
173 end
174
175 fun test_process_bquote2 do
176 var test = """
177 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
178 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
179 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
180
181 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
182 id sem consectetuer libero luctus adipiscing.
183 """
184 var exp = """<blockquote>
185 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
186 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
187 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
188 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
189 id sem consectetuer libero luctus adipiscing.</p>
190 </blockquote>
191 """
192 var res = test.md_to_html.write_to_string
193 assert res == exp
194 end
195
196 fun test_process_bquote3 do
197 var test = """
198 > This is the first level of quoting.
199 >
200 > > This is nested blockquote.
201 >
202 > Back to the first level.
203 """
204 var exp = """<blockquote>
205 <p>This is the first level of quoting.</p>
206 <blockquote>
207 <p>This is nested blockquote.</p>
208 </blockquote>
209 <p>Back to the first level.</p>
210 </blockquote>
211 """
212 var res = test.md_to_html.write_to_string
213 assert res == exp
214 end
215
216 fun test_process_list1 do
217 var test = """
218 * Red
219 * Green
220 * Blue
221 """
222 var exp = """<ul>
223 <li>Red</li>
224 <li>Green</li>
225 <li>Blue</li>
226 </ul>
227 """
228 var res = test.md_to_html.write_to_string
229 assert res == exp
230 end
231
232 fun test_process_list2 do
233 var test = """
234 + Red
235 + Green
236 + Blue
237 """
238 var exp = """<ul>
239 <li>Red</li>
240 <li>Green</li>
241 <li>Blue</li>
242 </ul>
243 """
244 var res = test.md_to_html.write_to_string
245 assert res == exp
246 end
247
248 fun test_process_list3 do
249 var test = """
250 - Red
251 - Green
252 - Blue
253 """
254 var exp = """<ul>
255 <li>Red</li>
256 <li>Green</li>
257 <li>Blue</li>
258 </ul>
259 """
260 var res = test.md_to_html.write_to_string
261 assert res == exp
262 end
263
264 fun test_process_list4 do
265 var test = """
266 1. Bird
267 2. McHale
268 3. Parish
269 """
270 var exp = """<ol>
271 <li>Bird</li>
272 <li>McHale</li>
273 <li>Parish</li>
274 </ol>
275 """
276 var res = test.md_to_html.write_to_string
277 assert res == exp
278 end
279
280 fun test_process_list5 do
281 var test = """
282 3. Bird
283 1. McHale
284 8. Parish
285 """
286 var exp = """<ol>
287 <li>Bird</li>
288 <li>McHale</li>
289 <li>Parish</li>
290 </ol>
291 """
292 var res = test.md_to_html.write_to_string
293 assert res == exp
294 end
295
296 fun test_process_list6 do
297 var test = """
298 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
299 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
300 viverra nec, fringilla in, laoreet vitae, risus.
301 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
302 Suspendisse id sem consectetuer libero luctus adipiscing.
303 """
304 var exp = """
305 <ul>
306 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
307 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
308 viverra nec, fringilla in, laoreet vitae, risus.</li>
309 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
310 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
311 </ul>
312 """
313 var res = test.md_to_html.write_to_string
314 assert res == exp
315 end
316
317 fun test_process_list7 do
318 var test = """
319 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
320 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
321 viverra nec, fringilla in, laoreet vitae, risus.
322 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
323 Suspendisse id sem consectetuer libero luctus adipiscing.
324 """
325 var exp = """
326 <ul>
327 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
328 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
329 viverra nec, fringilla in, laoreet vitae, risus.</li>
330 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
331 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
332 </ul>
333 """
334 var res = test.md_to_html.write_to_string
335 assert res == exp
336 end
337
338 fun test_process_list8 do
339 var test = """
340 * Bird
341
342 * Magic
343 """
344 var exp = """
345 <ul>
346 <li><p>Bird</p>
347 </li>
348 <li><p>Magic</p>
349 </li>
350 </ul>
351 """
352 var res = test.md_to_html.write_to_string
353 assert res == exp
354 end
355
356 fun test_process_list9 do
357 var test = """
358 1. This is a list item with two paragraphs. Lorem ipsum dolor
359 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
360 mi posuere lectus.
361
362 Vestibulum enim wisi, viverra nec, fringilla in, laoreet
363 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
364 sit amet velit.
365
366 2. Suspendisse id sem consectetuer libero luctus adipiscing.
367 """
368 var exp = """
369 <ol>
370 <li><p>This is a list item with two paragraphs. Lorem ipsum dolor
371 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
372 mi posuere lectus.</p>
373 <p>Vestibulum enim wisi, viverra nec, fringilla in, laoreet
374 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
375 sit amet velit.</p>
376 </li>
377 <li><p>Suspendisse id sem consectetuer libero luctus adipiscing.</p>
378 </li>
379 </ol>
380 """
381 var res = test.md_to_html.write_to_string
382 assert res == exp
383 end
384
385 fun test_process_list10 do
386 var test = """
387 * This is a list item with two paragraphs.
388
389 This is the second paragraph in the list item. You're
390 only required to indent the first line. Lorem ipsum dolor
391 sit amet, consectetuer adipiscing elit.
392
393 * Another item in the same list.
394 """
395 var exp = """
396 <ul>
397 <li><p>This is a list item with two paragraphs.</p>
398 <p>This is the second paragraph in the list item. You're
399 only required to indent the first line. Lorem ipsum dolor
400 sit amet, consectetuer adipiscing elit.</p>
401 </li>
402 <li><p>Another item in the same list.</p>
403 </li>
404 </ul>
405 """
406 var res = test.md_to_html.write_to_string
407 assert res == exp
408 end
409
410 fun test_process_list11 do
411 var test = """
412 This is a paragraph
413 * and this is not a list
414 """
415 var exp = """
416 <p>This is a paragraph
417 * and this is not a list</p>
418 """
419 var proc = new MarkdownProcessor
420 proc.ext_mode = false
421 var res = proc.process(test).write_to_string
422 assert res == exp
423 end
424
425 fun test_process_list_ext do
426 var test = """
427 This is a paragraph
428 * and this is not a list
429 """
430 var exp = """
431 <p>This is a paragraph</p>
432 <ul>
433 <li>and this is not a list</li>
434 </ul>
435 """
436 var res = test.md_to_html.write_to_string
437 assert res == exp
438 end
439
440 fun test_process_code1 do
441 var test = """
442 This is a normal paragraph:
443
444 This is a code block.
445 """
446 var exp = """<p>This is a normal paragraph:</p>
447 <pre><code>This is a code block.
448 </code></pre>
449 """
450 var res = test.md_to_html.write_to_string
451 assert res == exp
452 end
453
454 fun test_process_code2 do
455 var test = """
456 Here is an example of AppleScript:
457
458 tell application "Foo"
459 beep
460 end tell
461
462 <div class="footer">
463 &copy; 2004 Foo Corporation
464 </div>
465 """
466 var exp = """
467 <p>Here is an example of AppleScript:</p>
468 <pre><code>tell application "Foo"
469 beep
470 end tell
471
472 &lt;div class="footer"&gt;
473 &amp;copy; 2004 Foo Corporation
474 &lt;/div&gt;
475 </code></pre>
476 """
477 var res = test.md_to_html.write_to_string
478 assert res == exp
479 end
480
481 fun test_process_code_ext1 do
482 var test = """
483 Here is an example of AppleScript:
484 ~~~
485 tell application "Foo"
486 beep
487 end tell
488
489 <div class="footer">
490 &copy; 2004 Foo Corporation
491 </div>
492 ~~~
493 """
494 var exp = """
495 <p>Here is an example of AppleScript:</p>
496 <pre><code>tell application "Foo"
497 beep
498 end tell
499
500 &lt;div class="footer"&gt;
501 &amp;copy; 2004 Foo Corporation
502 &lt;/div&gt;
503 </code></pre>
504 """
505 var res = test.md_to_html.write_to_string
506 assert res == exp
507 end
508
509 fun test_process_code_ext2 do
510 var test = """
511 Here is an example of AppleScript:
512 ```
513 tell application "Foo"
514 beep
515 end tell
516
517 <div class="footer">
518 &copy; 2004 Foo Corporation
519 </div>
520 ```
521 """
522 var exp = """
523 <p>Here is an example of AppleScript:</p>
524 <pre><code>tell application "Foo"
525 beep
526 end tell
527
528 &lt;div class="footer"&gt;
529 &amp;copy; 2004 Foo Corporation
530 &lt;/div&gt;
531 </code></pre>
532 """
533 var res = test.md_to_html.write_to_string
534 assert res == exp
535 end
536
537 fun test_process_code_ext3 do
538 var proc = new MarkdownProcessor
539 proc.ext_mode = false
540
541 var test = """
542 Here is an example of AppleScript:
543 beep
544 """
545 var exp = """
546 <p>Here is an example of AppleScript:
547 beep</p>
548 """
549 var res = proc.process(test).write_to_string
550 assert res == exp
551 end
552
553 fun test_process_code_ext4 do
554 var test = """
555 Here is an example of AppleScript:
556 beep
557 """
558 var exp = """
559 <p>Here is an example of AppleScript:</p>
560 <pre><code>beep
561 </code></pre>
562 """
563 var res = test.md_to_html.write_to_string
564 assert res == exp
565 end
566
567 fun test_process_code_ext5 do
568 var test = """
569 ```nit
570 print "Hello World!"
571 ```
572 """
573 var exp = """
574 <pre class="nit"><code>print "Hello World!"
575 </code></pre>
576 """
577 var res = test.md_to_html.write_to_string
578 assert res == exp
579 end
580
581 fun test_process_nesting1 do
582 var test = """
583 > ## This is a header.
584 >
585 > 1. This is the first list item.
586 > 2. This is the second list item.
587 >
588 > Here's some example code:
589 >
590 > return shell_exec("echo $input | $markdown_script");
591 """
592 var exp = """
593 <blockquote>
594 <h2 id="This_is_a_header.">This is a header.</h2>
595 <ol>
596 <li>This is the first list item.</li>
597 <li>This is the second list item.</li>
598 </ol>
599 <p>Here's some example code:</p>
600 <pre><code>return shell_exec("echo $input | $markdown_script");
601 </code></pre>
602 </blockquote>
603 """
604 var res = test.md_to_html.write_to_string
605 assert res == exp
606 end
607
608 fun test_process_nesting2 do
609 var test = """
610 * A list item with a blockquote:
611
612 > This is a blockquote
613 > inside a list item.
614 """
615 var exp = """
616 <ul>
617 <li><p>A list item with a blockquote:</p>
618 <blockquote>
619 <p>This is a blockquote
620 inside a list item.</p>
621 </blockquote>
622 </li>
623 </ul>
624 """
625 var res = test.md_to_html.write_to_string
626 assert res == exp
627 end
628
629 fun test_process_nesting3 do
630 var test = """
631 * A list item with a code block:
632
633 <code goes here>
634 """
635 var exp = """
636 <ul>
637 <li><p>A list item with a code block:</p>
638 <pre><code>&lt;code goes here&gt;
639 </code></pre>
640 </li>
641 </ul>
642 """
643 var res = test.md_to_html.write_to_string
644 assert res == exp
645 end
646
647 fun test_process_nesting4 do
648 var test = """
649 * Tab
650 * Tab
651 * Tab
652 """
653 var exp = """
654 <ul>
655 <li>Tab<ul>
656 <li>Tab<ul>
657 <li>Tab</li>
658 </ul>
659 </li>
660 </ul>
661 </li>
662 </ul>
663 """
664 var res = test.md_to_html.write_to_string
665 assert res == exp
666 end
667
668 # TODO
669 # fun test_process_nesting5 do
670 # var test = """
671 # * this
672 #
673 # * sub
674 #
675 # that
676 # """
677 # var exp = """
678 # <ul>
679 # <li><p>this</p>
680 # <ul>
681 # <li>sub</li>
682 # </ul>
683 # <p>that</p>
684 # </li>
685 # </ul>
686 # """
687 # var res = test.md_to_html.write_to_string
688 # assert res == exp
689 # end
690
691 fun test_process_emph1 do
692 var test = """
693 *single asterisks*
694
695 _single underscores_
696
697 **double asterisks**
698
699 __double underscores__
700 """
701 var exp = """<p><em>single asterisks</em></p>
702 <p><em>single underscores</em></p>
703 <p><strong>double asterisks</strong></p>
704 <p><strong>double underscores</strong></p>
705 """
706 var res = test.md_to_html.write_to_string
707 assert res == exp
708 end
709
710 fun test_process_emph2 do
711 var test = "un*frigging*believable"
712 var exp = "<p>un<em>frigging</em>believable</p>\n"
713 var res = test.md_to_html.write_to_string
714 assert res == exp
715 end
716
717 fun test_process_emph3 do
718 var proc = new MarkdownProcessor
719 proc.ext_mode = false
720 var test = "Con_cat_this"
721 var exp = "<p>Con<em>cat</em>this</p>\n"
722 var res = proc.process(test).write_to_string
723 assert res == exp
724 end
725
726 fun test_process_emph_ext do
727 var test = "Con_cat_this"
728 var exp = "<p>Con_cat_this</p>\n"
729 var res = test.md_to_html.write_to_string
730 assert res == exp
731 end
732
733 fun test_process_xml1 do
734 var test = """
735 This is a regular paragraph.
736
737 <table>
738 <tr>
739 <td>Foo</td>
740 </tr>
741 </table>
742
743 This is another regular paragraph.
744 """
745 var exp = """
746 <p>This is a regular paragraph.</p>
747 <table>
748 <tr>
749 <td>Foo</td>
750 </tr>
751 </table>
752 <p>This is another regular paragraph.</p>
753 """
754 var res = test.md_to_html.write_to_string
755 assert res == exp
756 end
757
758 fun test_process_xml2 do
759 var test = """
760 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
761 """
762 var exp = """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
763 """
764 var res = test.md_to_html.write_to_string
765 assert res == exp
766 end
767
768 fun test_process_xml3 do
769 var test = """
770 <div style=">"/>
771 """
772 var exp = """
773 <div style=">"/>
774 """
775 var res = test.md_to_html.write_to_string
776 assert res == exp
777 end
778
779 fun test_process_span_code1 do
780 var test = "Use the `printf()` function."
781 var exp = "<p>Use the <code>printf()</code> function.</p>\n"
782 var res = test.md_to_html.write_to_string
783 assert res == exp
784 end
785
786 fun test_process_span_code2 do
787 var test = "``There is a literal backtick (`) here.``"
788 var exp = "<p><code>There is a literal backtick (`) here.</code></p>\n"
789 var res = test.md_to_html.write_to_string
790 assert res == exp
791 end
792
793 fun test_process_span_code3 do
794 var test = """
795 A single backtick in a code span: `` ` ``
796
797 A backtick-delimited string in a code span: `` `foo` ``
798 """
799 var exp = """
800 <p>A single backtick in a code span: <code>`</code></p>
801 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
802 """
803 var res = test.md_to_html.write_to_string
804 assert res == exp
805 end
806
807 fun test_process_span_code4 do
808 var test = "Please don't use any `<blink>` tags."
809 var exp = "<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>\n"
810 var res = test.md_to_html.write_to_string
811 assert res == exp
812 end
813
814 fun test_process_span_code5 do
815 var test = "`&#8212;` is the decimal-encoded equivalent of `&mdash;`."
816 var exp = "<p><code>&amp;#8212;</code> is the decimal-encoded equivalent of <code>&amp;mdash;</code>.</p>\n"
817 var res = test.md_to_html.write_to_string
818 assert res == exp
819 end
820
821 fun test_process_escape1 do
822 var test = "\\*this text is surrounded by literal asterisks\\*"
823 var exp = "<p>*this text is surrounded by literal asterisks*</p>\n"
824 var res = test.md_to_html.write_to_string
825 assert res == exp
826 end
827
828 fun test_process_escape2 do
829 var test = "1986\\. What a great season."
830 var exp = "<p>1986. What a great season.</p>\n"
831 var res = test.md_to_html.write_to_string
832 assert res == exp
833 end
834
835 fun test_process_escape3 do
836 var test = "Ben & Lux"
837 var exp = "<p>Ben &amp; Lux</p>\n"
838 var res = test.md_to_html.write_to_string
839 assert res == exp
840 end
841
842 fun test_process_link1 do
843 var test = """
844 This is [an example](http://example.com/ "Title") inline link.
845
846 [This link](http://example.net/) has no title attribute.
847 """
848 var exp = """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
849 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
850 """
851 var res = test.md_to_html.write_to_string
852 assert res == exp
853 end
854
855 fun test_process_link2 do
856 var test = "See my [About](/about/) page for details."
857 var exp = "<p>See my <a href=\"/about/\">About</a> page for details.</p>\n"
858 var res = test.md_to_html.write_to_string
859 assert res == exp
860 end
861
862 fun test_process_link3 do
863 var test = """
864 This is [an example][id] reference-style link.
865
866 This is [an example] [id] reference-style link.
867
868 Some lorem ipsum
869
870 [id]: http://example.com/ "Optional Title Here"
871
872 Some other lipsum
873 """
874 var exp = """
875 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
876 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
877 <p>Some lorem ipsum</p>
878 <p>Some other lipsum</p>
879 """
880 var res = test.md_to_html.write_to_string
881 assert res == exp
882 end
883
884 fun test_process_link4 do
885 var test = """
886 This is multiple examples: [foo][1], [bar][2], [baz][3].
887
888 [1]: http://example.com/ "Optional Title Here"
889 [2]: http://example.com/ 'Optional Title Here'
890 [3]: http://example.com/ (Optional Title Here)
891 """
892 var exp = """
893 <p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">baz</a>.</p>
894 """
895 var res = test.md_to_html.write_to_string
896 assert res == exp
897 end
898
899 fun test_process_link5 do
900 var test = """
901 This is multiple examples: [foo][a], [bar][A], [a].
902
903 [a]: http://example.com/ "Optional Title Here"
904 """
905 var exp = """<p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">a</a>.</p>
906 """
907 var res = test.md_to_html.write_to_string
908 assert res == exp
909 end
910
911 fun test_process_link6 do
912 var test = """
913 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
914
915 [Google]: http://google.com/ "Google"
916 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
917 [MSN]: http://search.msn.com/ "MSN Search"
918 """
919 var exp = """<p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
920 """
921 var res = test.md_to_html.write_to_string
922 assert res == exp
923 end
924
925 fun test_process_link7 do
926 var test = """
927 Visit [Daring Fireball][] for more information.
928
929 [Daring Fireball]: http://daringfireball.net/
930 """
931 var exp = """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
932 """
933 var res = test.md_to_html.write_to_string
934 assert res == exp
935 end
936
937 fun test_process_link8 do
938 var test = """
939 This one has a [line
940 break].
941
942 This one has a [line
943 break] with a line-ending space.
944
945 [line break]: /foo
946 """
947 var exp = """
948 <p>This one has a <a href="/foo">line
949 break</a>.</p>
950 <p>This one has a <a href="/foo">line
951 break</a> with a line-ending space.</p>
952 """
953 var res = test.md_to_html.write_to_string
954 assert res == exp
955 end
956
957 # FIXME unignore test once escape strings fixed
958 # fun test_process_link9 do
959 # var test = """
960 # Foo [bar][].
961 #
962 # Foo [bar](/url/ "Title with \"quotes\" inside").
963 #
964 #
965 # [bar]: /url/ "Title with \"quotes\" inside"
966 # """
967 # var exp = """
968 # <p>Foo <a href="/url/" title="Title with &quot;quotes&quot; inside">bar</a>.</p>
969 # <p>Foo <a href="/url/" title="Title with &quot;quotes&quot; inside">bar</a>.</p>
970 # """
971 # var res = test.md_to_html.write_to_string
972 # assert res == exp
973 # end
974
975 fun test_process_img1 do
976 var test = """
977 ![Alt text](/path/to/img.jpg)
978
979 ![Alt text](/path/to/img.jpg "Optional title")
980 """
981 var exp = """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
982 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
983 """
984 var res = test.md_to_html.write_to_string
985 assert res == exp
986 end
987
988 fun test_process_img2 do
989 var test = """
990 ![Alt text][id]
991
992 [id]: url/to/image "Optional title attribute"
993 """
994 var exp = """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
995 """
996 var res = test.md_to_html.write_to_string
997 assert res == exp
998 end
999
1000 fun test_process_strike do
1001 var proc = new MarkdownProcessor
1002 proc.ext_mode = false
1003 var test = "This is how you ~~strike text~~"
1004 var exp = "<p>This is how you ~~strike text~~</p>\n"
1005 var res = proc.process(test).write_to_string
1006 assert exp == res
1007 end
1008
1009 fun test_process_strike_ext do
1010 var test = "This is how you ~~strike text~~"
1011 var exp = "<p>This is how you <del>strike text</del></p>\n"
1012 var res = test.md_to_html.write_to_string
1013 assert exp == res
1014 end
1015
1016
1017 fun test_daring_encoding do
1018 var test = """
1019 AT&T has an ampersand in their name.
1020
1021 AT&amp;T is another way to write it.
1022
1023 This & that.
1024
1025 4 < 5.
1026
1027 6 > 5.
1028
1029 Here's a [link] [1] with an ampersand in the URL.
1030
1031 Here's a link with an amersand in the link text: [AT&T] [2].
1032
1033 Here's an inline [link](/script?foo=1&bar=2).
1034
1035 Here's an inline [link](</script?foo=1&bar=2>).
1036
1037
1038 [1]: http://example.com/?foo=1&bar=2
1039 [2]: http://att.com/ "AT&T"
1040 """
1041
1042 var exp = """
1043 <p>AT&amp;T has an ampersand in their name.</p>
1044 <p>AT&amp;T is another way to write it.</p>
1045 <p>This &amp; that.</p>
1046 <p>4 &lt; 5.</p>
1047 <p>6 > 5.</p>
1048 <p>Here's a <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an ampersand in the URL.</p>
1049 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&amp;T">AT&amp;T</a>.</p>
1050 <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
1051 <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
1052 """
1053 var res = test.md_to_html.write_to_string
1054 assert res == exp
1055
1056 end
1057
1058 fun test_daring_autolinks do
1059 var test = """
1060 Link: <http://example.com/>.
1061
1062 With an ampersand: <http://example.com/?foo=1&bar=2>
1063
1064 * In a list?
1065 * <http://example.com/>
1066 * It should.
1067
1068 > Blockquoted: <http://example.com/>
1069
1070 Auto-links should not occur here: `<http://example.com/>`
1071
1072 or here: <http://example.com/>
1073 """
1074
1075 var exp = """
1076 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
1077 <p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
1078 <ul>
1079 <li>In a list?</li>
1080 <li><a href="http://example.com/">http://example.com/</a></li>
1081 <li>It should.</li>
1082 </ul>
1083 <blockquote>
1084 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
1085 </blockquote>
1086 <p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
1087 <pre><code>or here: &lt;http://example.com/&gt;
1088 </code></pre>
1089 """
1090 var res = test.md_to_html.write_to_string
1091 assert res == exp
1092 end
1093
1094 fun test_daring_escape do
1095 var test = """
1096 These should all get escaped:
1097
1098 Backslash: \\
1099
1100 Backtick: \`
1101
1102 Asterisk: \*
1103
1104 Underscore: \_
1105
1106 Left brace: \{
1107
1108 Right brace: \}
1109
1110 Left bracket: \[
1111
1112 Right bracket: \]
1113
1114 Left paren: \(
1115
1116 Right paren: \)
1117
1118 Greater-than: \>
1119
1120 Hash: \#
1121
1122 Period: \.
1123
1124 Bang: \!
1125
1126 Plus: \+
1127
1128 Minus: \-
1129
1130
1131 These should not, because they occur within a code block:
1132
1133 Backslash: \\
1134
1135 Backtick: \`
1136
1137 Asterisk: \*
1138
1139 Underscore: \_
1140
1141 Left brace: \{
1142
1143 Right brace: \}
1144
1145 Left bracket: \[
1146
1147 Right bracket: \]
1148
1149 Left paren: \(
1150
1151 Right paren: \)
1152
1153 Greater-than: \>
1154
1155 Hash: \#
1156
1157 Period: \.
1158
1159 Bang: \!
1160
1161 Plus: \+
1162
1163 Minus: \-
1164
1165 Nor should these, which occur in code spans:
1166
1167 Backslash: `\\`
1168
1169 Backtick: `` \` ``
1170
1171 Asterisk: `\*`
1172
1173 Underscore: `\_`
1174
1175 Left brace: `\{`
1176
1177 Right brace: `\}`
1178
1179 Left bracket: `\[`
1180
1181 Right bracket: `\]`
1182
1183 Left paren: `\(`
1184
1185 Right paren: `\)`
1186
1187 Greater-than: `\>`
1188
1189 Hash: `\#`
1190
1191 Period: `\.`
1192
1193 Bang: `\!`
1194
1195 Plus: `\+`
1196
1197 Minus: `\-`
1198
1199 These should get escaped, even though they're matching pairs for
1200 other Markdown constructs:
1201
1202 \\\*asterisks\\\*
1203
1204 \\\_underscores\\\_
1205
1206 \\\`backticks\\\`
1207
1208 This is a code span with a literal backslash-backtick sequence: `` \` ``
1209
1210 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1211
1212 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1213 """
1214 var exp = """
1215 <p>These should all get escaped:</p>
1216 <p>Backslash: \\</p>
1217 <p>Backtick: \`</p>
1218 <p>Asterisk: \*</p>
1219 <p>Underscore: \_</p>
1220 <p>Left brace: \{</p>
1221 <p>Right brace: \}</p>
1222 <p>Left bracket: \[</p>
1223 <p>Right bracket: \]</p>
1224 <p>Left paren: \(</p>
1225 <p>Right paren: \)</p>
1226 <p>Greater-than: \></p>
1227 <p>Hash: \#</p>
1228 <p>Period: \.</p>
1229 <p>Bang: \!</p>
1230 <p>Plus: \+</p>
1231 <p>Minus: \-</p>
1232 <p>These should not, because they occur within a code block:</p>
1233 <pre><code>Backslash: \\
1234
1235 Backtick: \`
1236
1237 Asterisk: \*
1238
1239 Underscore: \_
1240
1241 Left brace: \{
1242
1243 Right brace: \}
1244
1245 Left bracket: \[
1246
1247 Right bracket: \]
1248
1249 Left paren: \(
1250
1251 Right paren: \)
1252
1253 Greater-than: \&gt;
1254
1255 Hash: \#
1256
1257 Period: \.
1258
1259 Bang: \!
1260
1261 Plus: \+
1262
1263 Minus: \-
1264 </code></pre>
1265 <p>Nor should these, which occur in code spans:</p>
1266 <p>Backslash: <code>\\</code></p>
1267 <p>Backtick: <code>\`</code></p>
1268 <p>Asterisk: <code>\*</code></p>
1269 <p>Underscore: <code>\_</code></p>
1270 <p>Left brace: <code>\{</code></p>
1271 <p>Right brace: <code>\}</code></p>
1272 <p>Left bracket: <code>\[</code></p>
1273 <p>Right bracket: <code>\]</code></p>
1274 <p>Left paren: <code>\(</code></p>
1275 <p>Right paren: <code>\)</code></p>
1276 <p>Greater-than: <code>\&gt;</code></p>
1277 <p>Hash: <code>\#</code></p>
1278 <p>Period: <code>\.</code></p>
1279 <p>Bang: <code>\!</code></p>
1280 <p>Plus: <code>\+</code></p>
1281 <p>Minus: <code>\-</code></p>
1282 <p>These should get escaped, even though they're matching pairs for
1283 other Markdown constructs:</p>
1284 <p>*asterisks*</p>
1285 <p>_underscores_</p>
1286 <p>`backticks`</p>
1287 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1288 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1289 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1290 """
1291
1292 var res = test.md_to_html.write_to_string
1293 assert res == exp
1294 end
1295
1296 fun test_daring_blockquotes do
1297 var test = """
1298 > Example:
1299 >
1300 > sub status {
1301 > print "working";
1302 > }
1303 >
1304 > Or:
1305 >
1306 > sub status {
1307 > return "working";
1308 > }
1309 """
1310
1311 var exp = """
1312 <blockquote>
1313 <p>Example:</p>
1314 <pre><code>sub status {
1315 print "working";
1316 }
1317 </code></pre>
1318 <p>Or:</p>
1319 <pre><code>sub status {
1320 return "working";
1321 }
1322 </code></pre>
1323 </blockquote>
1324 """
1325 var res = test.md_to_html.write_to_string
1326 assert res == exp
1327 end
1328
1329 fun test_daring_code_blocks do
1330 var test = """
1331 code block on the first line
1332
1333 Regular text.
1334
1335 code block indented by spaces
1336
1337 Regular text.
1338
1339 the lines in this block
1340 all contain trailing spaces
1341
1342 Regular Text.
1343
1344 code block on the last line
1345 """
1346
1347 var exp = """
1348 <pre><code>code block on the first line
1349 </code></pre>
1350 <p>Regular text.</p>
1351 <pre><code>code block indented by spaces
1352 </code></pre>
1353 <p>Regular text.</p>
1354 <pre><code>the lines in this block
1355 all contain trailing spaces
1356 </code></pre>
1357 <p>Regular Text.</p>
1358 <pre><code>code block on the last line
1359 </code></pre>
1360 """
1361 var res = test.md_to_html.write_to_string
1362 assert res == exp
1363 end
1364
1365 fun test_daring_code_spans do
1366 var test = """
1367 `<test a="` content of attribute `">`
1368
1369 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1370
1371 Here's how you put `` `backticks` `` in a code span.
1372 """
1373
1374 var exp = """
1375 <p><code>&lt;test a="</code> content of attribute <code>"&gt;</code></p>
1376 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1377 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1378 """
1379 var res = test.md_to_html.write_to_string
1380 assert res == exp
1381 end
1382
1383 fun test_daring_pars do
1384 var proc = new MarkdownProcessor
1385 proc.ext_mode = false
1386
1387 var test = """
1388 In Markdown 1.0.0 and earlier. Version
1389 8. This line turns into a list item.
1390 Because a hard-wrapped line in the
1391 middle of a paragraph looked like a
1392 list item.
1393
1394 Here's one with a bullet.
1395 * criminey.
1396 """
1397
1398 var exp = """
1399 <p>In Markdown 1.0.0 and earlier. Version
1400 8. This line turns into a list item.
1401 Because a hard-wrapped line in the
1402 middle of a paragraph looked like a
1403 list item.</p>
1404 <p>Here's one with a bullet.
1405 * criminey.</p>
1406 """
1407 var res = proc.process(test).write_to_string
1408 assert res == exp
1409 end
1410
1411 fun test_daring_rules do
1412 var test = """
1413 Dashes:
1414
1415 ---
1416
1417 ---
1418
1419 ---
1420
1421 ---
1422
1423 ---
1424
1425 - - -
1426
1427 - - -
1428
1429 - - -
1430
1431 - - -
1432
1433 - - -
1434
1435
1436 Asterisks:
1437
1438 ***
1439
1440 ***
1441
1442 ***
1443
1444 ***
1445
1446 ***
1447
1448 * * *
1449
1450 * * *
1451
1452 * * *
1453
1454 * * *
1455
1456 * * *
1457
1458
1459 Underscores:
1460
1461 ___
1462
1463 ___
1464
1465 ___
1466
1467 ___
1468
1469 ___
1470
1471 _ _ _
1472
1473 _ _ _
1474
1475 _ _ _
1476
1477 _ _ _
1478
1479 _ _ _
1480 """
1481
1482 var exp = """
1483 <p>Dashes:</p>
1484 <hr/>
1485 <hr/>
1486 <hr/>
1487 <hr/>
1488 <pre><code>---
1489 </code></pre>
1490 <hr/>
1491 <hr/>
1492 <hr/>
1493 <hr/>
1494 <pre><code>- - -
1495 </code></pre>
1496 <p>Asterisks:</p>
1497 <hr/>
1498 <hr/>
1499 <hr/>
1500 <hr/>
1501 <pre><code>***
1502 </code></pre>
1503 <hr/>
1504 <hr/>
1505 <hr/>
1506 <hr/>
1507 <pre><code>* * *
1508 </code></pre>
1509 <p>Underscores:</p>
1510 <hr/>
1511 <hr/>
1512 <hr/>
1513 <hr/>
1514 <pre><code>___
1515 </code></pre>
1516 <hr/>
1517 <hr/>
1518 <hr/>
1519 <hr/>
1520 <pre><code>_ _ _
1521 </code></pre>
1522 """
1523 var res = test.md_to_html.write_to_string
1524 assert res == exp
1525 end
1526
1527 fun test_daring_images do
1528 var test = """
1529 ![Alt text](/path/to/img.jpg)
1530
1531 ![Alt text](/path/to/img.jpg "Optional title")
1532
1533 Inline within a paragraph: [alt text](/url/).
1534
1535 ![alt text](/url/ "title preceded by two spaces")
1536
1537 ![alt text](/url/ "title has spaces afterward" )
1538
1539 ![alt text](</url/>)
1540
1541 ![alt text](</url/> "with a title").
1542
1543 ![Empty]()
1544
1545 ![this is a stupid URL](http://example.com/(parens).jpg)
1546
1547
1548 ![alt text][foo]
1549
1550 [foo]: /url/
1551
1552 ![alt text][bar]
1553
1554 [bar]: /url/ "Title here"
1555 """
1556
1557 var exp = """
1558 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1559 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1560 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1561 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1562 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1563 <p><img src="/url/" alt="alt text"/></p>
1564 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1565 <p><img src="" alt="Empty"/></p>
1566 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1567 <p><img src="/url/" alt="alt text"/></p>
1568 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1569 """
1570 var res = test.md_to_html.write_to_string
1571 assert res == exp
1572 end
1573
1574 fun test_daring_inline_html1 do
1575 var test = """
1576 Here's a simple block:
1577
1578 <div>
1579 foo
1580 </div>
1581
1582 This should be a code block, though:
1583
1584 <div>
1585 foo
1586 </div>
1587
1588 As should this:
1589
1590 <div>foo</div>
1591
1592 Now, nested:
1593
1594 <div>
1595 <div>
1596 <div>
1597 foo
1598 </div>
1599 </div>
1600 </div>
1601
1602 This should just be an HTML comment:
1603
1604 <!-- Comment -->
1605
1606 Multiline:
1607
1608 <!--
1609 Blah
1610 Blah
1611 -->
1612
1613 Code block:
1614
1615 <!-- Comment -->
1616
1617 Just plain comment, with trailing spaces on the line:
1618
1619 <!-- foo -->
1620
1621 Code:
1622
1623 <hr />
1624
1625 Hr's:
1626
1627 <hr>
1628
1629 <hr/>
1630
1631 <hr />
1632
1633 <hr>
1634
1635 <hr/>
1636
1637 <hr />
1638
1639 <hr class="foo" id="bar" />
1640
1641 <hr class="foo" id="bar"/>
1642
1643 <hr class="foo" id="bar" >
1644 """
1645
1646 var exp = """
1647 <p>Here's a simple block:</p>
1648 <div>
1649 foo
1650 </div>
1651 <p>This should be a code block, though:</p>
1652 <pre><code>&lt;div&gt;
1653 foo
1654 &lt;/div&gt;
1655 </code></pre>
1656 <p>As should this:</p>
1657 <pre><code>&lt;div&gt;foo&lt;/div&gt;
1658 </code></pre>
1659 <p>Now, nested:</p>
1660 <div>
1661 <div>
1662 <div>
1663 foo
1664 </div>
1665 </div>
1666 </div>
1667 <p>This should just be an HTML comment:</p>
1668 <!-- Comment -->
1669 <p>Multiline:</p>
1670 <!--
1671 Blah
1672 Blah
1673 -->
1674 <p>Code block:</p>
1675 <pre><code>&lt;!-- Comment --&gt;
1676 </code></pre>
1677 <p>Just plain comment, with trailing spaces on the line:</p>
1678 <!-- foo -->
1679 <p>Code:</p>
1680 <pre><code>&lt;hr /&gt;
1681 </code></pre>
1682 <p>Hr's:</p>
1683 <hr>
1684 <hr/>
1685 <hr />
1686 <hr>
1687 <hr/>
1688 <hr />
1689 <hr class="foo" id="bar" />
1690 <hr class="foo" id="bar"/>
1691 <hr class="foo" id="bar" >
1692 """
1693 var res = test.md_to_html.write_to_string
1694 assert res == exp
1695 end
1696
1697 fun test_daring_inline_html2 do
1698 var test = """
1699 Simple block on one line:
1700
1701 <div>foo</div>
1702
1703 And nested without indentation:
1704
1705 <div>
1706 <div>
1707 <div>
1708 foo
1709 </div>
1710 <div style=">"/>
1711 </div>
1712 <div>bar</div>
1713 </div>
1714
1715 And with attributes:
1716
1717 <div>
1718 <div id="foo">
1719 </div>
1720 </div>
1721
1722 This was broken in 1.0.2b7:
1723
1724 <div class="inlinepage">
1725 <div class="toggleableend">
1726 foo
1727 </div>
1728 </div>
1729 """
1730
1731 var exp = """
1732 <p>Simple block on one line:</p>
1733 <div>foo</div>
1734 <p>And nested without indentation:</p>
1735 <div>
1736 <div>
1737 <div>
1738 foo
1739 </div>
1740 <div style=">"/>
1741 </div>
1742 <div>bar</div>
1743 </div>
1744 <p>And with attributes:</p>
1745 <div>
1746 <div id="foo">
1747 </div>
1748 </div>
1749 <p>This was broken in 1.0.2b7:</p>
1750 <div class="inlinepage">
1751 <div class="toggleableend">
1752 foo
1753 </div>
1754 </div>
1755 """
1756 var res = test.md_to_html.write_to_string
1757 assert res == exp
1758 end
1759
1760 fun test_daring_inline_html3 do
1761 var test = """
1762 Paragraph one.
1763
1764 <!-- This is a simple comment -->
1765
1766 <!--
1767 This is another comment.
1768 -->
1769
1770 Paragraph two.
1771
1772 <!-- one comment block -- -- with two comments -->
1773
1774 The end.
1775 """
1776
1777 var exp = """
1778 <p>Paragraph one.</p>
1779 <!-- This is a simple comment -->
1780 <!--
1781 This is another comment.
1782 -->
1783 <p>Paragraph two.</p>
1784 <!-- one comment block -- -- with two comments -->
1785 <p>The end.</p>
1786 """
1787 var res = test.md_to_html.write_to_string
1788 assert res == exp
1789 end
1790
1791 fun test_daring_links1 do
1792 var test = """
1793 Just a [URL](/url/).
1794
1795 [URL and title](/url/ "title").
1796
1797 [URL and title](/url/ "title preceded by two spaces").
1798
1799 [URL and title](/url/ "title preceded by a tab").
1800
1801 [URL and title](/url/ "title has spaces afterward" ).
1802
1803 [URL wrapped in angle brackets](</url/>).
1804
1805 [URL w/ angle brackets + title](</url/> "Here's the title").
1806
1807 [Empty]().
1808
1809 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1810
1811 (With outer parens and [parens in url](/foo(bar)))
1812
1813
1814 [With parens in the URL](/foo(bar) "and a title")
1815
1816 (With outer parens and [parens in url](/foo(bar) "and a title"))
1817 """
1818
1819 var exp = """
1820 <p>Just a <a href="/url/">URL</a>.</p>
1821 <p><a href="/url/" title="title">URL and title</a>.</p>
1822 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1823 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1824 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1825 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1826 <p><a href="/url/" title="Here&apos;s the title">URL w/ angle brackets + title</a>.</p>
1827 <p><a href="">Empty</a>.</p>
1828 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1829 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1830 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1831 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1832 """
1833 var res = test.md_to_html.write_to_string
1834 assert res == exp
1835 end
1836
1837 fun test_daring_links2 do
1838 var test = """
1839 Foo [bar] [1].
1840
1841 Foo [bar][1].
1842
1843 Foo [bar]
1844 [1].
1845
1846 [1]: /url/ "Title"
1847
1848
1849 With [embedded [brackets]] [b].
1850
1851
1852 Indented [once][].
1853
1854 Indented [twice][].
1855
1856 Indented [thrice][].
1857
1858 Indented [four][] times.
1859
1860 [once]: /url
1861
1862 [twice]: /url
1863
1864 [thrice]: /url
1865
1866 [four]: /url
1867
1868
1869 [b]: /url/
1870
1871 * * *
1872
1873 [this] [this] should work
1874
1875 So should [this][this].
1876
1877 And [this] [].
1878
1879 And [this][].
1880
1881 And [this].
1882
1883 But not [that] [].
1884
1885 Nor [that][].
1886
1887 Nor [that].
1888
1889 [Something in brackets like [this][] should work]
1890
1891 [Same with [this].]
1892
1893 In this case, [this](/somethingelse/) points to something else.
1894
1895 Backslashing should suppress \\\[this] and [this\\\].
1896
1897 [this]: foo
1898
1899
1900 * * *
1901
1902 Here's one where the [link
1903 breaks] across lines.
1904
1905 Here's another where the [link
1906 breaks] across lines, but with a line-ending space.
1907
1908
1909 [link breaks]: /url/
1910 """
1911
1912 var exp = """
1913 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1914 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1915 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1916 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1917 <p>Indented <a href="/url">once</a>.</p>
1918 <p>Indented <a href="/url">twice</a>.</p>
1919 <p>Indented <a href="/url">thrice</a>.</p>
1920 <p>Indented [four][] times.</p>
1921 <pre><code>[four]: /url
1922 </code></pre>
1923 <hr/>
1924 <p><a href="foo">this</a> should work</p>
1925 <p>So should <a href="foo">this</a>.</p>
1926 <p>And <a href="foo">this</a>.</p>
1927 <p>And <a href="foo">this</a>.</p>
1928 <p>And <a href="foo">this</a>.</p>
1929 <p>But not [that] [].</p>
1930 <p>Nor [that][].</p>
1931 <p>Nor [that].</p>
1932 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
1933 <p>[Same with <a href="foo">this</a>.]</p>
1934 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
1935 <p>Backslashing should suppress [this] and [this].</p>
1936 <hr/>
1937 <p>Here's one where the <a href="/url/">link
1938 breaks</a> across lines.</p>
1939 <p>Here's another where the <a href="/url/">link
1940 breaks</a> across lines, but with a line-ending space.</p>
1941 """
1942 var res = test.md_to_html.write_to_string
1943 assert res == exp
1944 end
1945
1946 fun test_daring_links3 do
1947 var test = """
1948 This is the [simple case].
1949
1950 [simple case]: /simple
1951
1952
1953
1954 This one has a [line
1955 break].
1956
1957 This one has a [line
1958 break] with a line-ending space.
1959
1960 [line break]: /foo
1961
1962
1963 [this] [that] and the [other]
1964
1965 [this]: /this
1966 [that]: /that
1967 [other]: /other
1968 """
1969
1970 var exp = """
1971 <p>This is the <a href="/simple">simple case</a>.</p>
1972 <p>This one has a <a href="/foo">line
1973 break</a>.</p>
1974 <p>This one has a <a href="/foo">line
1975 break</a> with a line-ending space.</p>
1976 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
1977 """
1978 var res = test.md_to_html.write_to_string
1979 assert res == exp
1980 end
1981
1982 fun test_daring_nested do
1983 var test = """
1984 > foo
1985 >
1986 > > bar
1987 >
1988 > foo
1989 """
1990
1991 var exp = """
1992 <blockquote>
1993 <p>foo</p>
1994 <blockquote>
1995 <p>bar</p>
1996 </blockquote>
1997 <p>foo</p>
1998 </blockquote>
1999 """
2000 var res = test.md_to_html.write_to_string
2001 assert res == exp
2002 end
2003
2004 fun test_daring_list do
2005 var test = """
2006 ## Unordered
2007
2008 Asterisks tight:
2009
2010 * asterisk 1
2011 * asterisk 2
2012 * asterisk 3
2013
2014
2015 Asterisks loose:
2016
2017 * asterisk 1
2018
2019 * asterisk 2
2020
2021 * asterisk 3
2022
2023 * * *
2024
2025 Pluses tight:
2026
2027 + Plus 1
2028 + Plus 2
2029 + Plus 3
2030
2031
2032 Pluses loose:
2033
2034 + Plus 1
2035
2036 + Plus 2
2037
2038 + Plus 3
2039
2040 * * *
2041
2042
2043 Minuses tight:
2044
2045 - Minus 1
2046 - Minus 2
2047 - Minus 3
2048
2049
2050 Minuses loose:
2051
2052 - Minus 1
2053
2054 - Minus 2
2055
2056 - Minus 3
2057
2058
2059 ## Ordered
2060
2061 Tight:
2062
2063 1. First
2064 2. Second
2065 3. Third
2066
2067 and:
2068
2069 1. One
2070 2. Two
2071 3. Three
2072
2073
2074 Loose using tabs:
2075
2076 1. First
2077
2078 2. Second
2079
2080 3. Third
2081
2082 and using spaces:
2083
2084 1. One
2085
2086 2. Two
2087
2088 3. Three
2089
2090 Multiple paragraphs:
2091
2092 1. Item 1, graf one.
2093
2094 Item 2. graf two. The quick brown fox jumped over the lazy dog's
2095 back.
2096
2097 2. Item 2.
2098
2099 3. Item 3.
2100
2101
2102
2103 ## Nested
2104
2105 * Tab
2106 * Tab
2107 * Tab
2108
2109 Here's another:
2110
2111 1. First
2112 2. Second:
2113 * Fee
2114 * Fie
2115 * Foe
2116 3. Third
2117
2118 Same thing but with paragraphs:
2119
2120 1. First
2121
2122 2. Second:
2123 * Fee
2124 * Fie
2125 * Foe
2126
2127 3. Third
2128 """
2129
2130 var exp = """
2131 <h2 id="Unordered">Unordered</h2>
2132 <p>Asterisks tight:</p>
2133 <ul>
2134 <li>asterisk 1</li>
2135 <li>asterisk 2</li>
2136 <li>asterisk 3</li>
2137 </ul>
2138 <p>Asterisks loose:</p>
2139 <ul>
2140 <li><p>asterisk 1</p>
2141 </li>
2142 <li><p>asterisk 2</p>
2143 </li>
2144 <li><p>asterisk 3</p>
2145 </li>
2146 </ul>
2147 <hr/>
2148 <p>Pluses tight:</p>
2149 <ul>
2150 <li>Plus 1</li>
2151 <li>Plus 2</li>
2152 <li>Plus 3</li>
2153 </ul>
2154 <p>Pluses loose:</p>
2155 <ul>
2156 <li><p>Plus 1</p>
2157 </li>
2158 <li><p>Plus 2</p>
2159 </li>
2160 <li><p>Plus 3</p>
2161 </li>
2162 </ul>
2163 <hr/>
2164 <p>Minuses tight:</p>
2165 <ul>
2166 <li>Minus 1</li>
2167 <li>Minus 2</li>
2168 <li>Minus 3</li>
2169 </ul>
2170 <p>Minuses loose:</p>
2171 <ul>
2172 <li><p>Minus 1</p>
2173 </li>
2174 <li><p>Minus 2</p>
2175 </li>
2176 <li><p>Minus 3</p>
2177 </li>
2178 </ul>
2179 <h2 id="Ordered">Ordered</h2>
2180 <p>Tight:</p>
2181 <ol>
2182 <li>First</li>
2183 <li>Second</li>
2184 <li>Third</li>
2185 </ol>
2186 <p>and:</p>
2187 <ol>
2188 <li>One</li>
2189 <li>Two</li>
2190 <li>Three</li>
2191 </ol>
2192 <p>Loose using tabs:</p>
2193 <ol>
2194 <li><p>First</p>
2195 </li>
2196 <li><p>Second</p>
2197 </li>
2198 <li><p>Third</p>
2199 </li>
2200 </ol>
2201 <p>and using spaces:</p>
2202 <ol>
2203 <li><p>One</p>
2204 </li>
2205 <li><p>Two</p>
2206 </li>
2207 <li><p>Three</p>
2208 </li>
2209 </ol>
2210 <p>Multiple paragraphs:</p>
2211 <ol>
2212 <li><p>Item 1, graf one.</p>
2213 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2214 back.</p>
2215 </li>
2216 <li><p>Item 2.</p>
2217 </li>
2218 <li><p>Item 3.</p>
2219 </li>
2220 </ol>
2221 <h2 id="Nested">Nested</h2>
2222 <ul>
2223 <li>Tab<ul>
2224 <li>Tab<ul>
2225 <li>Tab</li>
2226 </ul>
2227 </li>
2228 </ul>
2229 </li>
2230 </ul>
2231 <p>Here's another:</p>
2232 <ol>
2233 <li>First</li>
2234 <li>Second:<ul>
2235 <li>Fee</li>
2236 <li>Fie</li>
2237 <li>Foe</li>
2238 </ul>
2239 </li>
2240 <li>Third</li>
2241 </ol>
2242 <p>Same thing but with paragraphs:</p>
2243 <ol>
2244 <li><p>First</p>
2245 </li>
2246 <li><p>Second:</p>
2247 <ul>
2248 <li>Fee</li>
2249 <li>Fie</li>
2250 <li>Foe</li>
2251 </ul>
2252 </li>
2253 <li><p>Third</p>
2254 </li>
2255 </ol>
2256 """
2257 var res = test.md_to_html.write_to_string
2258 assert res == exp
2259 end
2260
2261 fun test_daring_strong_em do
2262 var test = """
2263 ***This is strong and em.***
2264
2265 So is ***this*** word.
2266
2267 ___This is strong and em.___
2268
2269 So is ___this___ word.
2270 """
2271
2272 var exp = """
2273 <p><strong><em>This is strong and em.</em></strong></p>
2274 <p>So is <strong><em>this</em></strong> word.</p>
2275 <p><strong><em>This is strong and em.</em></strong></p>
2276 <p>So is <strong><em>this</em></strong> word.</p>
2277 """
2278 var res = test.md_to_html.write_to_string
2279 assert res == exp
2280 end
2281
2282 fun test_daring_tabs do
2283 var test = """
2284 + this is a list item
2285 indented with tabs
2286
2287 + this is a list item
2288 indented with spaces
2289
2290 Code:
2291
2292 this code block is indented by one tab
2293
2294 And:
2295
2296 this code block is indented by two tabs
2297
2298 And:
2299
2300 + this is an example list item
2301 indented with tabs
2302
2303 + this is an example list item
2304 indented with spaces
2305 """
2306
2307 var exp = """
2308 <ul>
2309 <li><p>this is a list item
2310 indented with tabs</p>
2311 </li>
2312 <li><p>this is a list item
2313 indented with spaces</p>
2314 </li>
2315 </ul>
2316 <p>Code:</p>
2317 <pre><code>this code block is indented by one tab
2318 </code></pre>
2319 <p>And:</p>
2320 <pre><code> this code block is indented by two tabs
2321 </code></pre>
2322 <p>And:</p>
2323 <pre><code>+ this is an example list item
2324 indented with tabs
2325
2326 + this is an example list item
2327 indented with spaces
2328 </code></pre>
2329 """
2330 var res = test.md_to_html.write_to_string
2331 assert res == exp
2332 end
2333
2334 fun test_daring_tidyness do
2335 var test = """
2336 > A list within a blockquote:
2337 >
2338 > * asterisk 1
2339 > * asterisk 2
2340 > * asterisk 3
2341 """
2342
2343 var exp = """
2344 <blockquote>
2345 <p>A list within a blockquote:</p>
2346 <ul>
2347 <li>asterisk 1</li>
2348 <li>asterisk 2</li>
2349 <li>asterisk 3</li>
2350 </ul>
2351 </blockquote>
2352 """
2353 var res = test.md_to_html.write_to_string
2354 assert res == exp
2355 end
2356
2357
2358 end
2359
2360 class TestBlock
2361 super TestSuite
2362
2363 fun test_has_blocks do
2364 var subject = new MDBlock
2365 assert not subject.has_blocks
2366 subject.first_block = new MDBlock
2367 assert subject.has_blocks
2368 end
2369
2370 fun test_count_blocks do
2371 var subject = new MDBlock
2372 assert subject.count_blocks == 0
2373 subject.first_block = new MDBlock
2374 assert subject.count_blocks == 1
2375 subject.first_block.next = new MDBlock
2376 assert subject.count_blocks == 2
2377 end
2378
2379 fun test_has_lines do
2380 var subject = new MDBlock
2381 assert not subject.has_lines
2382 subject.first_line = new MDLine("")
2383 assert subject.has_lines
2384 end
2385
2386 fun test_count_lines do
2387 var subject = new MDBlock
2388 assert subject.count_lines == 0
2389 subject.first_line = new MDLine("")
2390 assert subject.count_lines == 1
2391 subject.first_line.next = new MDLine("")
2392 assert subject.count_lines == 2
2393 end
2394
2395 fun test_split do
2396 var line1 = new MDLine("line1")
2397 var line2 = new MDLine("line2")
2398 var line3 = new MDLine("line3")
2399 var subject = new MDBlock
2400 subject.add_line line1
2401 subject.add_line line2
2402 subject.add_line line3
2403 var block = subject.split(line2)
2404 assert subject.count_blocks == 1
2405 assert subject.count_lines == 1
2406 assert subject.first_line == line3
2407 assert block.count_blocks == 0
2408 assert block.count_lines == 2
2409 assert block.first_line == line1
2410 assert block.last_line == line2
2411 end
2412
2413 fun test_add_line do
2414 var subject = new MDBlock
2415 assert subject.count_lines == 0
2416 subject.add_line new MDLine("")
2417 assert subject.count_lines == 1
2418 subject.add_line new MDLine("")
2419 assert subject.count_lines == 2
2420 end
2421
2422 fun test_remove_line do
2423 var line1 = new MDLine("line1")
2424 var line2 = new MDLine("line2")
2425 var line3 = new MDLine("line3")
2426 var subject = new MDBlock
2427 subject.add_line line1
2428 subject.add_line line2
2429 subject.add_line line3
2430 subject.remove_line(line2)
2431 assert subject.count_lines == 2
2432 subject.remove_line(line1)
2433 assert subject.count_lines == 1
2434 assert subject.first_line == line3
2435 assert subject.last_line == line3
2436 end
2437
2438 fun test_transform_headline1 do
2439 var subject = new MDBlock
2440 var kind = new BlockHeadline(subject)
2441 subject.add_line new MDLine(" # Title 1 ")
2442 kind.transform_headline(subject)
2443 assert kind.depth == 1
2444 assert subject.first_line.value == "Title 1"
2445 end
2446
2447 fun test_transform_headline2 do
2448 var subject = new MDBlock
2449 var kind = new BlockHeadline(subject)
2450 subject.add_line new MDLine(" #####Title 5 ")
2451 kind.transform_headline(subject)
2452 assert kind.depth == 5
2453 assert subject.first_line.value == "Title 5"
2454 end
2455
2456 fun test_remove_quote_prefix do
2457 var subject = new MDBlock
2458 var kind = new BlockQuote(subject)
2459 subject.add_line new MDLine(" > line 1")
2460 subject.add_line new MDLine(" > line 2")
2461 subject.add_line new MDLine(" > line 3")
2462 kind.remove_block_quote_prefix(subject)
2463 assert subject.first_line.value == "line 1"
2464 assert subject.first_line.next.value == "line 2"
2465 assert subject.first_line.next.next.value == "line 3"
2466 end
2467
2468 fun test_remove_leading_empty_lines_1 do
2469 var block = new MDBlock
2470 block.add_line new MDLine("")
2471 block.add_line new MDLine("")
2472 block.add_line new MDLine("")
2473 block.add_line new MDLine("")
2474 block.add_line new MDLine(" text")
2475 block.add_line new MDLine("")
2476 assert block.remove_leading_empty_lines
2477 assert block.first_line.value == " text"
2478 end
2479
2480 fun test_remove_leading_empty_lines_2 do
2481 var block = new MDBlock
2482 block.add_line new MDLine(" text")
2483 block.remove_leading_empty_lines
2484 assert block.first_line.value == " text"
2485 end
2486
2487 fun test_remove_trailing_empty_lines_1 do
2488 var block = new MDBlock
2489 block.add_line new MDLine("")
2490 block.add_line new MDLine("text")
2491 block.add_line new MDLine("")
2492 block.add_line new MDLine("")
2493 block.add_line new MDLine("")
2494 block.add_line new MDLine("")
2495 assert block.remove_trailing_empty_lines
2496 assert block.last_line.value == "text"
2497 end
2498
2499 fun test_remove_trailing_empty_lines_2 do
2500 var block = new MDBlock
2501 block.add_line new MDLine("text ")
2502 assert not block.remove_trailing_empty_lines
2503 assert block.last_line.value == "text "
2504 end
2505
2506 fun test_remove_surrounding_empty_lines do
2507 var block = new MDBlock
2508 block.add_line new MDLine("")
2509 block.add_line new MDLine("text")
2510 block.add_line new MDLine("")
2511 block.add_line new MDLine("")
2512 block.add_line new MDLine("")
2513 block.add_line new MDLine("")
2514 assert block.remove_surrounding_empty_lines
2515 assert block.first_line.value == "text"
2516 assert block.last_line.value == "text"
2517 end
2518 end
2519
2520 class TestLine
2521 super TestSuite
2522
2523 var subject: MDLine
2524
2525 init do end
2526
2527 fun test_is_empty do
2528 subject = new MDLine("")
2529 assert subject.is_empty
2530 subject = new MDLine(" ")
2531 assert subject.is_empty
2532 subject = new MDLine("test")
2533 assert not subject.is_empty
2534 subject = new MDLine(" test")
2535 assert not subject.is_empty
2536 end
2537
2538 fun test_leading do
2539 subject = new MDLine("")
2540 assert subject.leading == 0
2541 subject = new MDLine(" ")
2542 assert subject.leading == 4
2543 subject = new MDLine("test")
2544 assert subject.leading == 0
2545 subject = new MDLine(" test")
2546 assert subject.leading == 4
2547 end
2548
2549 fun test_trailing do
2550 subject = new MDLine("")
2551 assert subject.trailing == 0
2552 subject = new MDLine(" ")
2553 assert subject.trailing == 0
2554 subject = new MDLine("test ")
2555 assert subject.trailing == 3
2556 subject = new MDLine(" test ")
2557 assert subject.trailing == 1
2558 end
2559
2560 fun test_line_type do
2561 var v = new MarkdownProcessor
2562 subject = new MDLine("")
2563 assert v.line_kind(subject) isa LineEmpty
2564 subject = new MDLine(" ")
2565 assert v.line_kind(subject) isa LineEmpty
2566 subject = new MDLine("text ")
2567 assert v.line_kind(subject) isa LineOther
2568 subject = new MDLine(" # Title")
2569 assert v.line_kind(subject) isa LineHeadline
2570 subject = new MDLine(" ### Title")
2571 assert v.line_kind(subject) isa LineHeadline
2572 subject = new MDLine(" code")
2573 assert v.line_kind(subject) isa LineCode
2574 subject = new MDLine(" Title ")
2575 subject.next = new MDLine("== ")
2576 assert v.line_kind(subject) isa LineHeadline1
2577 subject = new MDLine(" Title ")
2578 subject.next = new MDLine("-- ")
2579 assert v.line_kind(subject) isa LineHeadline2
2580 subject = new MDLine(" * * * ")
2581 assert v.line_kind(subject) isa LineHR
2582 subject = new MDLine(" *** ")
2583 assert v.line_kind(subject) isa LineHR
2584 subject = new MDLine("- -- ")
2585 assert v.line_kind(subject) isa LineHR
2586 subject = new MDLine("--------- ")
2587 assert v.line_kind(subject) isa LineHR
2588 subject = new MDLine(" >")
2589 assert v.line_kind(subject) isa LineBlockquote
2590 subject = new MDLine("<p></p>")
2591 assert v.line_kind(subject) isa LineXML
2592 subject = new MDLine("<p>")
2593 assert v.line_kind(subject) isa LineOther
2594 subject = new MDLine(" * foo")
2595 assert v.line_kind(subject) isa LineUList
2596 subject = new MDLine("- foo")
2597 assert v.line_kind(subject) isa LineUList
2598 subject = new MDLine("+ foo")
2599 assert v.line_kind(subject) isa LineUList
2600 subject = new MDLine("1. foo")
2601 assert v.line_kind(subject) isa LineOList
2602 subject = new MDLine(" 11111. foo")
2603 assert v.line_kind(subject) isa LineOList
2604 end
2605
2606 fun test_line_type_ext do
2607 var v = new MarkdownProcessor
2608 subject = new MDLine(" ~~~")
2609 assert v.line_kind(subject) isa LineFence
2610 subject = new MDLine(" ```")
2611 assert v.line_kind(subject) isa LineFence
2612 end
2613
2614 fun test_count_chars do
2615 subject = new MDLine("")
2616 assert subject.count_chars('*') == 0
2617 subject = new MDLine("* ")
2618 assert subject.count_chars('*') == 1
2619 subject = new MDLine(" * text")
2620 assert subject.count_chars('*') == 0
2621 subject = new MDLine(" * * *")
2622 assert subject.count_chars('*') == 3
2623 subject = new MDLine("text ** ")
2624 assert subject.count_chars('*') == 0
2625 end
2626
2627 fun test_count_chars_start do
2628 subject = new MDLine("")
2629 assert subject.count_chars_start('*') == 0
2630 subject = new MDLine("* ")
2631 assert subject.count_chars_start('*') == 1
2632 subject = new MDLine(" * text")
2633 assert subject.count_chars_start('*') == 1
2634 subject = new MDLine(" * * * text")
2635 assert subject.count_chars_start('*') == 3
2636 subject = new MDLine("text ** ")
2637 assert subject.count_chars_start('*') == 0
2638 end
2639 end
2640
2641 class TestHTMLDecorator
2642 super TestSuite
2643
2644 fun test_headlines do
2645 var test = """
2646 # **a**
2647 ## a.a
2648 ### a.a.b
2649 ### a.a.b
2650 ## a.b
2651 # [b](test)
2652 ## b.a
2653 ### b.a.c
2654 ## b.b
2655 ## b.c
2656 # c
2657 """
2658 var proc = new MarkdownProcessor
2659 var decorator = proc.emitter.decorator.as(HTMLDecorator)
2660 proc.process(test)
2661 var res = ""
2662 for id, headline in decorator.headlines do
2663 res += "{headline.title}:{id}\n"
2664 end
2665 var exp = """
2666 **a**:a
2667 a.a:a.a
2668 a.a.b:a.a.b
2669 a.a.b:a.a.b_1
2670 a.b:a.b
2671 [b](test):btest
2672 b.a:b.a
2673 b.a.c:b.a.c
2674 b.b:b.b
2675 b.c:b.c
2676 c:c
2677 """
2678 assert res == exp
2679 end
2680 end