Skip to content

Commit

Permalink
fix indentation of ASCII art in documentation browser (closes #796)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 11, 2015
1 parent a885ddc commit 29ce807
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

6.11 2015-05-09
6.11 2015-05-11
- Updated jQuery to version 2.1.4.
- Fixed indentation of ASCII art in documentation browser. (jberger)

6.10 2015-04-26
- Removed support for user/group switching, because it never worked
Expand Down
6 changes: 5 additions & 1 deletion lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -35,6 +35,10 @@ sub register {
'/perldoc/:module' => $defaults => [module => qr/[^.]+/] => \&_perldoc);
}

sub _indentation {
(sort map {/^(\s+)/} @{shift()})[0];
}

sub _html {
my ($c, $src) = @_;

Expand Down Expand Up @@ -97,7 +101,7 @@ 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(\&_indentation);
$parser->output_string(\(my $output));
return $@ unless eval { $parser->parse_string_document("$pod"); 1 };

Expand Down
17 changes: 16 additions & 1 deletion t/mojolicious/pod_renderer_lite_app.t
Expand Up @@ -20,7 +20,9 @@ get '/' => sub {

post '/' => 'index';

post '/block' => 'block';
post '/block';

get '/art';

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

Expand All @@ -42,6 +44,10 @@ $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/);

# Mixed indentation
$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 +112,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 29ce807

Please sign in to comment.