@@ -1266,19 +1266,22 @@ sub format {
12661266}
12671267
12681268sub string {
1269- my $self = shift ;
1270- my $block = shift ;
1269+ my ($self , $block ) = @_ ;
1270+ my $stack = $block ->{stack };
1271+ my $n = scalar(@$stack );
12711272 my @strings = ();
12721273 my $string ;
1273- foreach my $item (@{ $block ->{stack } }) {
1274+ for my $i (0 . . $n - 1) {
1275+ my $item = $stack ->[$i ];
1276+ my $next_par = $i + 1 < $n && $stack ->[ $i + 1 ]{type } eq 'par' ? $stack ->[ $i + 1 ] : undef ;
12741277 $self ->{item } = $item ;
12751278 $self ->{nl } = (!defined($strings [-1 ]) || $strings [-1 ] =~ m /\n $/ ? "" : "\n" );
12761279 for ($item ->{type }) {
1277- /indent / && do { $string = $self ->Indent ($item ); last };
1280+ /indent / && do { $string = $self ->Indent ($item , $ next_par ); last };
12781281 /align / && do { $string = $self ->Align ($item ); last };
12791282 /par / && do { $string = $self ->Par ($item ); last };
1280- /list / && do { $string = $self ->List ($item ); last };
1281- /bullet / && do { $string = $self ->Bullet ($item ); last };
1283+ /list / && do { $string = $self ->List ($item , $ next_par ); last };
1284+ /bullet / && do { $string = $self ->Bullet ($item , $ next_par ); last };
12821285 /text / && do { $string = $self ->Text ($item ); last };
12831286 /variable / && do { $string = $self ->Variable ($item , $block ); last };
12841287 /command / && do { $string = $self ->Command ($item ); last };
@@ -1523,17 +1526,14 @@ sub Escape {
15231526}
15241527
15251528sub Indent {
1526- my $self = shift ;
1527- my $item = shift ;
1528- return $self ->string($item ) if $item ->{indent } == 0 ;
1529- my $em = 2 .25 * $item ->{indent };
1530- return
1531- $self ->nl
1532- . '<div style="margin:0 0 0 '
1533- . $em . 'em">' . "\n"
1534- . $self->string($item)
1535- . $self->nl
1536- . "</div>\n";
1529+ my ($self , $item , $next_par ) = @_ ;
1530+ my $left = $item ->{indent } ? (2 .25 * $item ->{indent }) . 'em' : '0';
1531+ my $bottom = '0' ;
1532+ if ($next_par ) {
1533+ $next_par ->{used_on_prev_item } = 1 ;
1534+ $bottom = '1em' ;
1535+ }
1536+ return $self ->nl . "<div style=\"margin: 0 0 $bottom $left;\">\n" . $self->string($item) . $self->nl . "</div>\n";
15371537}
15381538
15391539sub Align {
@@ -1562,20 +1562,27 @@ sub Align {
15621562);
15631563
15641564sub List {
1565- my $self = shift ;
1566- my $item = shift ;
1567- my $list = $bullet { $item ->{bullet } };
1565+ my ($self , $item , $next_par ) = @_ ;
1566+ my $list = $bullet { $item ->{bullet } };
1567+ my $margin = '0' ;
1568+ if ($next_par ) {
1569+ $next_par ->{used_on_prev_item } = 1 ;
1570+ $margin = '0 0 1em 0' ;
1571+ }
15681572 return $self ->nl
15691573 . main::tag(
15701574 $list->[0],
1571- style => "margin:0 ; padding-left:2.25em; $list->[1]" ,
1575+ style => "margin: $margin ; padding-left: 2.25em; $list->[1]" ,
15721576 $self ->string($item ) . $self->nl
15731577 );
15741578}
15751579
15761580sub Bullet {
1577- my $self = shift ;
1578- my $item = shift ;
1581+ my ($self , $item , $next_par ) = @_ ;
1582+ if ($next_par ) {
1583+ $next_par ->{used_on_prev_item } = 1 ;
1584+ return $self ->nl . '<li style="margin-bottom: 1em;">' . $self->string($item) . "</li>\n";
1585+ }
15791586 return $self ->nl . '<li>' . $self->string($item) . "</li>\n";
15801587}
15811588
@@ -1603,9 +1610,8 @@ sub Heading {
16031610}
16041611
16051612sub Par {
1606- my $self = shift ;
1607- my $item = shift ;
1608- return $self ->nl . '<div style="margin-top:1em"></div>' . "\n";
1613+ my ($self , $item ) = @_ ;
1614+ return $item ->{used_on_prev_item } ? '' : $self ->nl . '<div style="margin-top:1em"></div>' . "\n";
16091615}
16101616
16111617sub Break {"<br />\n" }
0 commit comments