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_list11
do
413 * and this is not a list
416 <p>This is a paragraph
417 * and this is not a list</p>
419 var proc
= new MarkdownProcessor
420 proc
.ext_mode
= false
421 var res
= proc
.process
(test
).write_to_string
425 fun test_process_list_ext
do
428 * and this is not a list
431 <p>This is a paragraph</p>
433 <li>and this is not a list</li>
436 var res
= test
.md_to_html
.write_to_string
440 fun test_process_code1
do
442 This is a normal paragraph:
444 This is a code block.
446 var exp
= """<p>This is a normal paragraph:</p>
447 <pre><code>This is a code block.
450 var res
= test
.md_to_html
.write_to_string
454 fun test_process_code2
do
456 Here is an example of AppleScript:
458 tell application "Foo"
463 © 2004 Foo Corporation
467 <p>Here is an example of AppleScript:</p>
468 <pre><code>tell application "Foo"
472 <div class="footer">
473 &copy; 2004 Foo Corporation
477 var res
= test
.md_to_html
.write_to_string
481 fun test_process_code_ext1
do
483 Here is an example of AppleScript:
485 tell application "Foo"
490 © 2004 Foo Corporation
495 <p>Here is an example of AppleScript:</p>
496 <pre><code>tell application "Foo"
500 <div class="footer">
501 &copy; 2004 Foo Corporation
505 var res
= test
.md_to_html
.write_to_string
509 fun test_process_code_ext2
do
511 Here is an example of AppleScript:
513 tell application "Foo"
518 © 2004 Foo Corporation
523 <p>Here is an example of AppleScript:</p>
524 <pre><code>tell application "Foo"
528 <div class="footer">
529 &copy; 2004 Foo Corporation
533 var res
= test
.md_to_html
.write_to_string
537 fun test_process_code_ext3
do
538 var proc
= new MarkdownProcessor
539 proc
.ext_mode
= false
542 Here is an example of AppleScript:
546 <p>Here is an example of AppleScript:
549 var res
= proc
.process
(test
).write_to_string
553 fun test_process_code_ext4
do
555 Here is an example of AppleScript:
559 <p>Here is an example of AppleScript:</p>
563 var res
= test
.md_to_html
.write_to_string
567 fun test_process_code_ext5
do
574 <pre class="nit"><code>print "Hello World!"
577 var res
= test
.md_to_html
.write_to_string
581 fun test_process_code_ext6
do
591 <pre><code>print "Hello"
593 <pre><code>print "World"
596 var res
= test
.md_to_html
.write_to_string
600 fun test_process_code_ext7
do
610 <pre><code>print "Hello"
612 <pre><code>print "World"
615 var res
= test
.md_to_html
.write_to_string
619 fun test_process_nesting1
do
621 > ## This is a header.
623 > 1. This is the first list item.
624 > 2. This is the second list item.
626 > Here's some example code:
628 > return shell_exec("echo $input | $markdown_script");
632 <h2 id="This_is_a_header.">This is a header.</h2>
634 <li>This is the first list item.</li>
635 <li>This is the second list item.</li>
637 <p>Here's some example code:</p>
638 <pre><code>return shell_exec("echo $input | $markdown_script");
642 var res
= test
.md_to_html
.write_to_string
646 fun test_process_nesting2
do
648 * A list item with a blockquote:
650 > This is a blockquote
651 > inside a list item.
655 <li><p>A list item with a blockquote:</p>
657 <p>This is a blockquote
658 inside a list item.</p>
663 var res
= test
.md_to_html
.write_to_string
667 fun test_process_nesting3
do
669 * A list item with a code block:
675 <li><p>A list item with a code block:</p>
676 <pre><code><code goes here>
681 var res
= test
.md_to_html
.write_to_string
685 fun test_process_nesting4
do
702 var res
= test
.md_to_html
.write_to_string
707 # fun test_process_nesting5 do
725 # var res = test.md_to_html.write_to_string
729 fun test_process_emph1
do
737 __double underscores__
739 var exp
= """<p><em>single asterisks</em></p>
740 <p><em>single underscores</em></p>
741 <p><strong>double asterisks</strong></p>
742 <p><strong>double underscores</strong></p>
744 var res
= test
.md_to_html
.write_to_string
748 fun test_process_emph2
do
749 var test
= "un*frigging*believable"
750 var exp
= "<p>un<em>frigging</em>believable</p>\n"
751 var res
= test
.md_to_html
.write_to_string
755 fun test_process_emph3
do
756 var proc
= new MarkdownProcessor
757 proc
.ext_mode
= false
758 var test
= "Con_cat_this"
759 var exp
= "<p>Con<em>cat</em>this</p>\n"
760 var res
= proc
.process
(test
).write_to_string
764 fun test_process_emph_ext
do
765 var test
= "Con_cat_this"
766 var exp
= "<p>Con_cat_this</p>\n"
767 var res
= test
.md_to_html
.write_to_string
771 fun test_process_xml1
do
773 This is a regular paragraph.
781 This is another regular paragraph.
784 <p>This is a regular paragraph.</p>
790 <p>This is another regular paragraph.</p>
792 var res
= test
.md_to_html
.write_to_string
796 fun test_process_xml2
do
798 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
800 var exp
= """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
802 var res
= test
.md_to_html
.write_to_string
806 fun test_process_xml3
do
813 var res
= test
.md_to_html
.write_to_string
817 fun test_process_span_code1
do
818 var test
= "Use the `printf()` function."
819 var exp
= "<p>Use the <code>printf()</code> function.</p>\n"
820 var res
= test
.md_to_html
.write_to_string
824 fun test_process_span_code2
do
825 var test
= "``There is a literal backtick (`) here.``"
826 var exp
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
827 var res
= test
.md_to_html
.write_to_string
831 fun test_process_span_code3
do
833 A single backtick in a code span: `` ` ``
835 A backtick-delimited string in a code span: `` `foo` ``
838 <p>A single backtick in a code span: <code>`</code></p>
839 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
841 var res
= test
.md_to_html
.write_to_string
845 fun test_process_span_code4
do
846 var test
= "Please don't use any `<blink>` tags."
847 var exp
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
848 var res
= test
.md_to_html
.write_to_string
852 fun test_process_span_code5
do
853 var test
= "`—` is the decimal-encoded equivalent of `—`."
854 var exp
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
855 var res
= test
.md_to_html
.write_to_string
859 fun test_process_escape1
do
860 var test
= "\\*this text is surrounded by literal asterisks\\*"
861 var exp
= "<p>*this text is surrounded by literal asterisks*</p>\n"
862 var res
= test
.md_to_html
.write_to_string
866 fun test_process_escape2
do
867 var test
= "1986\\. What a great season."
868 var exp
= "<p>1986. What a great season.</p>\n"
869 var res
= test
.md_to_html
.write_to_string
873 fun test_process_escape3
do
874 var test
= "Ben & Lux"
875 var exp
= "<p>Ben & Lux</p>\n"
876 var res
= test
.md_to_html
.write_to_string
880 fun test_process_link1
do
882 This is [an example](http://example.com/ "Title") inline link.
884 [This link](http://example.net/) has no title attribute.
886 var exp
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
887 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
889 var res
= test
.md_to_html
.write_to_string
893 fun test_process_link2
do
894 var test
= "See my [About](/about/) page for details."
895 var exp
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
896 var res
= test
.md_to_html
.write_to_string
900 fun test_process_link3
do
902 This is [an example][id] reference-style link.
904 This is [an example] [id] reference-style link.
908 [id]: http://example.com/ "Optional Title Here"
913 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
914 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
915 <p>Some lorem ipsum</p>
916 <p>Some other lipsum</p>
918 var res
= test
.md_to_html
.write_to_string
922 fun test_process_link4
do
924 This is multiple examples: [foo][1], [bar][2], [baz][3].
926 [1]: http://example.com/ "Optional Title Here"
927 [2]: http://example.com/ 'Optional Title Here'
928 [3]: http://example.com/ (Optional Title Here)
931 <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>
933 var res
= test
.md_to_html
.write_to_string
937 fun test_process_link5
do
939 This is multiple examples: [foo][a], [bar][A], [a].
941 [a]: http://example.com/ "Optional Title Here"
943 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>
945 var res
= test
.md_to_html
.write_to_string
949 fun test_process_link6
do
951 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
953 [Google]: http://google.com/ "Google"
954 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
955 [MSN]: http://search.msn.com/ "MSN Search"
957 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>
959 var res
= test
.md_to_html
.write_to_string
963 fun test_process_link7
do
965 Visit [Daring Fireball][] for more information.
967 [Daring Fireball]: http://daringfireball.net/
969 var exp
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
971 var res
= test
.md_to_html
.write_to_string
975 fun test_process_link8
do
981 break] with a line-ending space.
986 <p>This one has a <a href="/foo">line
988 <p>This one has a <a href="/foo">line
989 break</a> with a line-ending space.</p>
991 var res
= test
.md_to_html
.write_to_string
995 # FIXME unignore test once escape strings fixed
996 # fun test_process_link9 do
1000 # Foo [bar](/url/ "Title with \"quotes\" inside").
1003 # [bar]: /url/ "Title with \"quotes\" inside"
1006 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
1007 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
1009 # var res = test.md_to_html.write_to_string
1013 fun test_process_img1
do
1015 ![Alt text](/path/to/img.jpg)
1017 ![Alt text](/path/to/img.jpg "Optional title")
1019 var exp
= """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1020 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1022 var res
= test
.md_to_html
.write_to_string
1026 fun test_process_img2
do
1030 [id]: url/to/image "Optional title attribute"
1032 var exp
= """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
1034 var res
= test
.md_to_html
.write_to_string
1038 fun test_process_strike
do
1039 var proc
= new MarkdownProcessor
1040 proc
.ext_mode
= false
1041 var test
= "This is how you ~~strike text~~"
1042 var exp
= "<p>This is how you ~~strike text~~</p>\n"
1043 var res
= proc
.process
(test
).write_to_string
1047 fun test_process_strike_ext
do
1048 var test
= "This is how you ~~strike text~~"
1049 var exp
= "<p>This is how you <del>strike text</del></p>\n"
1050 var res
= test
.md_to_html
.write_to_string
1054 fun test_escape_bad_html
do
1055 var test
= "-1 if < , +1 if > and 0 otherwise"
1056 var exp
= "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
1057 var res
= test
.md_to_html
.write_to_string
1061 fun test_daring_encoding
do
1063 AT&T has an ampersand in their name.
1065 AT&T is another way to write it.
1073 Here's a [link] [1] with an ampersand in the URL.
1075 Here's a link with an amersand in the link text: [AT&T] [2].
1077 Here's an inline [link](/script?foo=1&bar=2).
1079 Here's an inline [link](</script?foo=1&bar=2>).
1082 [1]: http://example.com/?foo=1&bar=2
1083 [2]: http://att.com/ "AT&T"
1087 <p>AT&T has an ampersand in their name.</p>
1088 <p>AT&T is another way to write it.</p>
1089 <p>This & that.</p>
1092 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
1093 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
1094 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1095 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1097 var res
= test
.md_to_html
.write_to_string
1102 fun test_daring_autolinks
do
1104 Link: <http://example.com/>.
1106 With an ampersand: <http://example.com/?foo=1&bar=2>
1109 * <http://example.com/>
1112 > Blockquoted: <http://example.com/>
1114 Auto-links should not occur here: `<http://example.com/>`
1116 or here: <http://example.com/>
1120 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
1121 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
1124 <li><a href="http://example.com/">http://example.com/</a></li>
1128 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
1130 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
1131 <pre><code>or here: <http://example.com/>
1134 var res
= test
.md_to_html
.write_to_string
1138 fun test_daring_escape
do
1140 These should all get escaped:
1175 These should not, because they occur within a code block:
1209 Nor should these, which occur in code spans:
1243 These should get escaped, even though they're matching pairs for
1244 other Markdown constructs:
1252 This is a code span with a literal backslash-backtick sequence: `` \` ``
1254 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1256 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1259 <p>These should all get escaped:</p>
1260 <p>Backslash: \\</p>
1263 <p>Underscore: \_</p>
1264 <p>Left brace: \{</p>
1265 <p>Right brace: \}</p>
1266 <p>Left bracket: \[</p>
1267 <p>Right bracket: \]</p>
1268 <p>Left paren: \(</p>
1269 <p>Right paren: \)</p>
1270 <p>Greater-than: \></p>
1276 <p>These should not, because they occur within a code block:</p>
1277 <pre><code>Backslash: \\
1309 <p>Nor should these, which occur in code spans:</p>
1310 <p>Backslash: <code>\\</code></p>
1311 <p>Backtick: <code>\`</code></p>
1312 <p>Asterisk: <code>\*</code></p>
1313 <p>Underscore: <code>\_</code></p>
1314 <p>Left brace: <code>\{</code></p>
1315 <p>Right brace: <code>\}</code></p>
1316 <p>Left bracket: <code>\[</code></p>
1317 <p>Right bracket: <code>\]</code></p>
1318 <p>Left paren: <code>\(</code></p>
1319 <p>Right paren: <code>\)</code></p>
1320 <p>Greater-than: <code>\></code></p>
1321 <p>Hash: <code>\#</code></p>
1322 <p>Period: <code>\.</code></p>
1323 <p>Bang: <code>\!</code></p>
1324 <p>Plus: <code>\+</code></p>
1325 <p>Minus: <code>\-</code></p>
1326 <p>These should get escaped, even though they're matching pairs for
1327 other Markdown constructs:</p>
1329 <p>_underscores_</p>
1331 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1332 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1333 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1336 var res
= test
.md_to_html
.write_to_string
1340 fun test_daring_blockquotes
do
1358 <pre><code>sub status {
1363 <pre><code>sub status {
1369 var res
= test
.md_to_html
.write_to_string
1373 fun test_daring_code_blocks
do
1375 code block on the first line
1379 code block indented by spaces
1383 the lines in this block
1384 all contain trailing spaces
1388 code block on the last line
1392 <pre><code>code block on the first line
1394 <p>Regular text.</p>
1395 <pre><code>code block indented by spaces
1397 <p>Regular text.</p>
1398 <pre><code>the lines in this block
1399 all contain trailing spaces
1401 <p>Regular Text.</p>
1402 <pre><code>code block on the last line
1405 var res
= test
.md_to_html
.write_to_string
1409 fun test_daring_code_spans
do
1411 `<test a="` content of attribute `">`
1413 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1415 Here's how you put `` `backticks` `` in a code span.
1419 <p><code><test a="</code> content of attribute <code>"></code></p>
1420 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1421 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1423 var res
= test
.md_to_html
.write_to_string
1427 fun test_daring_pars
do
1428 var proc
= new MarkdownProcessor
1429 proc
.ext_mode
= false
1432 In Markdown 1.0.0 and earlier. Version
1433 8. This line turns into a list item.
1434 Because a hard-wrapped line in the
1435 middle of a paragraph looked like a
1438 Here's one with a bullet.
1443 <p>In Markdown 1.0.0 and earlier. Version
1444 8. This line turns into a list item.
1445 Because a hard-wrapped line in the
1446 middle of a paragraph looked like a
1448 <p>Here's one with a bullet.
1451 var res
= proc
.process
(test
).write_to_string
1455 fun test_daring_rules
do
1567 var res
= test
.md_to_html
.write_to_string
1571 fun test_daring_images
do
1573 ![Alt text](/path/to/img.jpg)
1575 ![Alt text](/path/to/img.jpg "Optional title")
1577 Inline within a paragraph: [alt text](/url/).
1579 ![alt text](/url/ "title preceded by two spaces")
1581 ![alt text](/url/ "title has spaces afterward" )
1583 ![alt text](</url/>)
1585 ![alt text](</url/> "with a title").
1589 ![this is a stupid URL](http://example.com/(parens).jpg)
1598 [bar]: /url/ "Title here"
1602 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1603 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1604 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1605 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1606 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1607 <p><img src="/url/" alt="alt text"/></p>
1608 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1609 <p><img src="" alt="Empty"/></p>
1610 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1611 <p><img src="/url/" alt="alt text"/></p>
1612 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1614 var res
= test
.md_to_html
.write_to_string
1618 fun test_daring_inline_html1
do
1620 Here's a simple block:
1626 This should be a code block, though:
1646 This should just be an HTML comment:
1661 Just plain comment, with trailing spaces on the line:
1683 <hr class="foo" id="bar" />
1685 <hr class="foo" id="bar"/>
1687 <hr class="foo" id="bar" >
1691 <p>Here's a simple block:</p>
1695 <p>This should be a code block, though:</p>
1696 <pre><code><div>
1700 <p>As should this:</p>
1701 <pre><code><div>foo</div>
1711 <p>This should just be an HTML comment:</p>
1719 <pre><code><!-- Comment -->
1721 <p>Just plain comment, with trailing spaces on the line:</p>
1724 <pre><code><hr />
1733 <hr class="foo" id="bar" />
1734 <hr class="foo" id="bar"/>
1735 <hr class="foo" id="bar" >
1737 var res
= test
.md_to_html
.write_to_string
1741 fun test_daring_inline_html2
do
1743 Simple block on one line:
1747 And nested without indentation:
1759 And with attributes:
1766 This was broken in 1.0.2b7:
1768 <div class="inlinepage">
1769 <div class="toggleableend">
1776 <p>Simple block on one line:</p>
1778 <p>And nested without indentation:</p>
1788 <p>And with attributes:</p>
1793 <p>This was broken in 1.0.2b7:</p>
1794 <div class="inlinepage">
1795 <div class="toggleableend">
1800 var res
= test
.md_to_html
.write_to_string
1804 fun test_daring_inline_html3
do
1808 <!-- This is a simple comment -->
1811 This is another comment.
1816 <!-- one comment block -- -- with two comments -->
1822 <p>Paragraph one.</p>
1823 <!-- This is a simple comment -->
1825 This is another comment.
1827 <p>Paragraph two.</p>
1828 <!-- one comment block -- -- with two comments -->
1831 var res
= test
.md_to_html
.write_to_string
1835 fun test_daring_links1
do
1837 Just a [URL](/url/).
1839 [URL and title](/url/ "title").
1841 [URL and title](/url/ "title preceded by two spaces").
1843 [URL and title](/url/ "title preceded by a tab").
1845 [URL and title](/url/ "title has spaces afterward" ).
1847 [URL wrapped in angle brackets](</url/>).
1849 [URL w/ angle brackets + title](</url/> "Here's the title").
1853 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1855 (With outer parens and [parens in url](/foo(bar)))
1858 [With parens in the URL](/foo(bar) "and a title")
1860 (With outer parens and [parens in url](/foo(bar) "and a title"))
1864 <p>Just a <a href="/url/">URL</a>.</p>
1865 <p><a href="/url/" title="title">URL and title</a>.</p>
1866 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1867 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1868 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1869 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1870 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
1871 <p><a href="">Empty</a>.</p>
1872 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1873 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1874 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1875 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1877 var res
= test
.md_to_html
.write_to_string
1881 fun test_daring_links2
do
1893 With [embedded [brackets]] [b].
1900 Indented [thrice][].
1902 Indented [four][] times.
1917 [this] [this] should work
1919 So should [this][this].
1933 [Something in brackets like [this][] should work]
1937 In this case, [this](/somethingelse/) points to something else.
1939 Backslashing should suppress \\\[this] and [this\\\].
1946 Here's one where the [link
1947 breaks] across lines.
1949 Here's another where the [link
1950 breaks] across lines, but with a line-ending space.
1953 [link breaks]: /url/
1957 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1958 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1959 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1960 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1961 <p>Indented <a href="/url">once</a>.</p>
1962 <p>Indented <a href="/url">twice</a>.</p>
1963 <p>Indented <a href="/url">thrice</a>.</p>
1964 <p>Indented [four][] times.</p>
1965 <pre><code>[four]: /url
1968 <p><a href="foo">this</a> should work</p>
1969 <p>So should <a href="foo">this</a>.</p>
1970 <p>And <a href="foo">this</a>.</p>
1971 <p>And <a href="foo">this</a>.</p>
1972 <p>And <a href="foo">this</a>.</p>
1973 <p>But not [that] [].</p>
1974 <p>Nor [that][].</p>
1976 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
1977 <p>[Same with <a href="foo">this</a>.]</p>
1978 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
1979 <p>Backslashing should suppress [this] and [this].</p>
1981 <p>Here's one where the <a href="/url/">link
1982 breaks</a> across lines.</p>
1983 <p>Here's another where the <a href="/url/">link
1984 breaks</a> across lines, but with a line-ending space.</p>
1986 var res
= test
.md_to_html
.write_to_string
1990 fun test_daring_links3
do
1992 This is the [simple case].
1994 [simple case]: /simple
1998 This one has a [line
2001 This one has a [line
2002 break] with a line-ending space.
2007 [this] [that] and the [other]
2015 <p>This is the <a href="/simple">simple case</a>.</p>
2016 <p>This one has a <a href="/foo">line
2018 <p>This one has a <a href="/foo">line
2019 break</a> with a line-ending space.</p>
2020 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
2022 var res
= test
.md_to_html
.write_to_string
2026 fun test_daring_nested
do
2044 var res
= test
.md_to_html
.write_to_string
2048 fun test_daring_list
do
2134 Multiple paragraphs:
2136 1. Item 1, graf one.
2138 Item 2. graf two. The quick brown fox jumped over the lazy dog's
2162 Same thing but with paragraphs:
2175 <h2 id="Unordered">Unordered</h2>
2176 <p>Asterisks tight:</p>
2182 <p>Asterisks loose:</p>
2184 <li><p>asterisk 1</p>
2186 <li><p>asterisk 2</p>
2188 <li><p>asterisk 3</p>
2192 <p>Pluses tight:</p>
2198 <p>Pluses loose:</p>
2208 <p>Minuses tight:</p>
2214 <p>Minuses loose:</p>
2223 <h2 id="Ordered">Ordered</h2>
2236 <p>Loose using tabs:</p>
2245 <p>and using spaces:</p>
2254 <p>Multiple paragraphs:</p>
2256 <li><p>Item 1, graf one.</p>
2257 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2265 <h2 id="Nested">Nested</h2>
2275 <p>Here's another:</p>
2286 <p>Same thing but with paragraphs:</p>
2301 var res
= test
.md_to_html
.write_to_string
2305 fun test_daring_strong_em
do
2307 ***This is strong and em.***
2309 So is ***this*** word.
2311 ___This is strong and em.___
2313 So is ___this___ word.
2317 <p><strong><em>This is strong and em.</em></strong></p>
2318 <p>So is <strong><em>this</em></strong> word.</p>
2319 <p><strong><em>This is strong and em.</em></strong></p>
2320 <p>So is <strong><em>this</em></strong> word.</p>
2322 var res
= test
.md_to_html
.write_to_string
2326 fun test_daring_tabs
do
2328 + this is a list item
2331 + this is a list item
2332 indented with spaces
2336 this code block is indented by one tab
2340 this code block is indented by two tabs
2344 + this is an example list item
2347 + this is an example list item
2348 indented with spaces
2353 <li><p>this is a list item
2354 indented with tabs</p>
2356 <li><p>this is a list item
2357 indented with spaces</p>
2361 <pre><code>this code block is indented by one tab
2364 <pre><code> this code block is indented by two tabs
2367 <pre><code>+ this is an example list item
2370 + this is an example list item
2371 indented with spaces
2374 var res
= test
.md_to_html
.write_to_string
2378 fun test_daring_tidyness
do
2380 > A list within a blockquote:
2389 <p>A list within a blockquote:</p>
2397 var res
= test
.md_to_html
.write_to_string
2407 # A dummy location for testing purposes.
2408 var loc
= new MDLocation(0, 0, 0, 0)
2410 fun test_has_blocks
do
2411 var subject
= new MDBlock(loc
)
2412 assert not subject
.has_blocks
2413 subject
.first_block
= new MDBlock(loc
)
2414 assert subject
.has_blocks
2417 fun test_count_blocks
do
2418 var subject
= new MDBlock(loc
)
2419 assert subject
.count_blocks
== 0
2420 subject
.first_block
= new MDBlock(loc
)
2421 assert subject
.count_blocks
== 1
2422 subject
.first_block
.next
= new MDBlock(loc
)
2423 assert subject
.count_blocks
== 2
2426 fun test_has_lines
do
2427 var subject
= new MDBlock(loc
)
2428 assert not subject
.has_lines
2429 subject
.first_line
= new MDLine(loc
, "")
2430 assert subject
.has_lines
2433 fun test_count_lines
do
2434 var subject
= new MDBlock(loc
)
2435 assert subject
.count_lines
== 0
2436 subject
.first_line
= new MDLine(loc
, "")
2437 assert subject
.count_lines
== 1
2438 subject
.first_line
.next
= new MDLine(loc
, "")
2439 assert subject
.count_lines
== 2
2443 var line1
= new MDLine(loc
, "line1")
2444 var line2
= new MDLine(loc
, "line2")
2445 var line3
= new MDLine(loc
, "line3")
2446 var subject
= new MDBlock(loc
)
2447 subject
.add_line line1
2448 subject
.add_line line2
2449 subject
.add_line line3
2450 var block
= subject
.split
(line2
)
2451 assert subject
.count_blocks
== 1
2452 assert subject
.count_lines
== 1
2453 assert subject
.first_line
== line3
2454 assert block
.count_blocks
== 0
2455 assert block
.count_lines
== 2
2456 assert block
.first_line
== line1
2457 assert block
.last_line
== line2
2460 fun test_add_line
do
2461 var subject
= new MDBlock(loc
)
2462 assert subject
.count_lines
== 0
2463 subject
.add_line
new MDLine(loc
, "")
2464 assert subject
.count_lines
== 1
2465 subject
.add_line
new MDLine(loc
, "")
2466 assert subject
.count_lines
== 2
2469 fun test_remove_line
do
2470 var line1
= new MDLine(loc
, "line1")
2471 var line2
= new MDLine(loc
, "line2")
2472 var line3
= new MDLine(loc
, "line3")
2473 var subject
= new MDBlock(loc
)
2474 subject
.add_line line1
2475 subject
.add_line line2
2476 subject
.add_line line3
2477 subject
.remove_line
(line2
)
2478 assert subject
.count_lines
== 2
2479 subject
.remove_line
(line1
)
2480 assert subject
.count_lines
== 1
2481 assert subject
.first_line
== line3
2482 assert subject
.last_line
== line3
2485 fun test_transform_headline1
do
2486 var subject
= new MDBlock(loc
)
2487 var kind
= new BlockHeadline(subject
)
2488 subject
.add_line
new MDLine(loc
, " # Title 1 ")
2489 kind
.transform_headline
(subject
)
2490 assert kind
.depth
== 1
2491 assert subject
.first_line
.value
== "Title 1"
2494 fun test_transform_headline2
do
2495 var subject
= new MDBlock(loc
)
2496 var kind
= new BlockHeadline(subject
)
2497 subject
.add_line
new MDLine(loc
, " #####Title 5 ")
2498 kind
.transform_headline
(subject
)
2499 assert kind
.depth
== 5
2500 assert subject
.first_line
.value
== "Title 5"
2503 fun test_remove_quote_prefix
do
2504 var subject
= new MDBlock(loc
)
2505 var kind
= new BlockQuote(subject
)
2506 subject
.add_line
new MDLine(loc
, " > line 1")
2507 subject
.add_line
new MDLine(loc
, " > line 2")
2508 subject
.add_line
new MDLine(loc
, " > line 3")
2509 kind
.remove_block_quote_prefix
(subject
)
2510 assert subject
.first_line
.value
== "line 1"
2511 assert subject
.first_line
.next
.value
== "line 2"
2512 assert subject
.first_line
.next
.next
.value
== "line 3"
2515 fun test_remove_leading_empty_lines_1
do
2516 var block
= new MDBlock(loc
)
2517 block
.add_line
new MDLine(loc
, "")
2518 block
.add_line
new MDLine(loc
, "")
2519 block
.add_line
new MDLine(loc
, "")
2520 block
.add_line
new MDLine(loc
, "")
2521 block
.add_line
new MDLine(loc
, " text")
2522 block
.add_line
new MDLine(loc
, "")
2523 assert block
.remove_leading_empty_lines
2524 assert block
.first_line
.value
== " text"
2527 fun test_remove_leading_empty_lines_2
do
2528 var block
= new MDBlock(loc
)
2529 block
.add_line
new MDLine(loc
, " text")
2530 block
.remove_leading_empty_lines
2531 assert block
.first_line
.value
== " text"
2534 fun test_remove_trailing_empty_lines_1
do
2535 var block
= new MDBlock(loc
)
2536 block
.add_line
new MDLine(loc
, "")
2537 block
.add_line
new MDLine(loc
, "text")
2538 block
.add_line
new MDLine(loc
, "")
2539 block
.add_line
new MDLine(loc
, "")
2540 block
.add_line
new MDLine(loc
, "")
2541 block
.add_line
new MDLine(loc
, "")
2542 assert block
.remove_trailing_empty_lines
2543 assert block
.last_line
.value
== "text"
2546 fun test_remove_trailing_empty_lines_2
do
2547 var block
= new MDBlock(loc
)
2548 block
.add_line
new MDLine(loc
, "text ")
2549 assert not block
.remove_trailing_empty_lines
2550 assert block
.last_line
.value
== "text "
2553 fun test_remove_surrounding_empty_lines
do
2554 var block
= new MDBlock(loc
)
2555 block
.add_line
new MDLine(loc
, "")
2556 block
.add_line
new MDLine(loc
, "text")
2557 block
.add_line
new MDLine(loc
, "")
2558 block
.add_line
new MDLine(loc
, "")
2559 block
.add_line
new MDLine(loc
, "")
2560 block
.add_line
new MDLine(loc
, "")
2561 assert block
.remove_surrounding_empty_lines
2562 assert block
.first_line
.value
== "text"
2563 assert block
.last_line
.value
== "text"
2570 # A dummy location for testing purposes.
2571 var loc
= new MDLocation(0, 0, 0, 0)
2575 fun test_is_empty
do
2576 subject
= new MDLine(loc
, "")
2577 assert subject
.is_empty
2578 subject
= new MDLine(loc
, " ")
2579 assert subject
.is_empty
2580 subject
= new MDLine(loc
, "test")
2581 assert not subject
.is_empty
2582 subject
= new MDLine(loc
, " test")
2583 assert not subject
.is_empty
2587 subject
= new MDLine(loc
, "")
2588 assert subject
.leading
== 0
2589 subject
= new MDLine(loc
, " ")
2590 assert subject
.leading
== 4
2591 subject
= new MDLine(loc
, "test")
2592 assert subject
.leading
== 0
2593 subject
= new MDLine(loc
, " test")
2594 assert subject
.leading
== 4
2597 fun test_trailing
do
2598 subject
= new MDLine(loc
, "")
2599 assert subject
.trailing
== 0
2600 subject
= new MDLine(loc
, " ")
2601 assert subject
.trailing
== 0
2602 subject
= new MDLine(loc
, "test ")
2603 assert subject
.trailing
== 3
2604 subject
= new MDLine(loc
, " test ")
2605 assert subject
.trailing
== 1
2608 fun test_line_type
do
2609 var v
= new MarkdownProcessor
2610 subject
= new MDLine(loc
, "")
2611 assert v
.line_kind
(subject
) isa LineEmpty
2612 subject
= new MDLine(loc
, " ")
2613 assert v
.line_kind
(subject
) isa LineEmpty
2614 subject
= new MDLine(loc
, "text ")
2615 assert v
.line_kind
(subject
) isa LineOther
2616 subject
= new MDLine(loc
, " # Title")
2617 assert v
.line_kind
(subject
) isa LineHeadline
2618 subject
= new MDLine(loc
, " ### Title")
2619 assert v
.line_kind
(subject
) isa LineHeadline
2620 subject
= new MDLine(loc
, " code")
2621 assert v
.line_kind
(subject
) isa LineCode
2622 subject
= new MDLine(loc
, " Title ")
2623 subject
.next
= new MDLine(loc
, "== ")
2624 assert v
.line_kind
(subject
) isa LineHeadline1
2625 subject
= new MDLine(loc
, " Title ")
2626 subject
.next
= new MDLine(loc
, "-- ")
2627 assert v
.line_kind
(subject
) isa LineHeadline2
2628 subject
= new MDLine(loc
, " * * * ")
2629 assert v
.line_kind
(subject
) isa LineHR
2630 subject
= new MDLine(loc
, " *** ")
2631 assert v
.line_kind
(subject
) isa LineHR
2632 subject
= new MDLine(loc
, "- -- ")
2633 assert v
.line_kind
(subject
) isa LineHR
2634 subject
= new MDLine(loc
, "--------- ")
2635 assert v
.line_kind
(subject
) isa LineHR
2636 subject
= new MDLine(loc
, " >")
2637 assert v
.line_kind
(subject
) isa LineBlockquote
2638 subject
= new MDLine(loc
, "<p></p>")
2639 assert v
.line_kind
(subject
) isa LineXML
2640 subject
= new MDLine(loc
, "<p>")
2641 assert v
.line_kind
(subject
) isa LineOther
2642 subject
= new MDLine(loc
, " * foo")
2643 assert v
.line_kind
(subject
) isa LineUList
2644 subject
= new MDLine(loc
, "- foo")
2645 assert v
.line_kind
(subject
) isa LineUList
2646 subject
= new MDLine(loc
, "+ foo")
2647 assert v
.line_kind
(subject
) isa LineUList
2648 subject
= new MDLine(loc
, "1. foo")
2649 assert v
.line_kind
(subject
) isa LineOList
2650 subject
= new MDLine(loc
, " 11111. foo")
2651 assert v
.line_kind
(subject
) isa LineOList
2654 fun test_line_type_ext
do
2655 var v
= new MarkdownProcessor
2656 subject
= new MDLine(loc
, " ~~~")
2657 assert v
.line_kind
(subject
) isa LineFence
2658 subject
= new MDLine(loc
, " ```")
2659 assert v
.line_kind
(subject
) isa LineFence
2660 subject
= new MDLine(loc
, "~~~raw")
2661 assert v
.line_kind
(subject
) isa LineFence
2664 fun test_count_chars
do
2665 subject
= new MDLine(loc
, "")
2666 assert subject
.count_chars
('*') == 0
2667 subject
= new MDLine(loc
, "* ")
2668 assert subject
.count_chars
('*') == 1
2669 subject
= new MDLine(loc
, " * text")
2670 assert subject
.count_chars
('*') == 0
2671 subject
= new MDLine(loc
, " * * *")
2672 assert subject
.count_chars
('*') == 3
2673 subject
= new MDLine(loc
, "text ** ")
2674 assert subject
.count_chars
('*') == 0
2677 fun test_count_chars_start
do
2678 subject
= new MDLine(loc
, "")
2679 assert subject
.count_chars_start
('*') == 0
2680 subject
= new MDLine(loc
, "* ")
2681 assert subject
.count_chars_start
('*') == 1
2682 subject
= new MDLine(loc
, " * text")
2683 assert subject
.count_chars_start
('*') == 1
2684 subject
= new MDLine(loc
, " * * * text")
2685 assert subject
.count_chars_start
('*') == 3
2686 subject
= new MDLine(loc
, "text ** ")
2687 assert subject
.count_chars_start
('*') == 0
2691 class TestHTMLDecorator
2694 fun test_headlines
do
2708 var proc
= new MarkdownProcessor
2709 var decorator
= proc
.emitter
.decorator
.as(HTMLDecorator)
2712 for id
, headline
in decorator
.headlines
do
2713 res
+= "{headline.title}:{id}\n"
2732 class TestTokenLocation
2735 fun test_token_location1
do
2736 var string
= "**Hello** `World`"
2738 "TokenStrongStar at 1,1--1,1",
2739 "TokenStrongStar at 1,8--1,8",
2740 "TokenCodeSingle at 1,11--1,11",
2741 "TokenCodeSingle at 1,17--1,17"]
2742 (new TestTokenProcessor(stack
)).process
(string
)
2745 fun test_token_location2
do
2746 var string
= "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
2748 "TokenStrongStar at 1,1--1,1",
2749 "TokenStrongStar at 1,8--1,8",
2750 "TokenCodeSingle at 2,1--2,1",
2751 "TokenCodeSingle at 2,7--2,7",
2752 "TokenEmStar at 3,1--3,1",
2753 "TokenEmStar at 3,9--3,9",
2754 "TokenLink at 4,1--4,1"]
2755 (new TestTokenProcessor(stack
)).process
(string
)
2758 fun test_token_location3
do
2759 var string
= """**Hello**
2764 "TokenStrongStar at 1,1--1,1",
2765 "TokenStrongStar at 1,8--1,8",
2766 "TokenCodeSingle at 2,1--2,1",
2767 "TokenCodeSingle at 2,7--2,7",
2768 "TokenEmStar at 3,1--3,1",
2769 "TokenEmStar at 3,9--3,9",
2770 "TokenLink at 4,1--4,1"]
2771 (new TestTokenProcessor(stack
)).process
(string
)
2774 fun test_token_location4
do
2775 var string
= "**Hello**\n\n`World`"
2777 "TokenStrongStar at 1,1--1,1",
2778 "TokenStrongStar at 1,8--1,8",
2779 "TokenCodeSingle at 3,1--3,1",
2780 "TokenCodeSingle at 3,7--3,7"]
2781 (new TestTokenProcessor(stack
)).process
(string
)
2784 fun test_token_location5
do
2785 var string
= "# *Title1*\n\n# *Title2*"
2787 "TokenEmStar at 1,3--1,3",
2788 "TokenEmStar at 1,10--1,10",
2789 "TokenEmStar at 3,3--3,3",
2790 "TokenEmStar at 3,10--3,10"]
2791 (new TestTokenProcessor(stack
)).process
(string
)
2795 class TestTokenProcessor
2796 super MarkdownProcessor
2798 var test_stack
: Array[String]
2800 redef fun token_at
(input
, pos
) do
2802 if token
isa TokenNone then return token
2803 var res
= "{token.class_name} at {token.location}"
2804 var exp
= test_stack
.shift
2813 class TestBlockLocation
2816 var proc
= new MarkdownProcessor
2818 fun test_block_location1
do
2820 "BlockHeadline: 1,1--1,8",
2821 "BlockListItem: 2,1--2,6",
2822 "BlockListItem: 3,1--3,5"
2825 "# Title\n* li1\n* li2"
2826 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2827 proc
.process
(string
)
2830 fun test_block_location2
do
2832 "BlockHeadline: 1,1--1,11",
2833 "BlockFence: 3,1--5,4",
2834 "BlockListItem: 7,1--7,7",
2835 "BlockListItem: 8,1--8,6"]
2836 var string
="""#### Title
2844 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2845 proc
.process
(string
)
2848 fun test_block_location3
do
2850 "BlockHeadline: 1,1--1,8",
2851 "BlockHeadline: 3,1--3,10"]
2852 var string
="""# Title\n\n## Title 2"""
2853 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2854 proc
.process
(string
)
2858 class TestBlockDecorator
2861 var stack
: Array[String]
2863 redef fun add_headline
(v
, block
) do
2868 redef fun add_listitem
(v
, block
) do
2873 redef fun add_blockquote
(v
, block
) do
2878 redef fun add_code
(v
, block
) do
2883 fun check_res
(block
: Block) do
2884 var res
= "{block.class_name}: {block.block.location}"
2885 var exp
= stack
.shift