Skip to content

Commit

Permalink
Merge pull request perl-pod#46 from tsibley/code-in-head-regression
Browse files Browse the repository at this point in the history
Fix code (C<>) in head regression
  • Loading branch information
theory committed Feb 13, 2013
2 parents 59be9b7 + 17c7b67 commit 1ca92b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/Pod/Simple/XHTML.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -342,15 +342,19 @@ sub accept_targets_as_html {
} }


sub handle_text { sub handle_text {
if ($_[0]{'in_code'} && @{$_[0]{'in_code'}}) {
return $_[0]->handle_code( $_[1], $_[0]{'in_code'}[-1] );
}
# escape special characters in HTML (<, >, &, etc) # escape special characters in HTML (<, >, &, etc)
my $text = $_[0]->__in_literal_xhtml_region my $text = $_[0]->__in_literal_xhtml_region
? $_[1] ? $_[1]
: $_[0]->encode_entities( $_[1] ); : $_[0]->encode_entities( $_[1] );


$_[0]{'scratch'} .= $text; if ($_[0]{'in_code'} && @{$_[0]{'in_code'}}) {
# Intentionally use the raw text in $_[1], even if we're not in a
# literal xhtml region, since handle_code calls encode_entities.
$_[0]->handle_code( $_[1], $_[0]{'in_code'}[-1] );
} else {
$_[0]{'scratch'} .= $text;
}

$_[0]{htext} .= $text if $_[0]{'in_head'}; $_[0]{htext} .= $text if $_[0]{'in_head'};
} }


Expand Down
18 changes: 17 additions & 1 deletion t/xhtml10.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {


use strict; use strict;
use lib '../lib'; use lib '../lib';
use Test::More tests => 58; use Test::More tests => 60;
#use Test::More 'no_plan'; #use Test::More 'no_plan';


use_ok('Pod::Simple::XHTML') or exit; use_ok('Pod::Simple::XHTML') or exit;
Expand Down Expand Up @@ -97,6 +97,22 @@ is $results, <<'EOF', 'Should have both and the index';
<h1 id="Bar">Bar</h1> <h1 id="Bar">Bar</h1>
EOF EOF

initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo C<Bar>\n\n=head1 C<Baz>" ),
'Parse two headers with C<> formatting';
is $results, <<'EOF', 'Should have the index';
<ul id="index">
<li><a href="#Foo-Bar">Foo Bar</a></li>
<li><a href="#Baz">Baz</a></li>
</ul>
<h1 id="Foo-Bar">Foo <code>Bar</code></h1>
<h1 id="Baz"><code>Baz</code></h1>
EOF

initialize($parser, $results); initialize($parser, $results);
ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar\n\n=head1 Baz" ), ok $parser->parse_string_document( "=head1 Foo\n\n=head1 Bar\n\n=head1 Baz" ),
'Parse three headers'; 'Parse three headers';
Expand Down

0 comments on commit 1ca92b9

Please sign in to comment.