Skip to content

fix for nested lists #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Jan 31, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/Pod/Simple/XHTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ sub new {
$new->{'output'} = [];
$new->{'saved'} = [];
$new->{'ids'} = {};
$new->{'in_li'} = [];

$new->{'__region_targets'} = [];
$new->{'__literal_targets'} = {};
Expand Down Expand Up @@ -282,15 +283,15 @@ sub start_head3 { $_[0]{'in_head'} = 3 }
sub start_head4 { $_[0]{'in_head'} = 4 }

sub start_item_number {
$_[0]{'scratch'} = "</li>\n" if $_[0]{'in_li'};
$_[0]{'scratch'} = "</li>\n" if ($_[0]{'in_li'}->[-1] && pop @{$_[0]{'in_li'}});
$_[0]{'scratch'} .= '<li><p>';
$_[0]{'in_li'} = 1
push @{$_[0]{'in_li'}}, 1;
}

sub start_item_bullet {
$_[0]{'scratch'} = "</li>\n" if $_[0]{'in_li'};
$_[0]{'scratch'} = "</li>\n" if ($_[0]{'in_li'}->[-1] && pop @{$_[0]{'in_li'}});
$_[0]{'scratch'} .= '<li><p>';
$_[0]{'in_li'} = 1
push @{$_[0]{'in_li'}}, 1;
}

sub start_item_text {
Expand All @@ -301,9 +302,9 @@ sub start_item_text {
$_[0]{'scratch'} .= '<dt>';
}

sub start_over_bullet { $_[0]{'scratch'} = '<ul>'; $_[0]->emit }
sub start_over_bullet { $_[0]{'scratch'} = '<ul>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit }
sub start_over_block { $_[0]{'scratch'} = '<ul>'; $_[0]->emit }
sub start_over_number { $_[0]{'scratch'} = '<ol>'; $_[0]->emit }
sub start_over_number { $_[0]{'scratch'} = '<ol>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit }
sub start_over_text {
$_[0]{'scratch'} = '<dl>';
$_[0]{'dl_level'}++;
Expand All @@ -314,14 +315,16 @@ sub start_over_text {
sub end_over_block { $_[0]{'scratch'} .= '</ul>'; $_[0]->emit }

sub end_over_number {
$_[0]{'scratch'} = "</li>\n" if delete $_[0]{'in_li'};
$_[0]{'scratch'} = "</li>\n" if ( pop @{$_[0]{'in_li'}} );
$_[0]{'scratch'} .= '</ol>';
pop @{$_[0]{'in_li'}};
$_[0]->emit;
}

sub end_over_bullet {
$_[0]{'scratch'} = "</li>\n" if delete $_[0]{'in_li'};
$_[0]{'scratch'} = "</li>\n" if ( pop @{$_[0]{'in_li'}} );
$_[0]{'scratch'} .= '</ul>';
pop @{$_[0]{'in_li'}};
$_[0]->emit;
}

Expand Down Expand Up @@ -513,8 +516,8 @@ sub start_L {

sub end_L { $_[0]{'scratch'} .= '</a>' }

sub start_S { $_[0]{'scratch'} .= '<nobr>' }
sub end_S { $_[0]{'scratch'} .= '</nobr>' }
sub start_S { $_[0]{'scratch'} .= '<span style="white-space: nowrap;">' }
sub end_S { $_[0]{'scratch'} .= '</span>' }

sub emit {
my($self) = @_;
Expand Down
109 changes: 107 additions & 2 deletions t/xhtml01.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {

use strict;
use lib '../lib';
use Test::More tests => 50;
use Test::More tests => 52;
#use Test::More 'no_plan';

use_ok('Pod::Simple::XHTML') or exit;
Expand Down Expand Up @@ -121,6 +121,59 @@ is($results, <<'EOHTML', "simple bulleted list");
EOHTML


initialize($parser, $results);
$parser->parse_string_document(<<'EOPOD');
=over

=item *

P: Gee, Brain, what do you want to do tonight?

=item *

B: The same thing we do every night, Pinky. Try to take over the world!

=over

=item *

Take over world

=item *

Do laundry

=back

=back

EOPOD

is($results, <<'EOHTML', "nested bulleted list");
<ul>

<li><p>P: Gee, Brain, what do you want to do tonight?</p>

</li>
<li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>

<ul>

<li><p>Take over world</p>

</li>
<li><p>Do laundry</p>

</li>
</ul>

</li>
</ul>

EOHTML



initialize($parser, $results);
$parser->parse_string_document(<<'EOPOD');
=over
Expand Down Expand Up @@ -151,6 +204,58 @@ is($results, <<'EOHTML', "numbered list");
EOHTML


initialize($parser, $results);
$parser->parse_string_document(<<'EOPOD');
=over

=item 1

P: Gee, Brain, what do you want to do tonight?

=item 2

B: The same thing we do every night, Pinky. Try to take over the world!

=over

=item 1

Take over world

=item 2

Do laundry

=back

=back

EOPOD

is($results, <<'EOHTML', "nested numbered list");
<ol>

<li><p>P: Gee, Brain, what do you want to do tonight?</p>

</li>
<li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>

<ol>

<li><p>Take over world</p>

</li>
<li><p>Do laundry</p>

</li>
</ol>

</li>
</ol>

EOHTML


initialize($parser, $results);
$parser->parse_string_document(<<'EOPOD');
=over
Expand Down Expand Up @@ -416,7 +521,7 @@ $parser->parse_string_document(<<'EOPOD');
A plain paragraph with S<non breaking text>.
EOPOD
is($results, <<"EOHTML", "Non breaking text in a paragraph");
<p>A plain paragraph with <nobr>non breaking text</nobr>.</p>
<p>A plain paragraph with <span style="white-space: nowrap;">non breaking text</span>.</p>

EOHTML

Expand Down