1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 15;
use MojoMojo::Formatter::Markdown;
use Test::Differences;
my ( $content, $got, $expected, $test );
#----------------------------------------------------------------------------
$test = 'extra EOL at EOF';
$content = 'foo';
$expected = "<p>foo</p>\n";
is( MojoMojo::Formatter::Markdown->main_format_content( \$content ), $expected, $test );
$test = 'consecutive EOL at EOF collapsed into one';
$content = "foo\n\n";
$expected = "<p>foo</p>\n";
is( MojoMojo::Formatter::Markdown->main_format_content( \$content ), $expected, $test );
#----------------------------------------------------------------------------
$content = 'Here is an  image.';
$expected =
'<p>Here is an <img src="/image.jpg" alt="Image alt text" title="Image title" /> image.</p>'
. "\n"; # Markdown makes sure there's a final "\n"
is( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
$expected, 'basic image' );
#----------------------------------------------------------------------------
$test = '<div with="attributes"> in a code span';
$content = <<'MARKDOWN';
This is the code: `<div markdown="1">`.
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<p>This is the code: <code><div markdown="1"></code>.</p>
HTML
#----------------------------------------------------------------------------
$test = 'blockquotes';
$content = <<'MARKDOWN';
Below is a blockquote:
> quoted text
A quote is above.
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<p>Below is a blockquote:</p>
<blockquote>
<p>quoted text</p>
</blockquote>
<p>A quote is above.</p>
HTML
#----------------------------------------------------------------------------
$test = 'direct <http://url.com> hyperlinks';
$content = <<'MARKDOWN';
This should be linked: <http://mojomojo.org>.
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<p>This should be linked: <a href="http://mojomojo.org">http://mojomojo.org</a>.</p>
HTML
#----------------------------------------------------------------------------
$test = "don't make a <div> into <p><div></p>, for empty divs";
$content = <<'MARKDOWN';
<div>
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div>
</div>
HTML
#----------------------------------------------------------------------------
$test = "don't make a <div> into <p><div></p>, for divs wth attributes";
$content = <<'MARKDOWN';
<div class="content">
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div class="content">
</div>
HTML
#----------------------------------------------------------------------------
$test =
"if div attributes are not quoted, they're fair game because that's invalid HTML Strict";
$content = <<'MARKDOWN';
<div class=this_must_be_quoted_otherwise_the_whole_div_is_not_HTML_but_junk>
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div class=this_must_be_quoted_otherwise_the_whole_div_is_not_HTML_but_junk>
</div>
HTML
#----------------------------------------------------------------------------
$test = 'do not interpret block-level Markdown in divs without attributes';
$content = <<'MARKDOWN';
<div>
# not a heading 1
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div>
# not a heading 1
</div>
HTML
$test = 'do interpret block-level Markdown in divs with the markdown="1" attribute';
$content = <<'MARKDOWN';
<div markdown="1">
# heading 1
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div>
<h1>heading 1</h1>
</div>
HTML
#----------------------------------------------------------------------------
$test = 'do not interpret inline Markdown in divs without attributes';
$content = <<'MARKDOWN';
<div>
*this should be left as is*
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div>
*this should be left as is*
</div>
HTML
$test = 'do interpret inline Markdown in divs with a markdown="on" attribute';
$content = <<'MARKDOWN';
<div markdown="on">
*this should be emphasized*
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div>
<p><em>this should be emphasized</em></p>
</div>
HTML
#----------------------------------------------------------------------------
$test = "interpret Markdown in divs with other attributes besides markdown='1'";
$content = <<'MARKDOWN';
<div class="content" markdown='1'>
*this should be emphasized*
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div class="content">
<p><em>this should be emphasized</em></p>
</div>
HTML
#----------------------------------------------------------------------------
$test = 'in <divs markdown="1">, leave alone HTML like <span>s';
$content = <<'MARKDOWN';
<div class="photo_frame" markdown="1">

<span class="caption">Caption</span>
</div>
MARKDOWN
eq_or_diff( MojoMojo::Formatter::Markdown->main_format_content( \$content ),
<<'HTML', $test );
<div class="photo_frame">
<p><img src="/image.jpg" alt="alt text" title="title" />
<span class="caption">Caption</span></p>
</div>
HTML
|