1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Test suites for module `markdown`
16 module test_markdown
is test_suite
19 intrude import markdown
21 class TestMarkdownProcessor
24 fun test_process_empty
do
27 var res
= test
.md_to_html
.write_to_string
31 fun test_process_tabs
do
35 var exp
= """<pre><code>some code
38 var res
= test
.md_to_html
.write_to_string
43 fun test_process_par1
do
45 var exp
= "<p>test</p>\n"
46 var res
= test
.md_to_html
.write_to_string
50 fun test_process_par2
do
64 var res
= test
.md_to_html
.write_to_string
68 fun test_process_par3
do
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.
74 Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
75 id sem consectetuer libero luctus adipiscing.
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>
84 var res
= test
.md_to_html
.write_to_string
88 fun test_process_headings_1
do
97 <h1 id="This_is_a_H1">This is a H1</h1>
98 <h2 id="This_is_a_H2">This is a H2</h2>
100 var res
= test
.md_to_html
.write_to_string
104 fun test_process_headings_2
do
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>
116 var res
= test
.md_to_html
.write_to_string
120 fun test_process_headings_3
do
126 ### This is a H3 ######
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>
133 var res
= test
.md_to_html
.write_to_string
137 fun test_process_hr
do
147 ---------------------------------------
149 var exp
= "<hr/>\n<hr/>\n<hr/>\n<hr/>\n<hr/>\n"
150 var res
= test
.md_to_html
.write_to_string
154 fun test_process_bquote1
do
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.
160 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
161 > id sem consectetuer libero luctus adipiscing.
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>
171 var res
= test
.md_to_html
.write_to_string
175 fun test_process_bquote2
do
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.
181 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
182 id sem consectetuer libero luctus adipiscing.
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>
192 var res
= test
.md_to_html
.write_to_string
196 fun test_process_bquote3
do
198 > This is the first level of quoting.
200 > > This is nested blockquote.
202 > Back to the first level.
204 var exp
= """<blockquote>
205 <p>This is the first level of quoting.</p>
207 <p>This is nested blockquote.</p>
209 <p>Back to the first level.</p>
212 var res
= test
.md_to_html
.write_to_string
216 fun test_process_list1
do
228 var res
= test
.md_to_html
.write_to_string
232 fun test_process_list2
do
244 var res
= test
.md_to_html
.write_to_string
248 fun test_process_list3
do
260 var res
= test
.md_to_html
.write_to_string
264 fun test_process_list4
do
276 var res
= test
.md_to_html
.write_to_string
280 fun test_process_list5
do
292 var res
= test
.md_to_html
.write_to_string
296 fun test_process_list6
do
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.
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>
313 var res
= test
.md_to_html
.write_to_string
317 fun test_process_list7
do
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.
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>
334 var res
= test
.md_to_html
.write_to_string
338 fun test_process_list8
do
352 var res
= test
.md_to_html
.write_to_string
356 fun test_process_list9
do
358 1. This is a list item with two paragraphs. Lorem ipsum dolor
359 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
362 Vestibulum enim wisi, viverra nec, fringilla in, laoreet
363 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
366 2. Suspendisse id sem consectetuer libero luctus adipiscing.
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
377 <li><p>Suspendisse id sem consectetuer libero luctus adipiscing.</p>
381 var res
= test
.md_to_html
.write_to_string
385 fun test_process_list10
do
387 * This is a list item with two paragraphs.
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.
393 * Another item in the same list.
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>
402 <li><p>Another item in the same list.</p>
406 var res
= test
.md_to_html
.write_to_string
410 fun test_process_code1
do
412 This is a normal paragraph:
414 This is a code block.
416 var exp
= """<p>This is a normal paragraph:</p>
417 <pre><code>This is a code block.
420 var res
= test
.md_to_html
.write_to_string
424 fun test_process_code2
do
426 Here is an example of AppleScript:
428 tell application "Foo"
433 © 2004 Foo Corporation
437 <p>Here is an example of AppleScript:</p>
438 <pre><code>tell application "Foo"
442 <div class="footer">
443 &copy; 2004 Foo Corporation
447 var res
= test
.md_to_html
.write_to_string
451 fun test_process_nesting1
do
453 > ## This is a header.
455 > 1. This is the first list item.
456 > 2. This is the second list item.
458 > Here's some example code:
460 > return shell_exec("echo $input | $markdown_script");
464 <h2 id="This_is_a_header.">This is a header.</h2>
466 <li>This is the first list item.</li>
467 <li>This is the second list item.</li>
469 <p>Here's some example code:</p>
470 <pre><code>return shell_exec("echo $input | $markdown_script");
474 var res
= test
.md_to_html
.write_to_string
478 fun test_process_nesting2
do
480 * A list item with a blockquote:
482 > This is a blockquote
483 > inside a list item.
487 <li><p>A list item with a blockquote:</p>
489 <p>This is a blockquote
490 inside a list item.</p>
495 var res
= test
.md_to_html
.write_to_string
499 fun test_process_nesting3
do
501 * A list item with a code block:
507 <li><p>A list item with a code block:</p>
508 <pre><code><code goes here>
513 var res
= test
.md_to_html
.write_to_string
517 fun test_process_nesting4
do
534 var res
= test
.md_to_html
.write_to_string
539 # fun test_process_nesting5 do
557 # var res = test.md_to_html.write_to_string
561 fun test_process_emph1
do
569 __double underscores__
571 var exp
= """<p><em>single asterisks</em></p>
572 <p><em>single underscores</em></p>
573 <p><strong>double asterisks</strong></p>
574 <p><strong>double underscores</strong></p>
576 var res
= test
.md_to_html
.write_to_string
580 fun test_process_emph2
do
581 var test
= "un*frigging*believable"
582 var exp
= "<p>un<em>frigging</em>believable</p>\n"
583 var res
= test
.md_to_html
.write_to_string
587 fun test_process_xml1
do
589 This is a regular paragraph.
597 This is another regular paragraph.
600 <p>This is a regular paragraph.</p>
606 <p>This is another regular paragraph.</p>
608 var res
= test
.md_to_html
.write_to_string
612 fun test_process_xml2
do
614 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
616 var exp
= """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
618 var res
= test
.md_to_html
.write_to_string
622 fun test_process_xml3
do
629 var res
= test
.md_to_html
.write_to_string
633 fun test_process_span_code1
do
634 var test
= "Use the `printf()` function."
635 var exp
= "<p>Use the <code>printf()</code> function.</p>\n"
636 var res
= test
.md_to_html
.write_to_string
640 fun test_process_span_code2
do
641 var test
= "``There is a literal backtick (`) here.``"
642 var exp
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
643 var res
= test
.md_to_html
.write_to_string
647 fun test_process_span_code3
do
649 A single backtick in a code span: `` ` ``
651 A backtick-delimited string in a code span: `` `foo` ``
654 <p>A single backtick in a code span: <code>`</code></p>
655 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
657 var res
= test
.md_to_html
.write_to_string
661 fun test_process_span_code4
do
662 var test
= "Please don't use any `<blink>` tags."
663 var exp
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
664 var res
= test
.md_to_html
.write_to_string
668 fun test_process_span_code5
do
669 var test
= "`—` is the decimal-encoded equivalent of `—`."
670 var exp
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
671 var res
= test
.md_to_html
.write_to_string
675 fun test_process_escape1
do
676 var test
= "\\*this text is surrounded by literal asterisks\\*"
677 var exp
= "<p>*this text is surrounded by literal asterisks*</p>\n"
678 var res
= test
.md_to_html
.write_to_string
682 fun test_process_escape2
do
683 var test
= "1986\\. What a great season."
684 var exp
= "<p>1986. What a great season.</p>\n"
685 var res
= test
.md_to_html
.write_to_string
689 fun test_process_escape3
do
690 var test
= "Ben & Lux"
691 var exp
= "<p>Ben & Lux</p>\n"
692 var res
= test
.md_to_html
.write_to_string
696 fun test_process_link1
do
698 This is [an example](http://example.com/ "Title") inline link.
700 [This link](http://example.net/) has no title attribute.
702 var exp
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
703 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
705 var res
= test
.md_to_html
.write_to_string
709 fun test_process_link2
do
710 var test
= "See my [About](/about/) page for details."
711 var exp
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
712 var res
= test
.md_to_html
.write_to_string
716 fun test_process_link3
do
718 This is [an example][id] reference-style link.
720 This is [an example] [id] reference-style link.
724 [id]: http://example.com/ "Optional Title Here"
729 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
730 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
731 <p>Some lorem ipsum</p>
732 <p>Some other lipsum</p>
734 var res
= test
.md_to_html
.write_to_string
738 fun test_process_link4
do
740 This is multiple examples: [foo][1], [bar][2], [baz][3].
742 [1]: http://example.com/ "Optional Title Here"
743 [2]: http://example.com/ 'Optional Title Here'
744 [3]: http://example.com/ (Optional Title Here)
747 <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>
749 var res
= test
.md_to_html
.write_to_string
753 fun test_process_link5
do
755 This is multiple examples: [foo][a], [bar][A], [a].
757 [a]: http://example.com/ "Optional Title Here"
759 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>
761 var res
= test
.md_to_html
.write_to_string
765 fun test_process_link6
do
767 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
769 [Google]: http://google.com/ "Google"
770 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
771 [MSN]: http://search.msn.com/ "MSN Search"
773 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>
775 var res
= test
.md_to_html
.write_to_string
779 fun test_process_link7
do
781 Visit [Daring Fireball][] for more information.
783 [Daring Fireball]: http://daringfireball.net/
785 var exp
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
787 var res
= test
.md_to_html
.write_to_string
791 fun test_process_link8
do
797 break] with a line-ending space.
802 <p>This one has a <a href="/foo">line
804 <p>This one has a <a href="/foo">line
805 break</a> with a line-ending space.</p>
807 var res
= test
.md_to_html
.write_to_string
811 # FIXME unignore test once escape strings fixed
812 # fun test_process_link9 do
816 # Foo [bar](/url/ "Title with \"quotes\" inside").
819 # [bar]: /url/ "Title with \"quotes\" inside"
822 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
823 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
825 # var res = test.md_to_html.write_to_string
829 fun test_process_img1
do
831 ![Alt text](/path/to/img.jpg)
833 ![Alt text](/path/to/img.jpg "Optional title")
835 var exp
= """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
836 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
838 var res
= test
.md_to_html
.write_to_string
842 fun test_process_img2
do
846 [id]: url/to/image "Optional title attribute"
848 var exp
= """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
850 var res
= test
.md_to_html
.write_to_string
854 fun test_daring_encoding
do
856 AT&T has an ampersand in their name.
858 AT&T is another way to write it.
866 Here's a [link] [1] with an ampersand in the URL.
868 Here's a link with an amersand in the link text: [AT&T] [2].
870 Here's an inline [link](/script?foo=1&bar=2).
872 Here's an inline [link](</script?foo=1&bar=2>).
875 [1]: http://example.com/?foo=1&bar=2
876 [2]: http://att.com/ "AT&T"
880 <p>AT&T has an ampersand in their name.</p>
881 <p>AT&T is another way to write it.</p>
882 <p>This & that.</p>
885 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
886 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
887 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
888 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
890 var res
= test
.md_to_html
.write_to_string
895 fun test_daring_autolinks
do
897 Link: <http://example.com/>.
899 With an ampersand: <http://example.com/?foo=1&bar=2>
902 * <http://example.com/>
905 > Blockquoted: <http://example.com/>
907 Auto-links should not occur here: `<http://example.com/>`
909 or here: <http://example.com/>
913 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
914 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
917 <li><a href="http://example.com/">http://example.com/</a></li>
921 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
923 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
924 <pre><code>or here: <http://example.com/>
927 var res
= test
.md_to_html
.write_to_string
931 fun test_daring_escape
do
933 These should all get escaped:
968 These should not, because they occur within a code block:
1002 Nor should these, which occur in code spans:
1036 These should get escaped, even though they're matching pairs for
1037 other Markdown constructs:
1045 This is a code span with a literal backslash-backtick sequence: `` \` ``
1047 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1049 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1052 <p>These should all get escaped:</p>
1053 <p>Backslash: \\</p>
1056 <p>Underscore: \_</p>
1057 <p>Left brace: \{</p>
1058 <p>Right brace: \}</p>
1059 <p>Left bracket: \[</p>
1060 <p>Right bracket: \]</p>
1061 <p>Left paren: \(</p>
1062 <p>Right paren: \)</p>
1063 <p>Greater-than: \></p>
1069 <p>These should not, because they occur within a code block:</p>
1070 <pre><code>Backslash: \\
1102 <p>Nor should these, which occur in code spans:</p>
1103 <p>Backslash: <code>\\</code></p>
1104 <p>Backtick: <code>\`</code></p>
1105 <p>Asterisk: <code>\*</code></p>
1106 <p>Underscore: <code>\_</code></p>
1107 <p>Left brace: <code>\{</code></p>
1108 <p>Right brace: <code>\}</code></p>
1109 <p>Left bracket: <code>\[</code></p>
1110 <p>Right bracket: <code>\]</code></p>
1111 <p>Left paren: <code>\(</code></p>
1112 <p>Right paren: <code>\)</code></p>
1113 <p>Greater-than: <code>\></code></p>
1114 <p>Hash: <code>\#</code></p>
1115 <p>Period: <code>\.</code></p>
1116 <p>Bang: <code>\!</code></p>
1117 <p>Plus: <code>\+</code></p>
1118 <p>Minus: <code>\-</code></p>
1119 <p>These should get escaped, even though they're matching pairs for
1120 other Markdown constructs:</p>
1122 <p>_underscores_</p>
1124 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1125 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1126 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1129 var res
= test
.md_to_html
.write_to_string
1133 fun test_daring_blockquotes
do
1151 <pre><code>sub status {
1156 <pre><code>sub status {
1162 var res
= test
.md_to_html
.write_to_string
1166 fun test_daring_code_blocks
do
1168 code block on the first line
1172 code block indented by spaces
1176 the lines in this block
1177 all contain trailing spaces
1181 code block on the last line
1185 <pre><code>code block on the first line
1187 <p>Regular text.</p>
1188 <pre><code>code block indented by spaces
1190 <p>Regular text.</p>
1191 <pre><code>the lines in this block
1192 all contain trailing spaces
1194 <p>Regular Text.</p>
1195 <pre><code>code block on the last line
1198 var res
= test
.md_to_html
.write_to_string
1202 fun test_daring_code_spans
do
1204 `<test a="` content of attribute `">`
1206 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1208 Here's how you put `` `backticks` `` in a code span.
1212 <p><code><test a="</code> content of attribute <code>"></code></p>
1213 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1214 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1216 var res
= test
.md_to_html
.write_to_string
1220 fun test_daring_pars
do
1222 In Markdown 1.0.0 and earlier. Version
1223 8. This line turns into a list item.
1224 Because a hard-wrapped line in the
1225 middle of a paragraph looked like a
1228 Here's one with a bullet.
1233 <p>In Markdown 1.0.0 and earlier. Version
1234 8. This line turns into a list item.
1235 Because a hard-wrapped line in the
1236 middle of a paragraph looked like a
1238 <p>Here's one with a bullet.
1241 var res
= test
.md_to_html
.write_to_string
1245 fun test_daring_rules
do
1357 var res
= test
.md_to_html
.write_to_string
1361 fun test_daring_images
do
1363 ![Alt text](/path/to/img.jpg)
1365 ![Alt text](/path/to/img.jpg "Optional title")
1367 Inline within a paragraph: [alt text](/url/).
1369 ![alt text](/url/ "title preceded by two spaces")
1371 ![alt text](/url/ "title has spaces afterward" )
1373 ![alt text](</url/>)
1375 ![alt text](</url/> "with a title").
1379 ![this is a stupid URL](http://example.com/(parens).jpg)
1388 [bar]: /url/ "Title here"
1392 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1393 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1394 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1395 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1396 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1397 <p><img src="/url/" alt="alt text"/></p>
1398 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1399 <p><img src="" alt="Empty"/></p>
1400 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1401 <p><img src="/url/" alt="alt text"/></p>
1402 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1404 var res
= test
.md_to_html
.write_to_string
1408 fun test_daring_inline_html1
do
1410 Here's a simple block:
1416 This should be a code block, though:
1436 This should just be an HTML comment:
1451 Just plain comment, with trailing spaces on the line:
1473 <hr class="foo" id="bar" />
1475 <hr class="foo" id="bar"/>
1477 <hr class="foo" id="bar" >
1481 <p>Here's a simple block:</p>
1485 <p>This should be a code block, though:</p>
1486 <pre><code><div>
1490 <p>As should this:</p>
1491 <pre><code><div>foo</div>
1501 <p>This should just be an HTML comment:</p>
1509 <pre><code><!-- Comment -->
1511 <p>Just plain comment, with trailing spaces on the line:</p>
1514 <pre><code><hr />
1523 <hr class="foo" id="bar" />
1524 <hr class="foo" id="bar"/>
1525 <hr class="foo" id="bar" >
1527 var res
= test
.md_to_html
.write_to_string
1531 fun test_daring_inline_html2
do
1533 Simple block on one line:
1537 And nested without indentation:
1549 And with attributes:
1556 This was broken in 1.0.2b7:
1558 <div class="inlinepage">
1559 <div class="toggleableend">
1566 <p>Simple block on one line:</p>
1568 <p>And nested without indentation:</p>
1578 <p>And with attributes:</p>
1583 <p>This was broken in 1.0.2b7:</p>
1584 <div class="inlinepage">
1585 <div class="toggleableend">
1590 var res
= test
.md_to_html
.write_to_string
1594 fun test_daring_inline_html3
do
1598 <!-- This is a simple comment -->
1601 This is another comment.
1606 <!-- one comment block -- -- with two comments -->
1612 <p>Paragraph one.</p>
1613 <!-- This is a simple comment -->
1615 This is another comment.
1617 <p>Paragraph two.</p>
1618 <!-- one comment block -- -- with two comments -->
1621 var res
= test
.md_to_html
.write_to_string
1625 fun test_daring_links1
do
1627 Just a [URL](/url/).
1629 [URL and title](/url/ "title").
1631 [URL and title](/url/ "title preceded by two spaces").
1633 [URL and title](/url/ "title preceded by a tab").
1635 [URL and title](/url/ "title has spaces afterward" ).
1637 [URL wrapped in angle brackets](</url/>).
1639 [URL w/ angle brackets + title](</url/> "Here's the title").
1643 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1645 (With outer parens and [parens in url](/foo(bar)))
1648 [With parens in the URL](/foo(bar) "and a title")
1650 (With outer parens and [parens in url](/foo(bar) "and a title"))
1654 <p>Just a <a href="/url/">URL</a>.</p>
1655 <p><a href="/url/" title="title">URL and title</a>.</p>
1656 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1657 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1658 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1659 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1660 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
1661 <p><a href="">Empty</a>.</p>
1662 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1663 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1664 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1665 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1667 var res
= test
.md_to_html
.write_to_string
1671 fun test_daring_links2
do
1683 With [embedded [brackets]] [b].
1690 Indented [thrice][].
1692 Indented [four][] times.
1707 [this] [this] should work
1709 So should [this][this].
1723 [Something in brackets like [this][] should work]
1727 In this case, [this](/somethingelse/) points to something else.
1729 Backslashing should suppress \\\[this] and [this\\\].
1736 Here's one where the [link
1737 breaks] across lines.
1739 Here's another where the [link
1740 breaks] across lines, but with a line-ending space.
1743 [link breaks]: /url/
1747 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1748 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1749 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1750 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1751 <p>Indented <a href="/url">once</a>.</p>
1752 <p>Indented <a href="/url">twice</a>.</p>
1753 <p>Indented <a href="/url">thrice</a>.</p>
1754 <p>Indented [four][] times.</p>
1755 <pre><code>[four]: /url
1758 <p><a href="foo">this</a> should work</p>
1759 <p>So should <a href="foo">this</a>.</p>
1760 <p>And <a href="foo">this</a>.</p>
1761 <p>And <a href="foo">this</a>.</p>
1762 <p>And <a href="foo">this</a>.</p>
1763 <p>But not [that] [].</p>
1764 <p>Nor [that][].</p>
1766 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
1767 <p>[Same with <a href="foo">this</a>.]</p>
1768 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
1769 <p>Backslashing should suppress [this] and [this].</p>
1771 <p>Here's one where the <a href="/url/">link
1772 breaks</a> across lines.</p>
1773 <p>Here's another where the <a href="/url/">link
1774 breaks</a> across lines, but with a line-ending space.</p>
1776 var res
= test
.md_to_html
.write_to_string
1780 fun test_daring_links3
do
1782 This is the [simple case].
1784 [simple case]: /simple
1788 This one has a [line
1791 This one has a [line
1792 break] with a line-ending space.
1797 [this] [that] and the [other]
1805 <p>This is the <a href="/simple">simple case</a>.</p>
1806 <p>This one has a <a href="/foo">line
1808 <p>This one has a <a href="/foo">line
1809 break</a> with a line-ending space.</p>
1810 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
1812 var res
= test
.md_to_html
.write_to_string
1816 fun test_daring_nested
do
1834 var res
= test
.md_to_html
.write_to_string
1838 fun test_daring_list
do
1924 Multiple paragraphs:
1926 1. Item 1, graf one.
1928 Item 2. graf two. The quick brown fox jumped over the lazy dog's
1952 Same thing but with paragraphs:
1965 <h2 id="Unordered">Unordered</h2>
1966 <p>Asterisks tight:</p>
1972 <p>Asterisks loose:</p>
1974 <li><p>asterisk 1</p>
1976 <li><p>asterisk 2</p>
1978 <li><p>asterisk 3</p>
1982 <p>Pluses tight:</p>
1988 <p>Pluses loose:</p>
1998 <p>Minuses tight:</p>
2004 <p>Minuses loose:</p>
2013 <h2 id="Ordered">Ordered</h2>
2026 <p>Loose using tabs:</p>
2035 <p>and using spaces:</p>
2044 <p>Multiple paragraphs:</p>
2046 <li><p>Item 1, graf one.</p>
2047 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2055 <h2 id="Nested">Nested</h2>
2065 <p>Here's another:</p>
2076 <p>Same thing but with paragraphs:</p>
2091 var res
= test
.md_to_html
.write_to_string
2095 fun test_daring_strong_em
do
2097 ***This is strong and em.***
2099 So is ***this*** word.
2101 ___This is strong and em.___
2103 So is ___this___ word.
2107 <p><strong><em>This is strong and em.</em></strong></p>
2108 <p>So is <strong><em>this</em></strong> word.</p>
2109 <p><strong><em>This is strong and em.</em></strong></p>
2110 <p>So is <strong><em>this</em></strong> word.</p>
2112 var res
= test
.md_to_html
.write_to_string
2116 fun test_daring_tabs
do
2118 + this is a list item
2121 + this is a list item
2122 indented with spaces
2126 this code block is indented by one tab
2130 this code block is indented by two tabs
2134 + this is an example list item
2137 + this is an example list item
2138 indented with spaces
2143 <li><p>this is a list item
2144 indented with tabs</p>
2146 <li><p>this is a list item
2147 indented with spaces</p>
2151 <pre><code>this code block is indented by one tab
2154 <pre><code> this code block is indented by two tabs
2157 <pre><code>+ this is an example list item
2160 + this is an example list item
2161 indented with spaces
2164 var res
= test
.md_to_html
.write_to_string
2168 fun test_daring_tidyness
do
2170 > A list within a blockquote:
2179 <p>A list within a blockquote:</p>
2187 var res
= test
.md_to_html
.write_to_string
2197 fun test_has_blocks
do
2198 var subject
= new MDBlock
2199 assert not subject
.has_blocks
2200 subject
.first_block
= new MDBlock
2201 assert subject
.has_blocks
2204 fun test_count_blocks
do
2205 var subject
= new MDBlock
2206 assert subject
.count_blocks
== 0
2207 subject
.first_block
= new MDBlock
2208 assert subject
.count_blocks
== 1
2209 subject
.first_block
.next
= new MDBlock
2210 assert subject
.count_blocks
== 2
2213 fun test_has_lines
do
2214 var subject
= new MDBlock
2215 assert not subject
.has_lines
2216 subject
.first_line
= new MDLine("")
2217 assert subject
.has_lines
2220 fun test_count_lines
do
2221 var subject
= new MDBlock
2222 assert subject
.count_lines
== 0
2223 subject
.first_line
= new MDLine("")
2224 assert subject
.count_lines
== 1
2225 subject
.first_line
.next
= new MDLine("")
2226 assert subject
.count_lines
== 2
2230 var line1
= new MDLine("line1")
2231 var line2
= new MDLine("line2")
2232 var line3
= new MDLine("line3")
2233 var subject
= new MDBlock
2234 subject
.add_line line1
2235 subject
.add_line line2
2236 subject
.add_line line3
2237 var block
= subject
.split
(line2
)
2238 assert subject
.count_blocks
== 1
2239 assert subject
.count_lines
== 1
2240 assert subject
.first_line
== line3
2241 assert block
.count_blocks
== 0
2242 assert block
.count_lines
== 2
2243 assert block
.first_line
== line1
2244 assert block
.last_line
== line2
2247 fun test_add_line
do
2248 var subject
= new MDBlock
2249 assert subject
.count_lines
== 0
2250 subject
.add_line
new MDLine("")
2251 assert subject
.count_lines
== 1
2252 subject
.add_line
new MDLine("")
2253 assert subject
.count_lines
== 2
2256 fun test_remove_line
do
2257 var line1
= new MDLine("line1")
2258 var line2
= new MDLine("line2")
2259 var line3
= new MDLine("line3")
2260 var subject
= new MDBlock
2261 subject
.add_line line1
2262 subject
.add_line line2
2263 subject
.add_line line3
2264 subject
.remove_line
(line2
)
2265 assert subject
.count_lines
== 2
2266 subject
.remove_line
(line1
)
2267 assert subject
.count_lines
== 1
2268 assert subject
.first_line
== line3
2269 assert subject
.last_line
== line3
2272 fun test_transform_headline1
do
2273 var subject
= new MDBlock
2274 var kind
= new BlockHeadline(subject
)
2275 subject
.add_line
new MDLine(" # Title 1 ")
2276 kind
.transform_headline
(subject
)
2277 assert kind
.depth
== 1
2278 assert subject
.first_line
.value
== "Title 1"
2281 fun test_transform_headline2
do
2282 var subject
= new MDBlock
2283 var kind
= new BlockHeadline(subject
)
2284 subject
.add_line
new MDLine(" #####Title 5 ")
2285 kind
.transform_headline
(subject
)
2286 assert kind
.depth
== 5
2287 assert subject
.first_line
.value
== "Title 5"
2290 fun test_remove_quote_prefix
do
2291 var subject
= new MDBlock
2292 var kind
= new BlockQuote(subject
)
2293 subject
.add_line
new MDLine(" > line 1")
2294 subject
.add_line
new MDLine(" > line 2")
2295 subject
.add_line
new MDLine(" > line 3")
2296 kind
.remove_block_quote_prefix
(subject
)
2297 assert subject
.first_line
.value
== "line 1"
2298 assert subject
.first_line
.next
.value
== "line 2"
2299 assert subject
.first_line
.next
.next
.value
== "line 3"
2302 fun test_remove_leading_empty_lines_1
do
2303 var block
= new MDBlock
2304 block
.add_line
new MDLine("")
2305 block
.add_line
new MDLine("")
2306 block
.add_line
new MDLine("")
2307 block
.add_line
new MDLine("")
2308 block
.add_line
new MDLine(" text")
2309 block
.add_line
new MDLine("")
2310 assert block
.remove_leading_empty_lines
2311 assert block
.first_line
.value
== " text"
2314 fun test_remove_leading_empty_lines_2
do
2315 var block
= new MDBlock
2316 block
.add_line
new MDLine(" text")
2317 block
.remove_leading_empty_lines
2318 assert block
.first_line
.value
== " text"
2321 fun test_remove_trailing_empty_lines_1
do
2322 var block
= new MDBlock
2323 block
.add_line
new MDLine("")
2324 block
.add_line
new MDLine("text")
2325 block
.add_line
new MDLine("")
2326 block
.add_line
new MDLine("")
2327 block
.add_line
new MDLine("")
2328 block
.add_line
new MDLine("")
2329 assert block
.remove_trailing_empty_lines
2330 assert block
.last_line
.value
== "text"
2333 fun test_remove_trailing_empty_lines_2
do
2334 var block
= new MDBlock
2335 block
.add_line
new MDLine("text ")
2336 assert not block
.remove_trailing_empty_lines
2337 assert block
.last_line
.value
== "text "
2340 fun test_remove_surrounding_empty_lines
do
2341 var block
= new MDBlock
2342 block
.add_line
new MDLine("")
2343 block
.add_line
new MDLine("text")
2344 block
.add_line
new MDLine("")
2345 block
.add_line
new MDLine("")
2346 block
.add_line
new MDLine("")
2347 block
.add_line
new MDLine("")
2348 assert block
.remove_surrounding_empty_lines
2349 assert block
.first_line
.value
== "text"
2350 assert block
.last_line
.value
== "text"
2361 fun test_is_empty
do
2362 subject
= new MDLine("")
2363 assert subject
.is_empty
2364 subject
= new MDLine(" ")
2365 assert subject
.is_empty
2366 subject
= new MDLine("test")
2367 assert not subject
.is_empty
2368 subject
= new MDLine(" test")
2369 assert not subject
.is_empty
2373 subject
= new MDLine("")
2374 assert subject
.leading
== 0
2375 subject
= new MDLine(" ")
2376 assert subject
.leading
== 4
2377 subject
= new MDLine("test")
2378 assert subject
.leading
== 0
2379 subject
= new MDLine(" test")
2380 assert subject
.leading
== 4
2383 fun test_trailing
do
2384 subject
= new MDLine("")
2385 assert subject
.trailing
== 0
2386 subject
= new MDLine(" ")
2387 assert subject
.trailing
== 0
2388 subject
= new MDLine("test ")
2389 assert subject
.trailing
== 3
2390 subject
= new MDLine(" test ")
2391 assert subject
.trailing
== 1
2394 fun test_line_type
do
2395 var v
= new MarkdownProcessor
2396 subject
= new MDLine("")
2397 assert subject
.kind
(v
) isa LineEmpty
2398 subject
= new MDLine(" ")
2399 assert subject
.kind
(v
) isa LineEmpty
2400 subject
= new MDLine("text ")
2401 assert subject
.kind
(v
) isa LineOther
2402 subject
= new MDLine(" # Title")
2403 assert subject
.kind
(v
) isa LineHeadline
2404 subject
= new MDLine(" ### Title")
2405 assert subject
.kind
(v
) isa LineHeadline
2406 subject
= new MDLine(" code")
2407 assert subject
.kind
(v
) isa LineCode
2408 subject
= new MDLine(" ~~~")
2409 assert subject
.kind
(v
) isa LineFence
2410 subject
= new MDLine(" ```")
2411 assert subject
.kind
(v
) isa LineFence
2412 subject
= new MDLine(" Title ")
2413 subject
.next
= new MDLine("== ")
2414 assert subject
.kind
(v
) isa LineHeadline1
2415 subject
= new MDLine(" Title ")
2416 subject
.next
= new MDLine("-- ")
2417 assert subject
.kind
(v
) isa LineHeadline2
2418 subject
= new MDLine(" * * * ")
2419 assert subject
.kind
(v
) isa LineHR
2420 subject
= new MDLine(" *** ")
2421 assert subject
.kind
(v
) isa LineHR
2422 subject
= new MDLine("- -- ")
2423 assert subject
.kind
(v
) isa LineHR
2424 subject
= new MDLine("--------- ")
2425 assert subject
.kind
(v
) isa LineHR
2426 subject
= new MDLine(" >")
2427 assert subject
.kind
(v
) isa LineBlockquote
2428 subject
= new MDLine("<p></p>")
2429 assert subject
.kind
(v
) isa LineXML
2430 subject
= new MDLine("<p>")
2431 assert subject
.kind
(v
) isa LineOther
2432 subject
= new MDLine(" * foo")
2433 assert subject
.kind
(v
) isa LineUList
2434 subject
= new MDLine("- foo")
2435 assert subject
.kind
(v
) isa LineUList
2436 subject
= new MDLine("+ foo")
2437 assert subject
.kind
(v
) isa LineUList
2438 subject
= new MDLine("1. foo")
2439 assert subject
.kind
(v
) isa LineOList
2440 subject
= new MDLine(" 11111. foo")
2441 assert subject
.kind
(v
) isa LineOList
2444 fun test_count_chars
do
2445 subject
= new MDLine("")
2446 assert subject
.count_chars
('*') == 0
2447 subject
= new MDLine("* ")
2448 assert subject
.count_chars
('*') == 1
2449 subject
= new MDLine(" * text")
2450 assert subject
.count_chars
('*') == 0
2451 subject
= new MDLine(" * * *")
2452 assert subject
.count_chars
('*') == 3
2453 subject
= new MDLine("text ** ")
2454 assert subject
.count_chars
('*') == 0
2457 fun test_count_chars_start
do
2458 subject
= new MDLine("")
2459 assert subject
.count_chars_start
('*') == 0
2460 subject
= new MDLine("* ")
2461 assert subject
.count_chars_start
('*') == 1
2462 subject
= new MDLine(" * text")
2463 assert subject
.count_chars_start
('*') == 1
2464 subject
= new MDLine(" * * * text")
2465 assert subject
.count_chars_start
('*') == 3
2466 subject
= new MDLine("text ** ")
2467 assert subject
.count_chars_start
('*') == 0
2471 class TestHTMLDecorator
2474 fun test_headlines
do
2488 var proc
= new MarkdownProcessor
2489 var decorator
= proc
.emitter
.decorator
.as(HTMLDecorator)
2492 for id
, headline
in decorator
.headlines
do
2493 res
+= "{headline.title}:{id}\n"