Changeset 288

Show
Ignore:
Timestamp:
02/14/08 22:00:14 (5 months ago)
Author:
ingy
Message:
Account for multiple text events in a row.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ingy/WikiText/lib/WikiText/WikiByte/Emitter.pm

    r286 r288  
    55sub new { 
    66    my $class = shift; 
    7     return bless { @_ }, ref($class) || $class; 
     7    return bless { 
     8        @_, 
     9        last_event => '', 
     10    }, ref($class) || $class; 
    811} 
    912 
     
    2124    my $self = shift; 
    2225    my $ast = shift; 
    23     $self->{output} .= $ast->{output} || ''; 
     26    if ($self->{last_event} eq 'text') { 
     27        chomp $self->{output}; 
     28        my $subtext = $ast->{output} || ''; 
     29        $subtext =~ s/^ //; 
     30        $self->{output} .= $subtext; 
     31    } 
     32    else { 
     33        $self->{output} .= $ast->{output} || ''; 
     34    } 
    2435} 
    2536 
     
    3142    my $attributes = _get_attributes($node); 
    3243    $self->{output} .= "+$tag$attributes\n"; 
     44    $self->{last_event} = 'begin'; 
    3345} 
    3446 
     
    3850    my $tag = $node->{type}; 
    3951 
    40     return if $self->{output} =~ s/^\+$tag\n\z/=$tag\n/m; 
     52    $self->{last_event} = 'end'; 
     53 
     54    return if $self->{output} =~ s/^\+$tag\b(.*\n)\z/=$tag$1/m; 
    4155 
    4256    $tag =~ s/-.*//; 
     
    4862    my $text = shift; 
    4963    $text =~ s/\n/\n /g; 
    50     $self->{output} .= " $text\n"; 
     64    if ($self->{last_event} eq 'text') { 
     65        chomp $self->{output}; 
     66        $self->{output} .= "$text\n"; 
     67    } 
     68    else { 
     69        $self->{output} .= " $text\n"; 
     70    } 
     71    $self->{last_event} = 'text'; 
    5172} 
    5273