Changeset 3986
- Timestamp:
- 05/27/09 19:54:07 (3 years ago)
- Location:
- trunk/WysiwygPlugin
- Files:
-
- 2 edited
-
lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm (modified) (4 diffs)
-
test/unit/WysiwygPlugin/TranslatorTests.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm
r3985 r3986 361 361 return $text; 362 362 } 363 363 364 # collapse adjacent nodes together, if they share the same class 364 sub _collapseOneClass 365 { 366 my $node = shift; 367 my $class = shift; 368 if ( defined( $node->{tag} ) && $node->hasClass($class) ) { 369 my $next = $node->{next}; 370 my @edible; 371 my $collapsible; 372 while ( 373 $next 374 && ( 375 ( !$next->{tag} && $next->{text} =~ /^\s*$/ ) 376 || ( $node->{tag} eq $next->{tag} 377 && $next->hasClass($class) ) 378 ) 379 ) 380 { 381 push( @edible, $next ); 382 $collapsible ||= $next->hasClass($class); 383 $next = $next->{next}; 384 } 385 if ($collapsible) { 386 foreach my $meal (@edible) { 387 $meal->_remove(); 388 if ( $meal->{tag} ) { 389 require Foswiki::Plugins::WysiwygPlugin::HTML2TML::Leaf; 390 $node->addChild( 391 new Foswiki::Plugins::WysiwygPlugin::HTML2TML::Leaf( 392 $WC::NBBR) 393 ); 394 $node->_eat($meal); 395 } 396 } 397 } 398 } 399 } 400 365 sub _collapseOneClass { 366 my $node = shift; 367 my $class = shift; 368 if ( defined( $node->{tag} ) && $node->hasClass($class) ) { 369 my $next = $node->{next}; 370 my @edible; 371 my $collapsible; 372 while ( 373 $next 374 && ( 375 ( !$next->{tag} && $next->{text} =~ /^\s*$/ ) 376 || ( $node->{tag} eq $next->{tag} 377 && $next->hasClass($class) ) 378 ) 379 ) 380 { 381 push( @edible, $next ); 382 $collapsible ||= $next->hasClass($class); 383 $next = $next->{next}; 384 } 385 if ($collapsible) { 386 foreach my $meal (@edible) { 387 $meal->_remove(); 388 if ( $meal->{tag} ) { 389 require Foswiki::Plugins::WysiwygPlugin::HTML2TML::Leaf; 390 $node->addChild( 391 new Foswiki::Plugins::WysiwygPlugin::HTML2TML::Leaf( 392 $WC::NBBR) 393 ); 394 $node->_eat($meal); 395 } 396 } 397 } 398 } 399 } 401 400 402 401 # Collapse adjacent VERBATIM nodes together … … 411 410 while ( scalar(@jobs) ) { 412 411 my $node = shift(@jobs); 413 _collapseOneClass($node, 'TMLverbatim');414 _collapseOneClass($node, 'WYSIWYG_STICKY');412 _collapseOneClass( $node, 'TMLverbatim' ); 413 _collapseOneClass( $node, 'WYSIWYG_STICKY' ); 415 414 if ( $node->{tag} eq 'p' 416 415 && $node->{head} … … 418 417 { 419 418 my $kid = $node->{head}; 420 if ( uc($kid->{tag}) eq 'SPAN'419 if ( uc( $kid->{tag} ) eq 'SPAN' 421 420 && $kid->hasClass('WYSIWYG_PROTECTED') ) 422 421 { … … 465 464 { 466 465 467 my %new_attrs = ( class => $class );466 my %new_attrs = ( class => $class ); 468 467 $new_attrs{style} = $this->{attrs}->{style} 469 468 if exists $this->{attrs}->{style}; -
trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm
r3985 r3986 232 232 </p> 233 233 BLAH 234 tml => '*%RED% =Code= %ENDCOLOR%*'234 tml => '*%RED% =Code= %ENDCOLOR%*' 235 235 }, 236 236 { … … 876 876 </verbatim> Outside', 877 877 }, 878 {879 exec => $TML2HTML | $ROUNDTRIP,880 name => 'verbatimWithNbsp1554',881 html => '<p><pre class="TMLverbatim">&nbsp;</pre></p>',882 tml=> "<verbatim> </verbatim>"883 },878 { 879 exec => $TML2HTML | $ROUNDTRIP, 880 name => 'verbatimWithNbsp1554', 881 html => '<p><pre class="TMLverbatim">&nbsp;</pre></p>', 882 tml => "<verbatim> </verbatim>" 883 }, 884 884 { 885 885 exec => $TML2HTML | $ROUNDTRIP, … … 1613 1613 ' 1614 1614 }, 1615 {1616 exec => $HTML2TML,1617 name => 'mergeStickyItem1667',1618 html => <<'BLAH',1615 { 1616 exec => $HTML2TML, 1617 name => 'mergeStickyItem1667', 1618 html => <<'BLAH', 1619 1619 <div class="WYSIWYG_STICKY">Line 1</div> 1620 1620 <div class="WYSIWYG_STICKY">Line 2</div> 1621 1621 BLAH 1622 tml => "<sticky>Line 1\nLine 2</sticky>"1623 },1624 {1625 exec => $HTML2TML | $ROUNDTRIP,1626 name => 'separateStickyRegions',1627 html => <<'BLAH',1622 tml => "<sticky>Line 1\nLine 2</sticky>" 1623 }, 1624 { 1625 exec => $HTML2TML | $ROUNDTRIP, 1626 name => 'separateStickyRegions', 1627 html => <<'BLAH', 1628 1628 <div class="WYSIWYG_STICKY">Oranges</div> 1629 1629 <p></p> 1630 1630 <div class="WYSIWYG_STICKY">Apples</div> 1631 1631 BLAH 1632 tml => "<sticky>Oranges</sticky>\n\n<sticky>Apples</sticky>"1633 },1632 tml => "<sticky>Oranges</sticky>\n\n<sticky>Apples</sticky>" 1633 }, 1634 1634 { 1635 1635 exec => $TML2HTML, … … 1756 1756 </table> 1757 1757 BLAH 1758 tml => <<'BLAH',1758 tml => <<'BLAH', 1759 1759 | *%RED%Red Heading%ENDCOLOR%* | 1760 1760 | %RED%Red herring%ENDCOLOR% | … … 1770 1770 </table> 1771 1771 BLAH 1772 tml => <<'BLAH',1772 tml => <<'BLAH', 1773 1773 | *%RED% =Redder code= %ENDCOLOR%* | 1774 1774 | %RED% =Red code= %ENDCOLOR% |
Note: See TracChangeset
for help on using the changeset viewer.
