Skip to content

Commit

Permalink
determine the verbatim pod indent from shortest indented line
Browse files Browse the repository at this point in the history
This addesses ascii art broken by #781

fixes #795
  • Loading branch information
jberger committed May 9, 2015
1 parent ef4fcea commit c657525
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -3,6 +3,7 @@ use Mojo::Base 'Mojolicious::Plugin';

use Mojo::Asset::File;
use Mojo::ByteStream 'b';
use Mojo::Collection 'c';
use Mojo::DOM;
use Mojo::URL;
use Mojo::Util 'slurp';
Expand Down Expand Up @@ -96,7 +97,12 @@ sub _pod_to_html {
my $parser = Pod::Simple::XHTML->new;
$parser->perldoc_url_prefix('https://metacpan.org/pod/');
$parser->$_('') for qw(html_header html_footer);
$parser->strip_verbatim_indent(sub { my ($i) = $_[0][0] =~ /^(\s+)/; $i });
$parser->strip_verbatim_indent(
sub {
c(@{$_[0]})->map(sub {/^(\s+)/})
->reduce(sub { length $b < length $a ? $b : $a });
}
);
$parser->output_string(\(my $output));
return $@ unless eval { $parser->parse_string_document("$pod"); 1 };

Expand Down
14 changes: 14 additions & 0 deletions t/mojolicious/pod_renderer_lite_app.t
Expand Up @@ -22,6 +22,8 @@ post '/' => 'index';

post '/block' => 'block';

get '/art' => 'art';

get '/empty' => {inline => '', handler => 'pod'};

my $t = Test::Mojo->new;
Expand All @@ -42,6 +44,9 @@ $t->post_ok('/block')->status_is(200)
->content_like(qr!<pre><code>\{\n foo\(\);\n\}</code></pre>!)
->content_like(qr!<p><code>test</code></p>!)->content_like(qr/Gray/);

$t->get_ok('/art')->status_is(200)->text_like('h2[id="art"]' => qr!art!)
->text_like('pre code' => qr!\s{2}#\n#\s{3}#\n\s{2}#!);

# Empty
$t->get_ok('/empty')->status_is(200)->content_is('');

Expand Down Expand Up @@ -106,3 +111,12 @@ test321<%= pod_to_html begin %>=head2 lalala
}
C<test><% end %>
@@ art.html.ep
<%= pod_to_html begin %>=head2 art
#
# #
#
<% end %>

0 comments on commit c657525

Please sign in to comment.