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_nesting1
do
583 > ## This is a header.
585 > 1. This is the first list item.
586 > 2. This is the second list item.
588 > Here's some example code:
590 > return shell_exec("echo $input | $markdown_script");
594 <h2 id="This_is_a_header.">This is a header.</h2>
596 <li>This is the first list item.</li>
597 <li>This is the second list item.</li>
599 <p>Here's some example code:</p>
600 <pre><code>return shell_exec("echo $input | $markdown_script");
604 var res
= test
.md_to_html
.write_to_string
608 fun test_process_nesting2
do
610 * A list item with a blockquote:
612 > This is a blockquote
613 > inside a list item.
617 <li><p>A list item with a blockquote:</p>
619 <p>This is a blockquote
620 inside a list item.</p>
625 var res
= test
.md_to_html
.write_to_string
629 fun test_process_nesting3
do
631 * A list item with a code block:
637 <li><p>A list item with a code block:</p>
638 <pre><code><code goes here>
643 var res
= test
.md_to_html
.write_to_string
647 fun test_process_nesting4
do
664 var res
= test
.md_to_html
.write_to_string
669 # fun test_process_nesting5 do
687 # var res = test.md_to_html.write_to_string
691 fun test_process_emph1
do
699 __double underscores__
701 var exp
= """<p><em>single asterisks</em></p>
702 <p><em>single underscores</em></p>
703 <p><strong>double asterisks</strong></p>
704 <p><strong>double underscores</strong></p>
706 var res
= test
.md_to_html
.write_to_string
710 fun test_process_emph2
do
711 var test
= "un*frigging*believable"
712 var exp
= "<p>un<em>frigging</em>believable</p>\n"
713 var res
= test
.md_to_html
.write_to_string
717 fun test_process_emph3
do
718 var proc
= new MarkdownProcessor
719 proc
.ext_mode
= false
720 var test
= "Con_cat_this"
721 var exp
= "<p>Con<em>cat</em>this</p>\n"
722 var res
= proc
.process
(test
).write_to_string
726 fun test_process_emph_ext
do
727 var test
= "Con_cat_this"
728 var exp
= "<p>Con_cat_this</p>\n"
729 var res
= test
.md_to_html
.write_to_string
733 fun test_process_xml1
do
735 This is a regular paragraph.
743 This is another regular paragraph.
746 <p>This is a regular paragraph.</p>
752 <p>This is another regular paragraph.</p>
754 var res
= test
.md_to_html
.write_to_string
758 fun test_process_xml2
do
760 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
762 var exp
= """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
764 var res
= test
.md_to_html
.write_to_string
768 fun test_process_xml3
do
775 var res
= test
.md_to_html
.write_to_string
779 fun test_process_span_code1
do
780 var test
= "Use the `printf()` function."
781 var exp
= "<p>Use the <code>printf()</code> function.</p>\n"
782 var res
= test
.md_to_html
.write_to_string
786 fun test_process_span_code2
do
787 var test
= "``There is a literal backtick (`) here.``"
788 var exp
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
789 var res
= test
.md_to_html
.write_to_string
793 fun test_process_span_code3
do
795 A single backtick in a code span: `` ` ``
797 A backtick-delimited string in a code span: `` `foo` ``
800 <p>A single backtick in a code span: <code>`</code></p>
801 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
803 var res
= test
.md_to_html
.write_to_string
807 fun test_process_span_code4
do
808 var test
= "Please don't use any `<blink>` tags."
809 var exp
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
810 var res
= test
.md_to_html
.write_to_string
814 fun test_process_span_code5
do
815 var test
= "`—` is the decimal-encoded equivalent of `—`."
816 var exp
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
817 var res
= test
.md_to_html
.write_to_string
821 fun test_process_escape1
do
822 var test
= "\\*this text is surrounded by literal asterisks\\*"
823 var exp
= "<p>*this text is surrounded by literal asterisks*</p>\n"
824 var res
= test
.md_to_html
.write_to_string
828 fun test_process_escape2
do
829 var test
= "1986\\. What a great season."
830 var exp
= "<p>1986. What a great season.</p>\n"
831 var res
= test
.md_to_html
.write_to_string
835 fun test_process_escape3
do
836 var test
= "Ben & Lux"
837 var exp
= "<p>Ben & Lux</p>\n"
838 var res
= test
.md_to_html
.write_to_string
842 fun test_process_link1
do
844 This is [an example](http://example.com/ "Title") inline link.
846 [This link](http://example.net/) has no title attribute.
848 var exp
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
849 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
851 var res
= test
.md_to_html
.write_to_string
855 fun test_process_link2
do
856 var test
= "See my [About](/about/) page for details."
857 var exp
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
858 var res
= test
.md_to_html
.write_to_string
862 fun test_process_link3
do
864 This is [an example][id] reference-style link.
866 This is [an example] [id] reference-style link.
870 [id]: http://example.com/ "Optional Title Here"
875 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
876 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
877 <p>Some lorem ipsum</p>
878 <p>Some other lipsum</p>
880 var res
= test
.md_to_html
.write_to_string
884 fun test_process_link4
do
886 This is multiple examples: [foo][1], [bar][2], [baz][3].
888 [1]: http://example.com/ "Optional Title Here"
889 [2]: http://example.com/ 'Optional Title Here'
890 [3]: http://example.com/ (Optional Title Here)
893 <p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">baz</a>.</p>
895 var res
= test
.md_to_html
.write_to_string
899 fun test_process_link5
do
901 This is multiple examples: [foo][a], [bar][A], [a].
903 [a]: http://example.com/ "Optional Title Here"
905 var exp
= """<p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">a</a>.</p>
907 var res
= test
.md_to_html
.write_to_string
911 fun test_process_link6
do
913 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
915 [Google]: http://google.com/ "Google"
916 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
917 [MSN]: http://search.msn.com/ "MSN Search"
919 var exp
= """<p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
921 var res
= test
.md_to_html
.write_to_string
925 fun test_process_link7
do
927 Visit [Daring Fireball][] for more information.
929 [Daring Fireball]: http://daringfireball.net/
931 var exp
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
933 var res
= test
.md_to_html
.write_to_string
937 fun test_process_link8
do
943 break] with a line-ending space.
948 <p>This one has a <a href="/foo">line
950 <p>This one has a <a href="/foo">line
951 break</a> with a line-ending space.</p>
953 var res
= test
.md_to_html
.write_to_string
957 # FIXME unignore test once escape strings fixed
958 # fun test_process_link9 do
962 # Foo [bar](/url/ "Title with \"quotes\" inside").
965 # [bar]: /url/ "Title with \"quotes\" inside"
968 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
969 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
971 # var res = test.md_to_html.write_to_string
975 fun test_process_img1
do
977 ![Alt text](/path/to/img.jpg)
979 ![Alt text](/path/to/img.jpg "Optional title")
981 var exp
= """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
982 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
984 var res
= test
.md_to_html
.write_to_string
988 fun test_process_img2
do
992 [id]: url/to/image "Optional title attribute"
994 var exp
= """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
996 var res
= test
.md_to_html
.write_to_string
1000 fun test_process_strike
do
1001 var proc
= new MarkdownProcessor
1002 proc
.ext_mode
= false
1003 var test
= "This is how you ~~strike text~~"
1004 var exp
= "<p>This is how you ~~strike text~~</p>\n"
1005 var res
= proc
.process
(test
).write_to_string
1009 fun test_process_strike_ext
do
1010 var test
= "This is how you ~~strike text~~"
1011 var exp
= "<p>This is how you <del>strike text</del></p>\n"
1012 var res
= test
.md_to_html
.write_to_string
1016 fun test_escape_bad_html
do
1017 var test
= "-1 if < , +1 if > and 0 otherwise"
1018 var exp
= "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
1019 var res
= test
.md_to_html
.write_to_string
1023 fun test_daring_encoding
do
1025 AT&T has an ampersand in their name.
1027 AT&T is another way to write it.
1035 Here's a [link] [1] with an ampersand in the URL.
1037 Here's a link with an amersand in the link text: [AT&T] [2].
1039 Here's an inline [link](/script?foo=1&bar=2).
1041 Here's an inline [link](</script?foo=1&bar=2>).
1044 [1]: http://example.com/?foo=1&bar=2
1045 [2]: http://att.com/ "AT&T"
1049 <p>AT&T has an ampersand in their name.</p>
1050 <p>AT&T is another way to write it.</p>
1051 <p>This & that.</p>
1054 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
1055 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
1056 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1057 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1059 var res
= test
.md_to_html
.write_to_string
1064 fun test_daring_autolinks
do
1066 Link: <http://example.com/>.
1068 With an ampersand: <http://example.com/?foo=1&bar=2>
1071 * <http://example.com/>
1074 > Blockquoted: <http://example.com/>
1076 Auto-links should not occur here: `<http://example.com/>`
1078 or here: <http://example.com/>
1082 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
1083 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
1086 <li><a href="http://example.com/">http://example.com/</a></li>
1090 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
1092 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
1093 <pre><code>or here: <http://example.com/>
1096 var res
= test
.md_to_html
.write_to_string
1100 fun test_daring_escape
do
1102 These should all get escaped:
1137 These should not, because they occur within a code block:
1171 Nor should these, which occur in code spans:
1205 These should get escaped, even though they're matching pairs for
1206 other Markdown constructs:
1214 This is a code span with a literal backslash-backtick sequence: `` \` ``
1216 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1218 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1221 <p>These should all get escaped:</p>
1222 <p>Backslash: \\</p>
1225 <p>Underscore: \_</p>
1226 <p>Left brace: \{</p>
1227 <p>Right brace: \}</p>
1228 <p>Left bracket: \[</p>
1229 <p>Right bracket: \]</p>
1230 <p>Left paren: \(</p>
1231 <p>Right paren: \)</p>
1232 <p>Greater-than: \></p>
1238 <p>These should not, because they occur within a code block:</p>
1239 <pre><code>Backslash: \\
1271 <p>Nor should these, which occur in code spans:</p>
1272 <p>Backslash: <code>\\</code></p>
1273 <p>Backtick: <code>\`</code></p>
1274 <p>Asterisk: <code>\*</code></p>
1275 <p>Underscore: <code>\_</code></p>
1276 <p>Left brace: <code>\{</code></p>
1277 <p>Right brace: <code>\}</code></p>
1278 <p>Left bracket: <code>\[</code></p>
1279 <p>Right bracket: <code>\]</code></p>
1280 <p>Left paren: <code>\(</code></p>
1281 <p>Right paren: <code>\)</code></p>
1282 <p>Greater-than: <code>\></code></p>
1283 <p>Hash: <code>\#</code></p>
1284 <p>Period: <code>\.</code></p>
1285 <p>Bang: <code>\!</code></p>
1286 <p>Plus: <code>\+</code></p>
1287 <p>Minus: <code>\-</code></p>
1288 <p>These should get escaped, even though they're matching pairs for
1289 other Markdown constructs:</p>
1291 <p>_underscores_</p>
1293 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1294 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1295 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1298 var res
= test
.md_to_html
.write_to_string
1302 fun test_daring_blockquotes
do
1320 <pre><code>sub status {
1325 <pre><code>sub status {
1331 var res
= test
.md_to_html
.write_to_string
1335 fun test_daring_code_blocks
do
1337 code block on the first line
1341 code block indented by spaces
1345 the lines in this block
1346 all contain trailing spaces
1350 code block on the last line
1354 <pre><code>code block on the first line
1356 <p>Regular text.</p>
1357 <pre><code>code block indented by spaces
1359 <p>Regular text.</p>
1360 <pre><code>the lines in this block
1361 all contain trailing spaces
1363 <p>Regular Text.</p>
1364 <pre><code>code block on the last line
1367 var res
= test
.md_to_html
.write_to_string
1371 fun test_daring_code_spans
do
1373 `<test a="` content of attribute `">`
1375 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1377 Here's how you put `` `backticks` `` in a code span.
1381 <p><code><test a="</code> content of attribute <code>"></code></p>
1382 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1383 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1385 var res
= test
.md_to_html
.write_to_string
1389 fun test_daring_pars
do
1390 var proc
= new MarkdownProcessor
1391 proc
.ext_mode
= false
1394 In Markdown 1.0.0 and earlier. Version
1395 8. This line turns into a list item.
1396 Because a hard-wrapped line in the
1397 middle of a paragraph looked like a
1400 Here's one with a bullet.
1405 <p>In Markdown 1.0.0 and earlier. Version
1406 8. This line turns into a list item.
1407 Because a hard-wrapped line in the
1408 middle of a paragraph looked like a
1410 <p>Here's one with a bullet.
1413 var res
= proc
.process
(test
).write_to_string
1417 fun test_daring_rules
do
1529 var res
= test
.md_to_html
.write_to_string
1533 fun test_daring_images
do
1535 ![Alt text](/path/to/img.jpg)
1537 ![Alt text](/path/to/img.jpg "Optional title")
1539 Inline within a paragraph: [alt text](/url/).
1541 ![alt text](/url/ "title preceded by two spaces")
1543 ![alt text](/url/ "title has spaces afterward" )
1545 ![alt text](</url/>)
1547 ![alt text](</url/> "with a title").
1551 ![this is a stupid URL](http://example.com/(parens).jpg)
1560 [bar]: /url/ "Title here"
1564 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1565 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1566 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1567 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1568 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1569 <p><img src="/url/" alt="alt text"/></p>
1570 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1571 <p><img src="" alt="Empty"/></p>
1572 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1573 <p><img src="/url/" alt="alt text"/></p>
1574 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1576 var res
= test
.md_to_html
.write_to_string
1580 fun test_daring_inline_html1
do
1582 Here's a simple block:
1588 This should be a code block, though:
1608 This should just be an HTML comment:
1623 Just plain comment, with trailing spaces on the line:
1645 <hr class="foo" id="bar" />
1647 <hr class="foo" id="bar"/>
1649 <hr class="foo" id="bar" >
1653 <p>Here's a simple block:</p>
1657 <p>This should be a code block, though:</p>
1658 <pre><code><div>
1662 <p>As should this:</p>
1663 <pre><code><div>foo</div>
1673 <p>This should just be an HTML comment:</p>
1681 <pre><code><!-- Comment -->
1683 <p>Just plain comment, with trailing spaces on the line:</p>
1686 <pre><code><hr />
1695 <hr class="foo" id="bar" />
1696 <hr class="foo" id="bar"/>
1697 <hr class="foo" id="bar" >
1699 var res
= test
.md_to_html
.write_to_string
1703 fun test_daring_inline_html2
do
1705 Simple block on one line:
1709 And nested without indentation:
1721 And with attributes:
1728 This was broken in 1.0.2b7:
1730 <div class="inlinepage">
1731 <div class="toggleableend">
1738 <p>Simple block on one line:</p>
1740 <p>And nested without indentation:</p>
1750 <p>And with attributes:</p>
1755 <p>This was broken in 1.0.2b7:</p>
1756 <div class="inlinepage">
1757 <div class="toggleableend">
1762 var res
= test
.md_to_html
.write_to_string
1766 fun test_daring_inline_html3
do
1770 <!-- This is a simple comment -->
1773 This is another comment.
1778 <!-- one comment block -- -- with two comments -->
1784 <p>Paragraph one.</p>
1785 <!-- This is a simple comment -->
1787 This is another comment.
1789 <p>Paragraph two.</p>
1790 <!-- one comment block -- -- with two comments -->
1793 var res
= test
.md_to_html
.write_to_string
1797 fun test_daring_links1
do
1799 Just a [URL](/url/).
1801 [URL and title](/url/ "title").
1803 [URL and title](/url/ "title preceded by two spaces").
1805 [URL and title](/url/ "title preceded by a tab").
1807 [URL and title](/url/ "title has spaces afterward" ).
1809 [URL wrapped in angle brackets](</url/>).
1811 [URL w/ angle brackets + title](</url/> "Here's the title").
1815 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1817 (With outer parens and [parens in url](/foo(bar)))
1820 [With parens in the URL](/foo(bar) "and a title")
1822 (With outer parens and [parens in url](/foo(bar) "and a title"))
1826 <p>Just a <a href="/url/">URL</a>.</p>
1827 <p><a href="/url/" title="title">URL and title</a>.</p>
1828 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1829 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1830 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1831 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1832 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
1833 <p><a href="">Empty</a>.</p>
1834 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1835 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1836 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1837 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1839 var res
= test
.md_to_html
.write_to_string
1843 fun test_daring_links2
do
1855 With [embedded [brackets]] [b].
1862 Indented [thrice][].
1864 Indented [four][] times.
1879 [this] [this] should work
1881 So should [this][this].
1895 [Something in brackets like [this][] should work]
1899 In this case, [this](/somethingelse/) points to something else.
1901 Backslashing should suppress \\\[this] and [this\\\].
1908 Here's one where the [link
1909 breaks] across lines.
1911 Here's another where the [link
1912 breaks] across lines, but with a line-ending space.
1915 [link breaks]: /url/
1919 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1920 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1921 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1922 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1923 <p>Indented <a href="/url">once</a>.</p>
1924 <p>Indented <a href="/url">twice</a>.</p>
1925 <p>Indented <a href="/url">thrice</a>.</p>
1926 <p>Indented [four][] times.</p>
1927 <pre><code>[four]: /url
1930 <p><a href="foo">this</a> should work</p>
1931 <p>So should <a href="foo">this</a>.</p>
1932 <p>And <a href="foo">this</a>.</p>
1933 <p>And <a href="foo">this</a>.</p>
1934 <p>And <a href="foo">this</a>.</p>
1935 <p>But not [that] [].</p>
1936 <p>Nor [that][].</p>
1938 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
1939 <p>[Same with <a href="foo">this</a>.]</p>
1940 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
1941 <p>Backslashing should suppress [this] and [this].</p>
1943 <p>Here's one where the <a href="/url/">link
1944 breaks</a> across lines.</p>
1945 <p>Here's another where the <a href="/url/">link
1946 breaks</a> across lines, but with a line-ending space.</p>
1948 var res
= test
.md_to_html
.write_to_string
1952 fun test_daring_links3
do
1954 This is the [simple case].
1956 [simple case]: /simple
1960 This one has a [line
1963 This one has a [line
1964 break] with a line-ending space.
1969 [this] [that] and the [other]
1977 <p>This is the <a href="/simple">simple case</a>.</p>
1978 <p>This one has a <a href="/foo">line
1980 <p>This one has a <a href="/foo">line
1981 break</a> with a line-ending space.</p>
1982 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
1984 var res
= test
.md_to_html
.write_to_string
1988 fun test_daring_nested
do
2006 var res
= test
.md_to_html
.write_to_string
2010 fun test_daring_list
do
2096 Multiple paragraphs:
2098 1. Item 1, graf one.
2100 Item 2. graf two. The quick brown fox jumped over the lazy dog's
2124 Same thing but with paragraphs:
2137 <h2 id="Unordered">Unordered</h2>
2138 <p>Asterisks tight:</p>
2144 <p>Asterisks loose:</p>
2146 <li><p>asterisk 1</p>
2148 <li><p>asterisk 2</p>
2150 <li><p>asterisk 3</p>
2154 <p>Pluses tight:</p>
2160 <p>Pluses loose:</p>
2170 <p>Minuses tight:</p>
2176 <p>Minuses loose:</p>
2185 <h2 id="Ordered">Ordered</h2>
2198 <p>Loose using tabs:</p>
2207 <p>and using spaces:</p>
2216 <p>Multiple paragraphs:</p>
2218 <li><p>Item 1, graf one.</p>
2219 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2227 <h2 id="Nested">Nested</h2>
2237 <p>Here's another:</p>
2248 <p>Same thing but with paragraphs:</p>
2263 var res
= test
.md_to_html
.write_to_string
2267 fun test_daring_strong_em
do
2269 ***This is strong and em.***
2271 So is ***this*** word.
2273 ___This is strong and em.___
2275 So is ___this___ word.
2279 <p><strong><em>This is strong and em.</em></strong></p>
2280 <p>So is <strong><em>this</em></strong> word.</p>
2281 <p><strong><em>This is strong and em.</em></strong></p>
2282 <p>So is <strong><em>this</em></strong> word.</p>
2284 var res
= test
.md_to_html
.write_to_string
2288 fun test_daring_tabs
do
2290 + this is a list item
2293 + this is a list item
2294 indented with spaces
2298 this code block is indented by one tab
2302 this code block is indented by two tabs
2306 + this is an example list item
2309 + this is an example list item
2310 indented with spaces
2315 <li><p>this is a list item
2316 indented with tabs</p>
2318 <li><p>this is a list item
2319 indented with spaces</p>
2323 <pre><code>this code block is indented by one tab
2326 <pre><code> this code block is indented by two tabs
2329 <pre><code>+ this is an example list item
2332 + this is an example list item
2333 indented with spaces
2336 var res
= test
.md_to_html
.write_to_string
2340 fun test_daring_tidyness
do
2342 > A list within a blockquote:
2351 <p>A list within a blockquote:</p>
2359 var res
= test
.md_to_html
.write_to_string
2369 # A dummy location for testing purposes.
2370 var loc
= new MDLocation(0, 0, 0, 0)
2372 fun test_has_blocks
do
2373 var subject
= new MDBlock(loc
)
2374 assert not subject
.has_blocks
2375 subject
.first_block
= new MDBlock(loc
)
2376 assert subject
.has_blocks
2379 fun test_count_blocks
do
2380 var subject
= new MDBlock(loc
)
2381 assert subject
.count_blocks
== 0
2382 subject
.first_block
= new MDBlock(loc
)
2383 assert subject
.count_blocks
== 1
2384 subject
.first_block
.next
= new MDBlock(loc
)
2385 assert subject
.count_blocks
== 2
2388 fun test_has_lines
do
2389 var subject
= new MDBlock(loc
)
2390 assert not subject
.has_lines
2391 subject
.first_line
= new MDLine(loc
, "")
2392 assert subject
.has_lines
2395 fun test_count_lines
do
2396 var subject
= new MDBlock(loc
)
2397 assert subject
.count_lines
== 0
2398 subject
.first_line
= new MDLine(loc
, "")
2399 assert subject
.count_lines
== 1
2400 subject
.first_line
.next
= new MDLine(loc
, "")
2401 assert subject
.count_lines
== 2
2405 var line1
= new MDLine(loc
, "line1")
2406 var line2
= new MDLine(loc
, "line2")
2407 var line3
= new MDLine(loc
, "line3")
2408 var subject
= new MDBlock(loc
)
2409 subject
.add_line line1
2410 subject
.add_line line2
2411 subject
.add_line line3
2412 var block
= subject
.split
(line2
)
2413 assert subject
.count_blocks
== 1
2414 assert subject
.count_lines
== 1
2415 assert subject
.first_line
== line3
2416 assert block
.count_blocks
== 0
2417 assert block
.count_lines
== 2
2418 assert block
.first_line
== line1
2419 assert block
.last_line
== line2
2422 fun test_add_line
do
2423 var subject
= new MDBlock(loc
)
2424 assert subject
.count_lines
== 0
2425 subject
.add_line
new MDLine(loc
, "")
2426 assert subject
.count_lines
== 1
2427 subject
.add_line
new MDLine(loc
, "")
2428 assert subject
.count_lines
== 2
2431 fun test_remove_line
do
2432 var line1
= new MDLine(loc
, "line1")
2433 var line2
= new MDLine(loc
, "line2")
2434 var line3
= new MDLine(loc
, "line3")
2435 var subject
= new MDBlock(loc
)
2436 subject
.add_line line1
2437 subject
.add_line line2
2438 subject
.add_line line3
2439 subject
.remove_line
(line2
)
2440 assert subject
.count_lines
== 2
2441 subject
.remove_line
(line1
)
2442 assert subject
.count_lines
== 1
2443 assert subject
.first_line
== line3
2444 assert subject
.last_line
== line3
2447 fun test_transform_headline1
do
2448 var subject
= new MDBlock(loc
)
2449 var kind
= new BlockHeadline(subject
)
2450 subject
.add_line
new MDLine(loc
, " # Title 1 ")
2451 kind
.transform_headline
(subject
)
2452 assert kind
.depth
== 1
2453 assert subject
.first_line
.value
== "Title 1"
2456 fun test_transform_headline2
do
2457 var subject
= new MDBlock(loc
)
2458 var kind
= new BlockHeadline(subject
)
2459 subject
.add_line
new MDLine(loc
, " #####Title 5 ")
2460 kind
.transform_headline
(subject
)
2461 assert kind
.depth
== 5
2462 assert subject
.first_line
.value
== "Title 5"
2465 fun test_remove_quote_prefix
do
2466 var subject
= new MDBlock(loc
)
2467 var kind
= new BlockQuote(subject
)
2468 subject
.add_line
new MDLine(loc
, " > line 1")
2469 subject
.add_line
new MDLine(loc
, " > line 2")
2470 subject
.add_line
new MDLine(loc
, " > line 3")
2471 kind
.remove_block_quote_prefix
(subject
)
2472 assert subject
.first_line
.value
== "line 1"
2473 assert subject
.first_line
.next
.value
== "line 2"
2474 assert subject
.first_line
.next
.next
.value
== "line 3"
2477 fun test_remove_leading_empty_lines_1
do
2478 var block
= new MDBlock(loc
)
2479 block
.add_line
new MDLine(loc
, "")
2480 block
.add_line
new MDLine(loc
, "")
2481 block
.add_line
new MDLine(loc
, "")
2482 block
.add_line
new MDLine(loc
, "")
2483 block
.add_line
new MDLine(loc
, " text")
2484 block
.add_line
new MDLine(loc
, "")
2485 assert block
.remove_leading_empty_lines
2486 assert block
.first_line
.value
== " text"
2489 fun test_remove_leading_empty_lines_2
do
2490 var block
= new MDBlock(loc
)
2491 block
.add_line
new MDLine(loc
, " text")
2492 block
.remove_leading_empty_lines
2493 assert block
.first_line
.value
== " text"
2496 fun test_remove_trailing_empty_lines_1
do
2497 var block
= new MDBlock(loc
)
2498 block
.add_line
new MDLine(loc
, "")
2499 block
.add_line
new MDLine(loc
, "text")
2500 block
.add_line
new MDLine(loc
, "")
2501 block
.add_line
new MDLine(loc
, "")
2502 block
.add_line
new MDLine(loc
, "")
2503 block
.add_line
new MDLine(loc
, "")
2504 assert block
.remove_trailing_empty_lines
2505 assert block
.last_line
.value
== "text"
2508 fun test_remove_trailing_empty_lines_2
do
2509 var block
= new MDBlock(loc
)
2510 block
.add_line
new MDLine(loc
, "text ")
2511 assert not block
.remove_trailing_empty_lines
2512 assert block
.last_line
.value
== "text "
2515 fun test_remove_surrounding_empty_lines
do
2516 var block
= new MDBlock(loc
)
2517 block
.add_line
new MDLine(loc
, "")
2518 block
.add_line
new MDLine(loc
, "text")
2519 block
.add_line
new MDLine(loc
, "")
2520 block
.add_line
new MDLine(loc
, "")
2521 block
.add_line
new MDLine(loc
, "")
2522 block
.add_line
new MDLine(loc
, "")
2523 assert block
.remove_surrounding_empty_lines
2524 assert block
.first_line
.value
== "text"
2525 assert block
.last_line
.value
== "text"
2532 # A dummy location for testing purposes.
2533 var loc
= new MDLocation(0, 0, 0, 0)
2537 fun test_is_empty
do
2538 subject
= new MDLine(loc
, "")
2539 assert subject
.is_empty
2540 subject
= new MDLine(loc
, " ")
2541 assert subject
.is_empty
2542 subject
= new MDLine(loc
, "test")
2543 assert not subject
.is_empty
2544 subject
= new MDLine(loc
, " test")
2545 assert not subject
.is_empty
2549 subject
= new MDLine(loc
, "")
2550 assert subject
.leading
== 0
2551 subject
= new MDLine(loc
, " ")
2552 assert subject
.leading
== 4
2553 subject
= new MDLine(loc
, "test")
2554 assert subject
.leading
== 0
2555 subject
= new MDLine(loc
, " test")
2556 assert subject
.leading
== 4
2559 fun test_trailing
do
2560 subject
= new MDLine(loc
, "")
2561 assert subject
.trailing
== 0
2562 subject
= new MDLine(loc
, " ")
2563 assert subject
.trailing
== 0
2564 subject
= new MDLine(loc
, "test ")
2565 assert subject
.trailing
== 3
2566 subject
= new MDLine(loc
, " test ")
2567 assert subject
.trailing
== 1
2570 fun test_line_type
do
2571 var v
= new MarkdownProcessor
2572 subject
= new MDLine(loc
, "")
2573 assert v
.line_kind
(subject
) isa LineEmpty
2574 subject
= new MDLine(loc
, " ")
2575 assert v
.line_kind
(subject
) isa LineEmpty
2576 subject
= new MDLine(loc
, "text ")
2577 assert v
.line_kind
(subject
) isa LineOther
2578 subject
= new MDLine(loc
, " # Title")
2579 assert v
.line_kind
(subject
) isa LineHeadline
2580 subject
= new MDLine(loc
, " ### Title")
2581 assert v
.line_kind
(subject
) isa LineHeadline
2582 subject
= new MDLine(loc
, " code")
2583 assert v
.line_kind
(subject
) isa LineCode
2584 subject
= new MDLine(loc
, " Title ")
2585 subject
.next
= new MDLine(loc
, "== ")
2586 assert v
.line_kind
(subject
) isa LineHeadline1
2587 subject
= new MDLine(loc
, " Title ")
2588 subject
.next
= new MDLine(loc
, "-- ")
2589 assert v
.line_kind
(subject
) isa LineHeadline2
2590 subject
= new MDLine(loc
, " * * * ")
2591 assert v
.line_kind
(subject
) isa LineHR
2592 subject
= new MDLine(loc
, " *** ")
2593 assert v
.line_kind
(subject
) isa LineHR
2594 subject
= new MDLine(loc
, "- -- ")
2595 assert v
.line_kind
(subject
) isa LineHR
2596 subject
= new MDLine(loc
, "--------- ")
2597 assert v
.line_kind
(subject
) isa LineHR
2598 subject
= new MDLine(loc
, " >")
2599 assert v
.line_kind
(subject
) isa LineBlockquote
2600 subject
= new MDLine(loc
, "<p></p>")
2601 assert v
.line_kind
(subject
) isa LineXML
2602 subject
= new MDLine(loc
, "<p>")
2603 assert v
.line_kind
(subject
) isa LineOther
2604 subject
= new MDLine(loc
, " * foo")
2605 assert v
.line_kind
(subject
) isa LineUList
2606 subject
= new MDLine(loc
, "- foo")
2607 assert v
.line_kind
(subject
) isa LineUList
2608 subject
= new MDLine(loc
, "+ foo")
2609 assert v
.line_kind
(subject
) isa LineUList
2610 subject
= new MDLine(loc
, "1. foo")
2611 assert v
.line_kind
(subject
) isa LineOList
2612 subject
= new MDLine(loc
, " 11111. foo")
2613 assert v
.line_kind
(subject
) isa LineOList
2616 fun test_line_type_ext
do
2617 var v
= new MarkdownProcessor
2618 subject
= new MDLine(loc
, " ~~~")
2619 assert v
.line_kind
(subject
) isa LineFence
2620 subject
= new MDLine(loc
, " ```")
2621 assert v
.line_kind
(subject
) isa LineFence
2624 fun test_count_chars
do
2625 subject
= new MDLine(loc
, "")
2626 assert subject
.count_chars
('*') == 0
2627 subject
= new MDLine(loc
, "* ")
2628 assert subject
.count_chars
('*') == 1
2629 subject
= new MDLine(loc
, " * text")
2630 assert subject
.count_chars
('*') == 0
2631 subject
= new MDLine(loc
, " * * *")
2632 assert subject
.count_chars
('*') == 3
2633 subject
= new MDLine(loc
, "text ** ")
2634 assert subject
.count_chars
('*') == 0
2637 fun test_count_chars_start
do
2638 subject
= new MDLine(loc
, "")
2639 assert subject
.count_chars_start
('*') == 0
2640 subject
= new MDLine(loc
, "* ")
2641 assert subject
.count_chars_start
('*') == 1
2642 subject
= new MDLine(loc
, " * text")
2643 assert subject
.count_chars_start
('*') == 1
2644 subject
= new MDLine(loc
, " * * * text")
2645 assert subject
.count_chars_start
('*') == 3
2646 subject
= new MDLine(loc
, "text ** ")
2647 assert subject
.count_chars_start
('*') == 0
2651 class TestHTMLDecorator
2654 fun test_headlines
do
2668 var proc
= new MarkdownProcessor
2669 var decorator
= proc
.emitter
.decorator
.as(HTMLDecorator)
2672 for id
, headline
in decorator
.headlines
do
2673 res
+= "{headline.title}:{id}\n"
2692 class TestTokenLocation
2695 fun test_token_location1
do
2696 var string
= "**Hello** `World`"
2698 "TokenStrongStar at 1,1--1,1",
2699 "TokenStrongStar at 1,8--1,8",
2700 "TokenCodeSingle at 1,11--1,11",
2701 "TokenCodeSingle at 1,17--1,17"]
2702 (new TestTokenProcessor(stack
)).process
(string
)
2705 fun test_token_location2
do
2706 var string
= "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
2708 "TokenStrongStar at 1,1--1,1",
2709 "TokenStrongStar at 1,8--1,8",
2710 "TokenCodeSingle at 2,1--2,1",
2711 "TokenCodeSingle at 2,7--2,7",
2712 "TokenEmStar at 3,1--3,1",
2713 "TokenEmStar at 3,9--3,9",
2714 "TokenLink at 4,1--4,1"]
2715 (new TestTokenProcessor(stack
)).process
(string
)
2718 fun test_token_location3
do
2719 var string
= """**Hello**
2724 "TokenStrongStar at 1,1--1,1",
2725 "TokenStrongStar at 1,8--1,8",
2726 "TokenCodeSingle at 2,1--2,1",
2727 "TokenCodeSingle at 2,7--2,7",
2728 "TokenEmStar at 3,1--3,1",
2729 "TokenEmStar at 3,9--3,9",
2730 "TokenLink at 4,1--4,1"]
2731 (new TestTokenProcessor(stack
)).process
(string
)
2735 class TestTokenProcessor
2736 super MarkdownProcessor
2738 var test_stack
: Array[String]
2740 redef fun token_at
(input
, pos
) do
2742 if token
isa TokenNone then return token
2743 var res
= "{token.class_name} at {token.location}"
2745 var exp
= test_stack
.shift
2751 class TestBlockLocation
2754 var proc
= new MarkdownProcessor
2756 fun test_block_location1
do
2758 "BlockHeadline: 1,1--1,8",
2759 "BlockListItem: 2,1--2,6",
2760 "BlockListItem: 3,1--3,5"
2763 "# Title\n* li1\n* li2"
2764 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2765 proc
.process
(string
)
2768 fun test_block_location2
do
2770 "BlockHeadline: 1,1--1,11",
2771 "BlockFence: 3,1--5,4",
2772 "BlockListItem: 7,1--7,7",
2773 "BlockListItem: 8,1--8,6"]
2774 var string
="""#### Title
2782 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2783 proc
.process
(string
)
2787 class TestBlockDecorator
2790 var stack
: Array[String]
2792 redef fun add_headline
(v
, block
) do
2797 redef fun add_listitem
(v
, block
) do
2802 redef fun add_blockquote
(v
, block
) do
2807 redef fun add_code
(v
, block
) do
2812 fun check_res
(block
: Block) do
2813 var res
= "{block.class_name}: {block.block.location}"
2814 var exp
= stack
.shift