Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Maintain consistent indentation when handling multiple consecutive verbatim sections #4

Merged
merged 1 commit into from

2 participants

@prakashk

The following code segment from a pod file:

sub shirt_size {
    my $self = shift;

    if (@_) {
        $self->_validate_shirt_size( $_[0] );
        $self->{shirt_size} = $_[0];
    }

    return $self->{shirt_size};
}

is formatted as the following docbook xml (notice how the if block is outdented):

<screen><![CDATA[sub shirt_size {
    my $self = shift;

if (@_) {
    $self->_validate_shirt_size( $_[0] );
    $self->{shirt_size} = $_[0];
}

    return $self->{shirt_size};
}]]></screen>

This commit fixes this.

Please review.

Thanks,
Prakash

@jozef jozef merged commit e666125 into jozef:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2011
  1. @prakashk
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 6 deletions.
  1. +19 −6 lib/Pod/2/DocBook.pm
View
25 lib/Pod/2/DocBook.pm
@@ -434,16 +434,28 @@ sub verbatim {
# find the minimum-length whitespace leader for this paragraph
my ($leader) = ($line =~ /^(\s+)/xms);
$leader ||= q{};
-
+
$min_leader = length($leader)
- if ((not defined $min_leader) or (length($leader) < $min_leader));
- }
+ if ((not defined $min_leader) or ($leader and length($leader) < $min_leader));
- $paragraph = join("\n", @lines);
+ if ($state eq 'verbatim') {
+ if (defined $parser->{'Pod::2::DocBook::verbatim_prev_min_leader'}) {
+ if ($min_leader > $parser->{'Pod::2::DocBook::verbatim_prev_min_leader'}) {
+ $min_leader = $parser->{'Pod::2::DocBook::verbatim_prev_min_leader'};
+ }
+ }
+ else {
+ $parser->{'Pod::2::DocBook::verbatim_prev_min_leader'} = $min_leader;
+ }
+ }
+ }
# strip the minimum-length whitespace leader from every line
- $paragraph =~ s/^\s{$min_leader}//gxms
- if $min_leader;
+ if ($min_leader) {
+ s/^\s{$min_leader}// for @lines;
+ }
+
+ $paragraph = join("\n", @lines);
if (!defined $state) {
print $out_fh $parser->_current_indent(), "<screen><![CDATA[$paragraph";
@@ -811,6 +823,7 @@ sub _handle_item {
print $out_fh "]]></screen>\n";
$state = pop @{ $parser->{'Pod::2::DocBook::state'} };
$state = q{} unless defined $state;
+ $parser->{'Pod::2::DocBook::verbatim_prev_min_leader'} = undef;
}
if ($state =~ /list\+$/xms) {
Something went wrong with that request. Please try again.