Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle nested C<...> codes

  • Loading branch information...
commit d083631763d462da06916834ac28f397f03e0e94 1 parent 65359b5
@gisle gisle authored
Showing with 41 additions and 13 deletions.
  1. +14 −8 lib/Pod/Simple/XHTML.pm
  2. +27 −5 t/xhtml20.t
View
22 lib/Pod/Simple/XHTML.pm
@@ -342,8 +342,8 @@ sub accept_targets_as_html {
}
sub handle_text {
- if ($_[0]{'in_code'}) {
- return $_[0]->handle_code( $_[1] );
+ if ($_[0]{'in_code'} && @{$_[0]{'in_code'}}) {
+ return $_[0]->handle_code( $_[1], $_[0]{'in_code'}[-1] );
}
# escape special characters in HTML (<, >, &, etc)
my $text = $_[0]->__in_literal_xhtml_region
@@ -366,8 +366,15 @@ sub handle_code {
$_[0]{'scratch'} .= $_[0]->encode_entities( $_[1] );
}
-sub start_Para { $_[0]{'scratch'} = '<p>' }
-sub start_Verbatim { $_[0]{'scratch'} = '<pre>'; $_[0]{'in_code'} = 1; $_[0]->start_code('Verbatim'); }
+sub start_Para {
+ $_[0]{'scratch'} = '<p>';
+}
+
+sub start_Verbatim {
+ $_[0]{'scratch'} = '<pre>';
+ push(@{$_[0]{'in_code'}}, 'Verbatim');
+ $_[0]->start_code($_[0]{'in_code'}[-1]);
+}
sub start_head1 { $_[0]{'in_head'} = 1; $_[0]{htext} = ''; }
sub start_head2 { $_[0]{'in_head'} = 2; $_[0]{htext} = ''; }
@@ -430,9 +437,8 @@ sub end_over_text {
sub end_Para { $_[0]{'scratch'} .= '</p>'; $_[0]->emit }
sub end_Verbatim {
- $_[0]->end_code('Verbatim');
+ $_[0]->end_code(pop(@{$_[0]->{'in_code'}}));
$_[0]{'scratch'} .= '</pre>';
- delete $_[0]{'in_code'};
$_[0]->emit;
}
@@ -603,8 +609,8 @@ sub end_Document {
sub start_B { $_[0]{'scratch'} .= '<b>' }
sub end_B { $_[0]{'scratch'} .= '</b>' }
-sub start_C { $_[0]{'in_code'} = 1; $_[0]->start_code('C'); }
-sub end_C { $_[0]->end_code('C'); delete $_[0]{'in_code'}; }
+sub start_C { push(@{$_[0]{'in_code'}}, 'C'); $_[0]->start_code($_[0]{'in_code'}[-1]); }
+sub end_C { $_[0]->end_code(pop(@{$_[0]{'in_code'}})); }
sub start_F { $_[0]{'scratch'} .= '<i>' }
sub end_F { $_[0]{'scratch'} .= '</i>' }
View
32 t/xhtml20.t
@@ -4,17 +4,27 @@
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 1;
BEGIN {
package MyXHTML;
use base 'Pod::Simple::XHTML';
sub handle_code {
- my($self, $code) = @_;
- $code = "[$code]";
+ my($self, $code, $kind) = @_;
+ $code = "${kind}[$code]";
$self->SUPER::handle_code($code);
}
+
+ sub start_code {
+ my($self, $kind) = @_;
+ $self->{scratch} .= "<code class=\"$kind\">";
+ }
+
+ sub end_code {
+ my($self, $kind) = @_;
+ $self->{scratch} .= "</code><!-- $kind -->";
+ }
}
@@ -28,14 +38,26 @@ $parser->parse_string_document(<<'EOT');
This is C<$code> and so is:
my $foo = 1;
+
+Code might even be C<<< nested( B<< C<1> >> ) >>>.
EOT
-like $results, qr/<code>\[\$code]<\/code>/;
-like $results , qr/<pre><code>\[ my \$foo = 1;/;
+is($results, <<'EOT');
+<h1 id="Foo">Foo</h1>
+
+<p>This is <code class="C">C[$code]</code><!-- C --> and so is:</p>
+
+<pre><code class="Verbatim">Verbatim[ my $foo = 1;]</code><!-- Verbatim --></pre>
+
+<p>Code might even be <code class="C">C[nested( ]<b><code class="C">C[1]</code><!-- C --></b>C[ )]</code><!-- C -->.</p>
+
+EOT
sub initialize {
$parser = MyXHTML->new;
+ $parser->html_header('');
+ $parser->html_footer('');
$parser->output_string( \$results );
$results = '';
}
Please sign in to comment.
Something went wrong with that request. Please try again.