Changeset 3875


Ignore:
Timestamp:
05/10/09 16:02:03 (3 years ago)
Author:
MichaelTempest
Message:

Item1535: Inserted span elements when WYSIWYG_TT class is applied to other elements. Added unit tests to replicate fault.

Also updated the internal test documentation in TranslatorTest.pm. (CDot: Thanks for explaining things)

Added explicit event handlers for each type of event generated by HTML::Parser, to eliminate the empty text elements generated from the start_document and end_document events. The default event handler should never be called, now.

Location:
trunk/WysiwygPlugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML.pm

    r2957 r3875  
    6666 
    6767    my $this = new HTML::Parser( 
    68         start_h       => [ \&_openTag,  'self,tagname,attr' ], 
    69         end_h         => [ \&_closeTag, 'self,tagname' ], 
    70         declaration_h => [ \&_ignore,   'self' ], 
    71         default_h     => [ \&_text,     'self,text' ], 
    72         comment_h     => [ \&_comment,  'self,text' ] 
     68        start_h          => [ \&_openTag,  'self,tagname,attr' ], 
     69        end_h            => [ \&_closeTag, 'self,tagname' ], 
     70        text_h           => [ \&_text,     'self,text' ], 
     71        comment_h        => [ \&_comment,  'self,text' ], 
     72        declaration_h    => [ \&_ignore,   'self' ], 
     73        start_document_h => [ \&_ignore,   'self' ], 
     74        end_document_h   => [ \&_ignore,   'self' ], 
     75                default_h        => [ \&_default,  'self,event,text' ] 
    7376    ); 
    7477 
     
    220223} 
    221224 
     225sub _default { 
     226        my ( $this, $event, $text ) = @_; 
     227    # Unexpected $event event from HTML::Parser; text contains '$text' 
     228        ASSERT(0); 
     229} 
     230 
    222231sub _apply { 
    223232    my ( $this, $tag ) = @_; 
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm

    r3396 r3875  
    363363 
    364364# Collapse adjacent VERBATIM nodes together 
    365 # Collapse a <p> than contains only a protected span into a protected P 
     365# Collapse a <p> that contains only a protected span into a protected P 
    366366# Collapse em in em 
    367367# Collapse adjacent text nodes 
     
    444444} 
    445445 
     446# If this node has the specified class, insert a new "span" node with that 
     447# class between this node and all of this node's children. 
     448sub _moveClassToSpan 
     449{ 
     450    my $this = shift; 
     451    my $class = shift; 
     452 
     453    if ( $this->{tag} and  
     454         lc($this->{tag}) ne 'span' and 
     455         $this->_removeClass($class) ) { 
     456          
     457        my $newspan = new Foswiki::Plugins::WysiwygPlugin::HTML2TML::Node( $this->{context}, 'span', { class => $class } ); 
     458        my $kid = $this->{head}; 
     459        while ($kid) { 
     460            $newspan->addChild($kid); 
     461            $kid = $kid->{next}; 
     462        } 
     463        $this->{head} = $this->{tail} = $newspan; 
     464    } 
     465} 
     466 
    446467# the actual generate function. rootGenerate is only applied to the root node. 
    447468sub generate { 
     
    487508    $tag =~ s/!//;    # DOCTYPE 
    488509    my $tmlFn = '_handle' . uc($tag); 
     510 
     511    $this->_moveClassToSpan('WYSIWYG_TT'); 
    489512 
    490513    # See if we have a TML translation function for this tag 
     
    839862    while ($kid) { 
    840863        if ( $kid->{tag} eq 'th' ) { 
     864            $kid->_moveClassToSpan('WYSIWYG_TT'); 
    841865            ( $flags, $text ) = $kid->_flatten($options); 
    842866            $text = _TDtrim($text); 
     
    844868        } 
    845869        elsif ( $kid->{tag} eq 'td' ) { 
     870            $kid->_moveClassToSpan('WYSIWYG_TT'); 
    846871            ( $flags, $text ) = $kid->_flatten($options); 
    847872            $text = _TDtrim($text); 
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm

    r3396 r3875  
    470470      (CGI::span({class => 'WYSIWYG_TT'}, $1))gem; 
    471471 
    472     # Handle [[][] and [[]] links 
     472    # Handle [[][]] and [[]] links 
    473473 
    474474    # We _not_ support [[http://link text]] syntax 
  • trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm

    r3396 r3875  
    3939my $HTML2TML  = 1 << 1;    # test html => finaltml (default tml) 
    4040my $ROUNDTRIP = 1 << 2;    # test tml => => finaltml 
     41# Note: ROUNDTRIP is *not* the same as the combination of  
     42# HTML2TML and TML2HTML. The HTML and TML comparisons are both 
     43# somewhat "flexible". This is necessry because, for example, 
     44# the nature of whitespace in the TML may change. 
     45# ROUNDTRIP tests are intended to isolate gradual degradation  
     46# of the TML, where TML -> HTML -> not quite TML -> HTML 
     47# -> even worse TML, ad nauseum 
    4148 
    4249# Bit mask for selected test types 
     
    5562 
    5663# Each testcase is a subhash with fields as follows: 
    57 # exec => 1 to test TML -> HTML, 2 to test HTML -> TML, 3 to 
    58 # test both, anything else to skin the test. 
     64# exec => $TML2HTML to test TML -> HTML, $HTML2TML to test HTML -> TML,  
     65#   $ROUNDTRIP to test TML-> ->TML, all other bits are ignored. 
     66#   They may be OR'd togoether to perform multiple tests.  
     67#   For example: $TML2HTML | $HTML2TML to test both  
     68#   TML -> HTML and HTML -> TML 
    5969# name => identifier (used to compose the testcase function name) 
    6070# tml => source topic meta-language 
    61 # html => expected html from expanding tml 
     71# html => expected html from expanding tml (not used in roundtrip tests) 
    6272# finaltml => optional expected tml from translating html. If not there, 
    6373# will use tml. Only use where round-trip can't be closed because 
     
    152162    }, 
    153163    { 
     164        exec => $TML2HTML | $HTML2TML, 
     165        name => 'codeToFromHtml', 
     166        html => <<'BLAH', 
     167<p> 
     168<span class="WYSIWYG_TT">Code</span> 
     169</p> 
     170BLAH 
     171        tml  => '=Code=' 
     172    }, 
     173    { 
    154174        exec => $ROUNDTRIP, 
    155175        name => 'strongCode', 
    156176        html => '<b><code>Bold Code</code></b>', 
    157177        tml  => '==Bold Code==' 
     178    }, 
     179    { 
     180        exec => $TML2HTML |  $HTML2TML, 
     181        name => 'bToFromHtml', 
     182        html => '<p><b>Bold</b></p>', 
     183        tml  => '*Bold*' 
     184    }, 
     185    { 
     186        exec => $TML2HTML |  $HTML2TML, 
     187        name => 'strongCodeToFromHtml', 
     188        html => <<'BLAH', 
     189<p> 
     190<b><span class="WYSIWYG_TT">Code</span></b> 
     191</p> 
     192BLAH 
     193        tml  => '==Code==' 
     194    }, 
     195    { 
     196        exec => $HTML2TML, 
     197        name => 'spanWithTtClassWithStrong', 
     198        html => <<'BLAH', 
     199<p> 
     200<span class="WYSIWYG_TT"><strong>Code</strong></span> 
     201</p> 
     202BLAH 
     203        tml  => '==Code==' 
     204    }, 
     205    { 
     206        exec => $HTML2TML, 
     207        name => 'strongWithSpanWithTtClass', 
     208        html => <<'BLAH', 
     209<p> 
     210<strong><span class="WYSIWYG_TT">Code</span></strong> 
     211</p> 
     212BLAH 
     213        tml  => '==Code==' 
     214    }, 
     215    { 
     216        exec => $HTML2TML, 
     217        name => 'strongWithTtClass', 
     218        html => <<'BLAH', 
     219<p> 
     220<strong class="WYSIWYG_TT">Code</strong> 
     221</p> 
     222BLAH 
     223        tml  => '==Code==' 
     224    }, 
     225    { 
     226        exec => $HTML2TML, 
     227        name => 'bWithTtClass', 
     228        html => "<p>\n<b class=\"WYSIWYG_TT\">Code</b>\n</p>", 
     229        tml  => '==Code==' 
     230    }, 
     231    { 
     232        exec => $HTML2TML | $ROUNDTRIP, 
     233        name => 'ttClassInTable', 
     234        html => '<table><tr><td class="WYSIWYG_TT">Code</td></tr></table>', 
     235        tml  => '| =Code= |' 
    158236    }, 
    159237    { 
Note: See TracChangeset for help on using the changeset viewer.