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_code3
do
453 Here is an example of AppleScript:
455 tell application "Foo"
460 © 2004 Foo Corporation
465 <p>Here is an example of AppleScript:</p>
466 <pre><code>tell application "Foo"
470 <div class="footer">
471 &copy; 2004 Foo Corporation
475 var res
= test
.md_to_html
.write_to_string
479 fun test_process_code4
do
481 Here is an example of AppleScript:
483 tell application "Foo"
488 © 2004 Foo Corporation
493 <p>Here is an example of AppleScript:</p>
494 <pre><code>tell application "Foo"
498 <div class="footer">
499 &copy; 2004 Foo Corporation
503 var res
= test
.md_to_html
.write_to_string
508 fun test_process_nesting1
do
510 > ## This is a header.
512 > 1. This is the first list item.
513 > 2. This is the second list item.
515 > Here's some example code:
517 > return shell_exec("echo $input | $markdown_script");
521 <h2 id="This_is_a_header.">This is a header.</h2>
523 <li>This is the first list item.</li>
524 <li>This is the second list item.</li>
526 <p>Here's some example code:</p>
527 <pre><code>return shell_exec("echo $input | $markdown_script");
531 var res
= test
.md_to_html
.write_to_string
535 fun test_process_nesting2
do
537 * A list item with a blockquote:
539 > This is a blockquote
540 > inside a list item.
544 <li><p>A list item with a blockquote:</p>
546 <p>This is a blockquote
547 inside a list item.</p>
552 var res
= test
.md_to_html
.write_to_string
556 fun test_process_nesting3
do
558 * A list item with a code block:
564 <li><p>A list item with a code block:</p>
565 <pre><code><code goes here>
570 var res
= test
.md_to_html
.write_to_string
574 fun test_process_nesting4
do
591 var res
= test
.md_to_html
.write_to_string
596 # fun test_process_nesting5 do
614 # var res = test.md_to_html.write_to_string
618 fun test_process_emph1
do
626 __double underscores__
628 var exp
= """<p><em>single asterisks</em></p>
629 <p><em>single underscores</em></p>
630 <p><strong>double asterisks</strong></p>
631 <p><strong>double underscores</strong></p>
633 var res
= test
.md_to_html
.write_to_string
637 fun test_process_emph2
do
638 var test
= "un*frigging*believable"
639 var exp
= "<p>un<em>frigging</em>believable</p>\n"
640 var res
= test
.md_to_html
.write_to_string
644 fun test_process_xml1
do
646 This is a regular paragraph.
654 This is another regular paragraph.
657 <p>This is a regular paragraph.</p>
663 <p>This is another regular paragraph.</p>
665 var res
= test
.md_to_html
.write_to_string
669 fun test_process_xml2
do
671 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
673 var exp
= """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
675 var res
= test
.md_to_html
.write_to_string
679 fun test_process_xml3
do
686 var res
= test
.md_to_html
.write_to_string
690 fun test_process_span_code1
do
691 var test
= "Use the `printf()` function."
692 var exp
= "<p>Use the <code>printf()</code> function.</p>\n"
693 var res
= test
.md_to_html
.write_to_string
697 fun test_process_span_code2
do
698 var test
= "``There is a literal backtick (`) here.``"
699 var exp
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
700 var res
= test
.md_to_html
.write_to_string
704 fun test_process_span_code3
do
706 A single backtick in a code span: `` ` ``
708 A backtick-delimited string in a code span: `` `foo` ``
711 <p>A single backtick in a code span: <code>`</code></p>
712 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
714 var res
= test
.md_to_html
.write_to_string
718 fun test_process_span_code4
do
719 var test
= "Please don't use any `<blink>` tags."
720 var exp
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
721 var res
= test
.md_to_html
.write_to_string
725 fun test_process_span_code5
do
726 var test
= "`—` is the decimal-encoded equivalent of `—`."
727 var exp
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
728 var res
= test
.md_to_html
.write_to_string
732 fun test_process_escape1
do
733 var test
= "\\*this text is surrounded by literal asterisks\\*"
734 var exp
= "<p>*this text is surrounded by literal asterisks*</p>\n"
735 var res
= test
.md_to_html
.write_to_string
739 fun test_process_escape2
do
740 var test
= "1986\\. What a great season."
741 var exp
= "<p>1986. What a great season.</p>\n"
742 var res
= test
.md_to_html
.write_to_string
746 fun test_process_escape3
do
747 var test
= "Ben & Lux"
748 var exp
= "<p>Ben & Lux</p>\n"
749 var res
= test
.md_to_html
.write_to_string
753 fun test_process_link1
do
755 This is [an example](http://example.com/ "Title") inline link.
757 [This link](http://example.net/) has no title attribute.
759 var exp
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
760 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
762 var res
= test
.md_to_html
.write_to_string
766 fun test_process_link2
do
767 var test
= "See my [About](/about/) page for details."
768 var exp
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
769 var res
= test
.md_to_html
.write_to_string
773 fun test_process_link3
do
775 This is [an example][id] reference-style link.
777 This is [an example] [id] reference-style link.
781 [id]: http://example.com/ "Optional Title Here"
786 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
787 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
788 <p>Some lorem ipsum</p>
789 <p>Some other lipsum</p>
791 var res
= test
.md_to_html
.write_to_string
795 fun test_process_link4
do
797 This is multiple examples: [foo][1], [bar][2], [baz][3].
799 [1]: http://example.com/ "Optional Title Here"
800 [2]: http://example.com/ 'Optional Title Here'
801 [3]: http://example.com/ (Optional Title Here)
804 <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>
806 var res
= test
.md_to_html
.write_to_string
810 fun test_process_link5
do
812 This is multiple examples: [foo][a], [bar][A], [a].
814 [a]: http://example.com/ "Optional Title Here"
816 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>
818 var res
= test
.md_to_html
.write_to_string
822 fun test_process_link6
do
824 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
826 [Google]: http://google.com/ "Google"
827 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
828 [MSN]: http://search.msn.com/ "MSN Search"
830 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>
832 var res
= test
.md_to_html
.write_to_string
836 fun test_process_link7
do
838 Visit [Daring Fireball][] for more information.
840 [Daring Fireball]: http://daringfireball.net/
842 var exp
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
844 var res
= test
.md_to_html
.write_to_string
848 fun test_process_link8
do
854 break] with a line-ending space.
859 <p>This one has a <a href="/foo">line
861 <p>This one has a <a href="/foo">line
862 break</a> with a line-ending space.</p>
864 var res
= test
.md_to_html
.write_to_string
868 # FIXME unignore test once escape strings fixed
869 # fun test_process_link9 do
873 # Foo [bar](/url/ "Title with \"quotes\" inside").
876 # [bar]: /url/ "Title with \"quotes\" inside"
879 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
880 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
882 # var res = test.md_to_html.write_to_string
886 fun test_process_img1
do
888 ![Alt text](/path/to/img.jpg)
890 ![Alt text](/path/to/img.jpg "Optional title")
892 var exp
= """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
893 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
895 var res
= test
.md_to_html
.write_to_string
899 fun test_process_img2
do
903 [id]: url/to/image "Optional title attribute"
905 var exp
= """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
907 var res
= test
.md_to_html
.write_to_string
911 fun test_daring_encoding
do
913 AT&T has an ampersand in their name.
915 AT&T is another way to write it.
923 Here's a [link] [1] with an ampersand in the URL.
925 Here's a link with an amersand in the link text: [AT&T] [2].
927 Here's an inline [link](/script?foo=1&bar=2).
929 Here's an inline [link](</script?foo=1&bar=2>).
932 [1]: http://example.com/?foo=1&bar=2
933 [2]: http://att.com/ "AT&T"
937 <p>AT&T has an ampersand in their name.</p>
938 <p>AT&T is another way to write it.</p>
939 <p>This & that.</p>
942 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
943 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
944 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
945 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
947 var res
= test
.md_to_html
.write_to_string
952 fun test_daring_autolinks
do
954 Link: <http://example.com/>.
956 With an ampersand: <http://example.com/?foo=1&bar=2>
959 * <http://example.com/>
962 > Blockquoted: <http://example.com/>
964 Auto-links should not occur here: `<http://example.com/>`
966 or here: <http://example.com/>
970 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
971 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
974 <li><a href="http://example.com/">http://example.com/</a></li>
978 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
980 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
981 <pre><code>or here: <http://example.com/>
984 var res
= test
.md_to_html
.write_to_string
988 fun test_daring_escape
do
990 These should all get escaped:
1025 These should not, because they occur within a code block:
1059 Nor should these, which occur in code spans:
1093 These should get escaped, even though they're matching pairs for
1094 other Markdown constructs:
1102 This is a code span with a literal backslash-backtick sequence: `` \` ``
1104 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1106 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1109 <p>These should all get escaped:</p>
1110 <p>Backslash: \\</p>
1113 <p>Underscore: \_</p>
1114 <p>Left brace: \{</p>
1115 <p>Right brace: \}</p>
1116 <p>Left bracket: \[</p>
1117 <p>Right bracket: \]</p>
1118 <p>Left paren: \(</p>
1119 <p>Right paren: \)</p>
1120 <p>Greater-than: \></p>
1126 <p>These should not, because they occur within a code block:</p>
1127 <pre><code>Backslash: \\
1159 <p>Nor should these, which occur in code spans:</p>
1160 <p>Backslash: <code>\\</code></p>
1161 <p>Backtick: <code>\`</code></p>
1162 <p>Asterisk: <code>\*</code></p>
1163 <p>Underscore: <code>\_</code></p>
1164 <p>Left brace: <code>\{</code></p>
1165 <p>Right brace: <code>\}</code></p>
1166 <p>Left bracket: <code>\[</code></p>
1167 <p>Right bracket: <code>\]</code></p>
1168 <p>Left paren: <code>\(</code></p>
1169 <p>Right paren: <code>\)</code></p>
1170 <p>Greater-than: <code>\></code></p>
1171 <p>Hash: <code>\#</code></p>
1172 <p>Period: <code>\.</code></p>
1173 <p>Bang: <code>\!</code></p>
1174 <p>Plus: <code>\+</code></p>
1175 <p>Minus: <code>\-</code></p>
1176 <p>These should get escaped, even though they're matching pairs for
1177 other Markdown constructs:</p>
1179 <p>_underscores_</p>
1181 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1182 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1183 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1186 var res
= test
.md_to_html
.write_to_string
1190 fun test_daring_blockquotes
do
1208 <pre><code>sub status {
1213 <pre><code>sub status {
1219 var res
= test
.md_to_html
.write_to_string
1223 fun test_daring_code_blocks
do
1225 code block on the first line
1229 code block indented by spaces
1233 the lines in this block
1234 all contain trailing spaces
1238 code block on the last line
1242 <pre><code>code block on the first line
1244 <p>Regular text.</p>
1245 <pre><code>code block indented by spaces
1247 <p>Regular text.</p>
1248 <pre><code>the lines in this block
1249 all contain trailing spaces
1251 <p>Regular Text.</p>
1252 <pre><code>code block on the last line
1255 var res
= test
.md_to_html
.write_to_string
1259 fun test_daring_code_spans
do
1261 `<test a="` content of attribute `">`
1263 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1265 Here's how you put `` `backticks` `` in a code span.
1269 <p><code><test a="</code> content of attribute <code>"></code></p>
1270 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1271 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1273 var res
= test
.md_to_html
.write_to_string
1277 fun test_daring_pars
do
1279 In Markdown 1.0.0 and earlier. Version
1280 8. This line turns into a list item.
1281 Because a hard-wrapped line in the
1282 middle of a paragraph looked like a
1285 Here's one with a bullet.
1290 <p>In Markdown 1.0.0 and earlier. Version
1291 8. This line turns into a list item.
1292 Because a hard-wrapped line in the
1293 middle of a paragraph looked like a
1295 <p>Here's one with a bullet.
1298 var res
= test
.md_to_html
.write_to_string
1302 fun test_daring_rules
do
1414 var res
= test
.md_to_html
.write_to_string
1418 fun test_daring_images
do
1420 ![Alt text](/path/to/img.jpg)
1422 ![Alt text](/path/to/img.jpg "Optional title")
1424 Inline within a paragraph: [alt text](/url/).
1426 ![alt text](/url/ "title preceded by two spaces")
1428 ![alt text](/url/ "title has spaces afterward" )
1430 ![alt text](</url/>)
1432 ![alt text](</url/> "with a title").
1436 ![this is a stupid URL](http://example.com/(parens).jpg)
1445 [bar]: /url/ "Title here"
1449 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1450 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1451 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1452 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1453 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1454 <p><img src="/url/" alt="alt text"/></p>
1455 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1456 <p><img src="" alt="Empty"/></p>
1457 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1458 <p><img src="/url/" alt="alt text"/></p>
1459 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1461 var res
= test
.md_to_html
.write_to_string
1465 fun test_daring_inline_html1
do
1467 Here's a simple block:
1473 This should be a code block, though:
1493 This should just be an HTML comment:
1508 Just plain comment, with trailing spaces on the line:
1530 <hr class="foo" id="bar" />
1532 <hr class="foo" id="bar"/>
1534 <hr class="foo" id="bar" >
1538 <p>Here's a simple block:</p>
1542 <p>This should be a code block, though:</p>
1543 <pre><code><div>
1547 <p>As should this:</p>
1548 <pre><code><div>foo</div>
1558 <p>This should just be an HTML comment:</p>
1566 <pre><code><!-- Comment -->
1568 <p>Just plain comment, with trailing spaces on the line:</p>
1571 <pre><code><hr />
1580 <hr class="foo" id="bar" />
1581 <hr class="foo" id="bar"/>
1582 <hr class="foo" id="bar" >
1584 var res
= test
.md_to_html
.write_to_string
1588 fun test_daring_inline_html2
do
1590 Simple block on one line:
1594 And nested without indentation:
1606 And with attributes:
1613 This was broken in 1.0.2b7:
1615 <div class="inlinepage">
1616 <div class="toggleableend">
1623 <p>Simple block on one line:</p>
1625 <p>And nested without indentation:</p>
1635 <p>And with attributes:</p>
1640 <p>This was broken in 1.0.2b7:</p>
1641 <div class="inlinepage">
1642 <div class="toggleableend">
1647 var res
= test
.md_to_html
.write_to_string
1651 fun test_daring_inline_html3
do
1655 <!-- This is a simple comment -->
1658 This is another comment.
1663 <!-- one comment block -- -- with two comments -->
1669 <p>Paragraph one.</p>
1670 <!-- This is a simple comment -->
1672 This is another comment.
1674 <p>Paragraph two.</p>
1675 <!-- one comment block -- -- with two comments -->
1678 var res
= test
.md_to_html
.write_to_string
1682 fun test_daring_links1
do
1684 Just a [URL](/url/).
1686 [URL and title](/url/ "title").
1688 [URL and title](/url/ "title preceded by two spaces").
1690 [URL and title](/url/ "title preceded by a tab").
1692 [URL and title](/url/ "title has spaces afterward" ).
1694 [URL wrapped in angle brackets](</url/>).
1696 [URL w/ angle brackets + title](</url/> "Here's the title").
1700 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1702 (With outer parens and [parens in url](/foo(bar)))
1705 [With parens in the URL](/foo(bar) "and a title")
1707 (With outer parens and [parens in url](/foo(bar) "and a title"))
1711 <p>Just a <a href="/url/">URL</a>.</p>
1712 <p><a href="/url/" title="title">URL and title</a>.</p>
1713 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1714 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1715 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1716 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1717 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
1718 <p><a href="">Empty</a>.</p>
1719 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1720 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1721 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1722 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1724 var res
= test
.md_to_html
.write_to_string
1728 fun test_daring_links2
do
1740 With [embedded [brackets]] [b].
1747 Indented [thrice][].
1749 Indented [four][] times.
1764 [this] [this] should work
1766 So should [this][this].
1780 [Something in brackets like [this][] should work]
1784 In this case, [this](/somethingelse/) points to something else.
1786 Backslashing should suppress \\\[this] and [this\\\].
1793 Here's one where the [link
1794 breaks] across lines.
1796 Here's another where the [link
1797 breaks] across lines, but with a line-ending space.
1800 [link breaks]: /url/
1804 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1805 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1806 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1807 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1808 <p>Indented <a href="/url">once</a>.</p>
1809 <p>Indented <a href="/url">twice</a>.</p>
1810 <p>Indented <a href="/url">thrice</a>.</p>
1811 <p>Indented [four][] times.</p>
1812 <pre><code>[four]: /url
1815 <p><a href="foo">this</a> should work</p>
1816 <p>So should <a href="foo">this</a>.</p>
1817 <p>And <a href="foo">this</a>.</p>
1818 <p>And <a href="foo">this</a>.</p>
1819 <p>And <a href="foo">this</a>.</p>
1820 <p>But not [that] [].</p>
1821 <p>Nor [that][].</p>
1823 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
1824 <p>[Same with <a href="foo">this</a>.]</p>
1825 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
1826 <p>Backslashing should suppress [this] and [this].</p>
1828 <p>Here's one where the <a href="/url/">link
1829 breaks</a> across lines.</p>
1830 <p>Here's another where the <a href="/url/">link
1831 breaks</a> across lines, but with a line-ending space.</p>
1833 var res
= test
.md_to_html
.write_to_string
1837 fun test_daring_links3
do
1839 This is the [simple case].
1841 [simple case]: /simple
1845 This one has a [line
1848 This one has a [line
1849 break] with a line-ending space.
1854 [this] [that] and the [other]
1862 <p>This is the <a href="/simple">simple case</a>.</p>
1863 <p>This one has a <a href="/foo">line
1865 <p>This one has a <a href="/foo">line
1866 break</a> with a line-ending space.</p>
1867 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
1869 var res
= test
.md_to_html
.write_to_string
1873 fun test_daring_nested
do
1891 var res
= test
.md_to_html
.write_to_string
1895 fun test_daring_list
do
1981 Multiple paragraphs:
1983 1. Item 1, graf one.
1985 Item 2. graf two. The quick brown fox jumped over the lazy dog's
2009 Same thing but with paragraphs:
2022 <h2 id="Unordered">Unordered</h2>
2023 <p>Asterisks tight:</p>
2029 <p>Asterisks loose:</p>
2031 <li><p>asterisk 1</p>
2033 <li><p>asterisk 2</p>
2035 <li><p>asterisk 3</p>
2039 <p>Pluses tight:</p>
2045 <p>Pluses loose:</p>
2055 <p>Minuses tight:</p>
2061 <p>Minuses loose:</p>
2070 <h2 id="Ordered">Ordered</h2>
2083 <p>Loose using tabs:</p>
2092 <p>and using spaces:</p>
2101 <p>Multiple paragraphs:</p>
2103 <li><p>Item 1, graf one.</p>
2104 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2112 <h2 id="Nested">Nested</h2>
2122 <p>Here's another:</p>
2133 <p>Same thing but with paragraphs:</p>
2148 var res
= test
.md_to_html
.write_to_string
2152 fun test_daring_strong_em
do
2154 ***This is strong and em.***
2156 So is ***this*** word.
2158 ___This is strong and em.___
2160 So is ___this___ word.
2164 <p><strong><em>This is strong and em.</em></strong></p>
2165 <p>So is <strong><em>this</em></strong> word.</p>
2166 <p><strong><em>This is strong and em.</em></strong></p>
2167 <p>So is <strong><em>this</em></strong> word.</p>
2169 var res
= test
.md_to_html
.write_to_string
2173 fun test_daring_tabs
do
2175 + this is a list item
2178 + this is a list item
2179 indented with spaces
2183 this code block is indented by one tab
2187 this code block is indented by two tabs
2191 + this is an example list item
2194 + this is an example list item
2195 indented with spaces
2200 <li><p>this is a list item
2201 indented with tabs</p>
2203 <li><p>this is a list item
2204 indented with spaces</p>
2208 <pre><code>this code block is indented by one tab
2211 <pre><code> this code block is indented by two tabs
2214 <pre><code>+ this is an example list item
2217 + this is an example list item
2218 indented with spaces
2221 var res
= test
.md_to_html
.write_to_string
2225 fun test_daring_tidyness
do
2227 > A list within a blockquote:
2236 <p>A list within a blockquote:</p>
2244 var res
= test
.md_to_html
.write_to_string
2254 fun test_has_blocks
do
2255 var subject
= new MDBlock
2256 assert not subject
.has_blocks
2257 subject
.first_block
= new MDBlock
2258 assert subject
.has_blocks
2261 fun test_count_blocks
do
2262 var subject
= new MDBlock
2263 assert subject
.count_blocks
== 0
2264 subject
.first_block
= new MDBlock
2265 assert subject
.count_blocks
== 1
2266 subject
.first_block
.next
= new MDBlock
2267 assert subject
.count_blocks
== 2
2270 fun test_has_lines
do
2271 var subject
= new MDBlock
2272 assert not subject
.has_lines
2273 subject
.first_line
= new MDLine("")
2274 assert subject
.has_lines
2277 fun test_count_lines
do
2278 var subject
= new MDBlock
2279 assert subject
.count_lines
== 0
2280 subject
.first_line
= new MDLine("")
2281 assert subject
.count_lines
== 1
2282 subject
.first_line
.next
= new MDLine("")
2283 assert subject
.count_lines
== 2
2287 var line1
= new MDLine("line1")
2288 var line2
= new MDLine("line2")
2289 var line3
= new MDLine("line3")
2290 var subject
= new MDBlock
2291 subject
.add_line line1
2292 subject
.add_line line2
2293 subject
.add_line line3
2294 var block
= subject
.split
(line2
)
2295 assert subject
.count_blocks
== 1
2296 assert subject
.count_lines
== 1
2297 assert subject
.first_line
== line3
2298 assert block
.count_blocks
== 0
2299 assert block
.count_lines
== 2
2300 assert block
.first_line
== line1
2301 assert block
.last_line
== line2
2304 fun test_add_line
do
2305 var subject
= new MDBlock
2306 assert subject
.count_lines
== 0
2307 subject
.add_line
new MDLine("")
2308 assert subject
.count_lines
== 1
2309 subject
.add_line
new MDLine("")
2310 assert subject
.count_lines
== 2
2313 fun test_remove_line
do
2314 var line1
= new MDLine("line1")
2315 var line2
= new MDLine("line2")
2316 var line3
= new MDLine("line3")
2317 var subject
= new MDBlock
2318 subject
.add_line line1
2319 subject
.add_line line2
2320 subject
.add_line line3
2321 subject
.remove_line
(line2
)
2322 assert subject
.count_lines
== 2
2323 subject
.remove_line
(line1
)
2324 assert subject
.count_lines
== 1
2325 assert subject
.first_line
== line3
2326 assert subject
.last_line
== line3
2329 fun test_transform_headline1
do
2330 var subject
= new MDBlock
2331 var kind
= new BlockHeadline(subject
)
2332 subject
.add_line
new MDLine(" # Title 1 ")
2333 kind
.transform_headline
(subject
)
2334 assert kind
.depth
== 1
2335 assert subject
.first_line
.value
== "Title 1"
2338 fun test_transform_headline2
do
2339 var subject
= new MDBlock
2340 var kind
= new BlockHeadline(subject
)
2341 subject
.add_line
new MDLine(" #####Title 5 ")
2342 kind
.transform_headline
(subject
)
2343 assert kind
.depth
== 5
2344 assert subject
.first_line
.value
== "Title 5"
2347 fun test_remove_quote_prefix
do
2348 var subject
= new MDBlock
2349 var kind
= new BlockQuote(subject
)
2350 subject
.add_line
new MDLine(" > line 1")
2351 subject
.add_line
new MDLine(" > line 2")
2352 subject
.add_line
new MDLine(" > line 3")
2353 kind
.remove_block_quote_prefix
(subject
)
2354 assert subject
.first_line
.value
== "line 1"
2355 assert subject
.first_line
.next
.value
== "line 2"
2356 assert subject
.first_line
.next
.next
.value
== "line 3"
2359 fun test_remove_leading_empty_lines_1
do
2360 var block
= new MDBlock
2361 block
.add_line
new MDLine("")
2362 block
.add_line
new MDLine("")
2363 block
.add_line
new MDLine("")
2364 block
.add_line
new MDLine("")
2365 block
.add_line
new MDLine(" text")
2366 block
.add_line
new MDLine("")
2367 assert block
.remove_leading_empty_lines
2368 assert block
.first_line
.value
== " text"
2371 fun test_remove_leading_empty_lines_2
do
2372 var block
= new MDBlock
2373 block
.add_line
new MDLine(" text")
2374 block
.remove_leading_empty_lines
2375 assert block
.first_line
.value
== " text"
2378 fun test_remove_trailing_empty_lines_1
do
2379 var block
= new MDBlock
2380 block
.add_line
new MDLine("")
2381 block
.add_line
new MDLine("text")
2382 block
.add_line
new MDLine("")
2383 block
.add_line
new MDLine("")
2384 block
.add_line
new MDLine("")
2385 block
.add_line
new MDLine("")
2386 assert block
.remove_trailing_empty_lines
2387 assert block
.last_line
.value
== "text"
2390 fun test_remove_trailing_empty_lines_2
do
2391 var block
= new MDBlock
2392 block
.add_line
new MDLine("text ")
2393 assert not block
.remove_trailing_empty_lines
2394 assert block
.last_line
.value
== "text "
2397 fun test_remove_surrounding_empty_lines
do
2398 var block
= new MDBlock
2399 block
.add_line
new MDLine("")
2400 block
.add_line
new MDLine("text")
2401 block
.add_line
new MDLine("")
2402 block
.add_line
new MDLine("")
2403 block
.add_line
new MDLine("")
2404 block
.add_line
new MDLine("")
2405 assert block
.remove_surrounding_empty_lines
2406 assert block
.first_line
.value
== "text"
2407 assert block
.last_line
.value
== "text"
2418 fun test_is_empty
do
2419 subject
= new MDLine("")
2420 assert subject
.is_empty
2421 subject
= new MDLine(" ")
2422 assert subject
.is_empty
2423 subject
= new MDLine("test")
2424 assert not subject
.is_empty
2425 subject
= new MDLine(" test")
2426 assert not subject
.is_empty
2430 subject
= new MDLine("")
2431 assert subject
.leading
== 0
2432 subject
= new MDLine(" ")
2433 assert subject
.leading
== 4
2434 subject
= new MDLine("test")
2435 assert subject
.leading
== 0
2436 subject
= new MDLine(" test")
2437 assert subject
.leading
== 4
2440 fun test_trailing
do
2441 subject
= new MDLine("")
2442 assert subject
.trailing
== 0
2443 subject
= new MDLine(" ")
2444 assert subject
.trailing
== 0
2445 subject
= new MDLine("test ")
2446 assert subject
.trailing
== 3
2447 subject
= new MDLine(" test ")
2448 assert subject
.trailing
== 1
2451 fun test_line_type
do
2452 var v
= new MarkdownProcessor
2453 subject
= new MDLine("")
2454 assert v
.line_kind
(subject
) isa LineEmpty
2455 subject
= new MDLine(" ")
2456 assert v
.line_kind
(subject
) isa LineEmpty
2457 subject
= new MDLine("text ")
2458 assert v
.line_kind
(subject
) isa LineOther
2459 subject
= new MDLine(" # Title")
2460 assert v
.line_kind
(subject
) isa LineHeadline
2461 subject
= new MDLine(" ### Title")
2462 assert v
.line_kind
(subject
) isa LineHeadline
2463 subject
= new MDLine(" code")
2464 assert v
.line_kind
(subject
) isa LineCode
2465 subject
= new MDLine(" ~~~")
2466 assert v
.line_kind
(subject
) isa LineFence
2467 subject
= new MDLine(" ```")
2468 assert v
.line_kind
(subject
) isa LineFence
2469 subject
= new MDLine(" Title ")
2470 subject
.next
= new MDLine("== ")
2471 assert v
.line_kind
(subject
) isa LineHeadline1
2472 subject
= new MDLine(" Title ")
2473 subject
.next
= new MDLine("-- ")
2474 assert v
.line_kind
(subject
) isa LineHeadline2
2475 subject
= new MDLine(" * * * ")
2476 assert v
.line_kind
(subject
) isa LineHR
2477 subject
= new MDLine(" *** ")
2478 assert v
.line_kind
(subject
) isa LineHR
2479 subject
= new MDLine("- -- ")
2480 assert v
.line_kind
(subject
) isa LineHR
2481 subject
= new MDLine("--------- ")
2482 assert v
.line_kind
(subject
) isa LineHR
2483 subject
= new MDLine(" >")
2484 assert v
.line_kind
(subject
) isa LineBlockquote
2485 subject
= new MDLine("<p></p>")
2486 assert v
.line_kind
(subject
) isa LineXML
2487 subject
= new MDLine("<p>")
2488 assert v
.line_kind
(subject
) isa LineOther
2489 subject
= new MDLine(" * foo")
2490 assert v
.line_kind
(subject
) isa LineUList
2491 subject
= new MDLine("- foo")
2492 assert v
.line_kind
(subject
) isa LineUList
2493 subject
= new MDLine("+ foo")
2494 assert v
.line_kind
(subject
) isa LineUList
2495 subject
= new MDLine("1. foo")
2496 assert v
.line_kind
(subject
) isa LineOList
2497 subject
= new MDLine(" 11111. foo")
2498 assert v
.line_kind
(subject
) isa LineOList
2501 fun test_count_chars
do
2502 subject
= new MDLine("")
2503 assert subject
.count_chars
('*') == 0
2504 subject
= new MDLine("* ")
2505 assert subject
.count_chars
('*') == 1
2506 subject
= new MDLine(" * text")
2507 assert subject
.count_chars
('*') == 0
2508 subject
= new MDLine(" * * *")
2509 assert subject
.count_chars
('*') == 3
2510 subject
= new MDLine("text ** ")
2511 assert subject
.count_chars
('*') == 0
2514 fun test_count_chars_start
do
2515 subject
= new MDLine("")
2516 assert subject
.count_chars_start
('*') == 0
2517 subject
= new MDLine("* ")
2518 assert subject
.count_chars_start
('*') == 1
2519 subject
= new MDLine(" * text")
2520 assert subject
.count_chars_start
('*') == 1
2521 subject
= new MDLine(" * * * text")
2522 assert subject
.count_chars_start
('*') == 3
2523 subject
= new MDLine("text ** ")
2524 assert subject
.count_chars_start
('*') == 0
2528 class TestHTMLDecorator
2531 fun test_headlines
do
2545 var proc
= new MarkdownProcessor
2546 var decorator
= proc
.emitter
.decorator
.as(HTMLDecorator)
2549 for id
, headline
in decorator
.headlines
do
2550 res
+= "{headline.title}:{id}\n"