| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use utf8; |
| 4 |
|
| 5 |
use Markdown::Perl; |
| 6 |
use Test2::V0; |
| 7 |
|
| 8 |
sub run { |
| 9 |
&Markdown::Perl::convert; |
| 10 |
} |
| 11 |
|
| 12 |
is(run("abc"), "<p>abc</p>\n", 'line1'); |
| 13 |
is(run("abc\n"), "<p>abc</p>\n", 'line2'); |
| 14 |
is(run(" abc "), "<p>abc</p>\n", 'line3'); |
| 15 |
is(run("0"), "<p>0</p>\n", 'line4'); |
| 16 |
|
| 17 |
is(run("abc\ndef\n"), "<p>abc\ndef</p>\n", 'soft_break'); |
| 18 |
is(run("abc \ndef\n", two_spaces_hard_line_breaks => 1), "<p>abc<br />\ndef</p>\n", 'hard_break1'); |
| 19 |
is(run("abc\ndef \n"), "<p>abc\ndef</p>\n", 'hard_break2'); |
| 20 |
is(run("abc\\\ndef"), "<p>abc<br />\ndef</p>\n", 'hard_break3'); |
| 21 |
is(run("abc\\\\\ndef"), "<p>abc\\\ndef</p>\n", 'hard_break4'); |
| 22 |
is(run("abc\\\\\\\ndef"), "<p>abc\\<br />\ndef</p>\n", 'hard_break5'); |
| 23 |
|
| 24 |
is(run("abc `def` ghi"), "<p>abc <code>def</code> ghi</p>\n", 'code1'); |
| 25 |
is(run("abc`def`ghi"), "<p>abc<code>def</code>ghi</p>\n", 'code2'); |
| 26 |
is(run("abc``def`ghi``"), "<p>abc<code>def`ghi</code></p>\n", 'code3'); |
| 27 |
is(run("`` ` ``"), "<p><code>`</code></p>\n", 'code4'); |
| 28 |
is(run("`` ``"), "<p><code> </code></p>\n", 'code5'); |
| 29 |
is(run("0`x`"), "<p>0<code>x</code></p>\n", 'code6'); |
| 30 |
is(run("`x`0"), "<p><code>x</code>0</p>\n", 'code7'); |
| 31 |
|
| 32 |
is(run("`abc`def`"), "<p><code>abc</code>def`</p>\n", 'escaped_code1'); |
| 33 |
is(run("\\`abc`def`"), "<p>`abc<code>def</code></p>\n", 'escaped_code2'); |
| 34 |
is(run("`abc\\`def`"), "<p><code>abc\\</code>def`</p>\n", 'escaped_code3'); |
| 35 |
is(run("\\\\`abc`def`"), "<p>\\<code>abc</code>def`</p>\n", 'escaped_code4'); |
| 36 |
|
| 37 |
is(run("&="), "<p>&=</p>\n", 'html_escape1'); |
| 38 |
is(run("&"), "<p>&</p>\n", 'html_escape2'); |
| 39 |
is(run("`&`"), "<p><code>&amp;</code></p>\n", 'html_escape3'); |
| 40 |
|
| 41 |
is(run("©"), "<p>©</p>\n", 'html_decode1'); |
| 42 |
is(run("`©`"), "<p><code>&copy;</code></p>\n", 'html_decode2'); |
| 43 |
|
| 44 |
is(run('<http://foo>'), "<p><a href=\"http://foo\">http://foo</a></p>\n", 'autolink1'); |
| 45 |
is(run('<http:>'), "<p><a href=\"http:\">http:</a></p>\n", 'autolink2'); |
| 46 |
is(run('<http:foo&bar>'), "<p><a href=\"http:foo&bar\">http:foo&bar</a></p>\n", 'autolink3'); |
| 47 |
|
| 48 |
is(run('[foo](/bar)'), "<p><a href=\"/bar\">foo</a></p>\n", 'link1'); |
| 49 |
is(run('[](/bar)'), "<p><a href=\"/bar\"></a></p>\n", 'link2'); |
| 50 |
is(run('[foo]()'), "<p><a href=\"\">foo</a></p>\n", 'link3'); |
| 51 |
is(run('[foo](/bar "title")'), "<p><a href=\"/bar\" title=\"title\">foo</a></p>\n", 'link4'); |
| 52 |
is(run('[foo](</bar/baz>)'), "<p><a href=\"/bar/baz\">foo</a></p>\n", 'link5'); |
| 53 |
is(run('[foo](</bar/baz> "title")'), "<p><a href=\"/bar/baz\" title=\"title\">foo</a></p>\n", 'link6'); |
| 54 |
is(run('[foo](/bar "0")'), "<p><a href=\"/bar\" title=\"0\">foo</a></p>\n", 'link7'); |
| 55 |
is(run("[foo](/bar '0')"), "<p><a href=\"/bar\" title=\"0\">foo</a></p>\n", 'link8'); |
| 56 |
is(run('[foo](/bar (0))'), "<p><a href=\"/bar\" title=\"0\">foo</a></p>\n", 'link9'); |
| 57 |
is(run('[foo](/bar "")'), "<p><a href=\"/bar\" title=\"\">foo</a></p>\n", 'link10'); |
| 58 |
is(run(''), "<p><img src=\"/bar\" alt=\"foo\" title=\"0\" /></p>\n", 'image1'); |
| 59 |
|
| 60 |
is(run('*foo*'), "<p><em>foo</em></p>\n", 'em1'); |
| 61 |
is(run('_foo_'), "<p><em>foo</em></p>\n", 'em2'); |
| 62 |
is(run('**foo**'), "<p><strong>foo</strong></p>\n", 'strong1'); |
| 63 |
is(run('__foo__'), "<p><strong>foo</strong></p>\n", 'strong2'); |
| 64 |
is(run('*foo*bar*'), "<p><em>foo</em>bar*</p>\n", 'em3'); |
| 65 |
is(run('*foo_bar*baz_'), "<p><em>foo_bar</em>baz_</p>\n", 'em4'); |
| 66 |
is(run('*foo**bar**baz*'), "<p><em>foo<strong>bar</strong>baz</em></p>\n", 'emphasis1'); |
| 67 |
is(run('*_*'), "<p><em>_</em></p>\n", 'emphasis2'); |
| 68 |
is(run('*foo __bar *baz__ bam*'), "<p><em>foo <strong>bar *baz</strong> bam</em></p>\n", 'emphasis3'); |
| 69 |
|
| 70 |
is(run('foo<div>bar'), "<p>foo<div>bar</p>\n", 'html1'); |
| 71 |
|
| 72 |
done_testing; |