Ticket #477: pod2html.patch

File pod2html.patch, 2.1 KB (added by rg, 5 years ago)
  • lib/Parrot/Docs/POD2HTML.pm

     
    3333our $VERSION = '1.0'; 
    3434 
    3535use Parrot::Docs::HTMLPage; 
     36use Parrot::Distribution; 
    3637 
     38=item C<new()> 
     39 
     40Extend C<Pod::Simple::HTML> method to accept PIR and PASM sections that 
     41contain example code, which will be put into a <pre> HTML element. 
     42 
     43=cut 
     44 
     45sub new { 
     46    my $new = shift->SUPER::new(@_); 
     47 
     48    $new->accept_targets('PIR', 'PASM'); 
     49    delete(@{$new->{'Tagmap'}}{'Data','/Data'}); 
     50 
     51    return $new; 
     52} 
     53 
    3754=item C<do_beginning()> 
    3855 
    3956Reimplements the C<Pod::Simple::HTML> method to add a header to the start 
     
    125142    elsif ( $tagname eq 'Data' ) { 
    126143        $self->process_data_start_token($token); 
    127144    } 
     145    elsif ( $tagname eq 'for' ) { 
     146        $self->process_for_start_token($token); 
     147    } 
    128148    else { 
    129149        $self->process_other_start_token($token); 
    130150    } 
     
    312332        return; 
    313333    } 
    314334 
    315     printf { $self->{'output_fh'} } "\n" . $next->text . "\n"; 
     335    if  ($self->{IN_CODE_BLOCK}) { 
     336        print { $self->{'output_fh'} } $next->text; 
     337    } 
     338    else { 
     339        print { $self->{'output_fh'} } "\n" . $next->text . "\n"; 
     340    } 
    316341} 
    317342 
     343=item C<process_for_start_token($token)> 
     344 
     345Processes a for start token. 
     346 
     347=cut 
     348 
     349sub process_for_start_token { 
     350    my $self  = shift; 
     351    my $token = shift; 
     352    my $target = $token->attr("target"); 
     353 
     354    if ($target eq "PIR" || $target eq "PASM") { 
     355        print { $self->{'output_fh'} } "<pre>"; 
     356        $self->{IN_CODE_BLOCK} = 1; 
     357    } 
     358} 
     359 
    318360=item C<process_other_start_token($token)> 
    319361 
    320362Processes a start token not processable by the above methods. 
     
    368410    elsif ( $tagname eq 'item-text' ) { 
    369411        $self->{IN_ITEM_TEXT} = 0; 
    370412    } 
     413    elsif ( $tagname eq 'for' ) { 
     414        print { $self->{'output_fh'} } '</pre>' if $self->{IN_CODE_BLOCK}; 
     415        $self->{IN_CODE_BLOCK} = 0; 
     416    } 
    371417 
    372418    print { $self->{'output_fh'} } $self->{'Tagmap'}{"/$tagname"} || return; 
    373419