From: Kenneth L. <ke...@la...> - 2007-09-29 11:27:27
|
Please merge this to TWikiRelease04x02 so we can test it. At least I ONLY test the 4.2 code now. Kenneth de...@de... wrote: > Author: CrawfordCurrie > Date: 2007-09-29 04:11:38 -0500 (Sat, 29 Sep 2007) > New Revision: 15087 > > Modified: > twiki/branches/MAIN/twikiplugins/WysiwygPlugin/data/TWiki/WysiwygPlugin.txt > twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm > twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/WC.pm > twiki/branches/MAIN/twikiplugins/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm > Log: > Item4706: merge adjacent verbatim blocks separated only by whitespace > > Modified: twiki/branches/MAIN/twikiplugins/WysiwygPlugin/data/TWiki/WysiwygPlugin.txt > =================================================================== > --- twiki/branches/MAIN/twikiplugins/WysiwygPlugin/data/TWiki/WysiwygPlugin.txt 2007-09-28 21:13:25 UTC (rev 15086) > +++ twiki/branches/MAIN/twikiplugins/WysiwygPlugin/data/TWiki/WysiwygPlugin.txt 2007-09-29 09:11:38 UTC (rev 15087) > @@ -165,7 +165,7 @@ > | License | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] | > | Plugin Version: | %$VERSION% | > | Change History: | | > -| | Bugs:Item4700: fixed colspans Bugs:Item4712: fixed eating of noautolink and literal | > +| | Bugs:Item4700: fixed colspans Bugs:Item4706: merge adjacent verbatim blocks separated only by whitespace Bugs:Item4712: fixed eating of noautolink and literal | > | 17 Sep 2007 | Bugs:Item4647: Bugs:Item4652: problems related to DIV fixed. Bugs:Item4653: fixed multi-line twiki variables | > | 16 Sep 2007 | Bugs:Item4630: polished up the way the secret string is done, to ensure synch between perl and JS. Item4622: added UTF-8 handling steps that fixup malformed UTF8 strings before presenting them to the editor (saves Moz) and stops the editor passing them back to TWiki (saves IE). Removed extra entity decoding steps that were causing problems. Bugs:Item4629: fixed issues with verbatim, highlighted by previous mangling of this topic | > | 13 Sep 2007 | Bugs:Item4613 cleaned up spurious message when navigating away Bugs:Item4615 fixed incorrect rendering of emphasis next to br | > > Modified: twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm > =================================================================== > --- twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm 2007-09-28 21:13:25 UTC (rev 15086) > +++ twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm 2007-09-29 09:11:38 UTC (rev 15087) > @@ -65,7 +65,7 @@ > $this->{attrs}->{$attr} = $attrs->{$attr}; > } > } > - $this->{children} = []; > + $this->{head} = $this->{tail} = undef; > > return bless( $this, $class ); > } > @@ -84,8 +84,10 @@ > if( $shallow ) { > $r .= '...'; > } else { > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > $r .= $kid->stringify(); > + $kid = $kid->{next}; > } > } > if( $this->{tag} ) { > @@ -107,7 +109,17 @@ > > ASSERT($node != $this) if DEBUG; > > - push( @{$this->{children}}, $node ); > + $node->{next} = undef; > + $node->{parent} = $this; > + my $kid = $this->{tail}; > + if ($kid) { > + $kid->{next} = $node; > + $node->{prev} = $kid; > + } else { > + $node->{prev} = undef; > + $this->{head} = $node; > + } > + $this->{tail} = $node; > } > > # top and tail a string > @@ -119,7 +131,7 @@ > return $s; > } > > -sub _hasClass { > +sub hasClass { > my ($attrs, $class) = @_; > return 0 unless $attrs && defined $attrs->{class}; > return $attrs->{class} =~ /\b$class\b/ ? 1 : 0; > @@ -127,7 +139,7 @@ > > sub _removeClass { > my ($attrs, $class) = @_; > - return 0 unless _hasClass($attrs, $class); > + return 0 unless hasClass($attrs, $class); > $attrs->{class} =~ s/\b$class\b//; > $attrs->{class} =~ s/\s+/ /g; > $attrs->{class} =~ s/^\s+//; > @@ -169,6 +181,8 @@ > > $this->cleanParseTree(); > > + $this->_collapseVerbatim(); > + > my( $f, $text ) = $this->generate($opts); > > # Debug support > @@ -271,6 +285,65 @@ > return $text; > } > > +# Collapse adjacent VERBATIM nodes together > +sub _collapseVerbatim { > + my $this = shift; > + > + my @jobs = ( $this ); > + while (scalar(@jobs)) { > + my $node = shift(@jobs); > + if (defined($node->{tag}) && hasClass($node->{attrs}, 'TMLverbatim')) { > + my $next = $node->{next}; > + my @edible; > + my $collapsible; > + while ($next && > + ((!$next->{tag} && $next->{text} =~ /^\s*$/) || > + ($node->{tag} eq $next->{tag} && > + hasClass($next->{attrs}, 'TMLverbatim')))) { > + push(@edible, $next); > + $collapsible ||= hasClass($next->{attrs}, 'TMLverbatim'); > + $next = $next->{next}; > + } > + if ($collapsible) { > + foreach my $meal (@edible) { > + $meal->_remove(); > + if ($meal->{tag}) { > + require TWiki::Plugins::WysiwygPlugin::HTML2TML::Leaf; > + $node->addChild(new TWiki::Plugins::WysiwygPlugin::HTML2TML::Leaf($WC::NBBR)); > + $node->_eat($meal); > + } > + } > + } > + } > + my $kid = $node->{head}; > + while ($kid) { > + push(@jobs, $kid); > + $kid = $kid->{next}; > + } > + } > +} > + > +# Move the content of $node into $this > +sub _eat { > + my ($this, $node) = @_; > + my $kid = $this->{tail}; > + if ($kid) { > + $kid->{next} = $node->{head}; > + if ($node->{head}) { > + $node->{head}->{prev} = $kid; > + } > + } else { > + $this->{head} = $node->{head}; > + } > + $this->{tail} = $node->{tail}; > + $kid = $node->{head}; > + while ($kid) { > + $kid->{parent} = $node->{parent}; > + $kid = $kid->{next}; > + } > + $node->{head} = $node->{tail} = undef; > +} > + > # the actual generate function. rootGenerate is only applied to the root node. > sub generate { > my( $this, $options ) = @_; > @@ -280,11 +353,13 @@ > > my $tag = uc( $this->{tag} ); > > - if (_hasClass($this->{attrs}, 'WYSIWYG_LITERAL')) { > + if (hasClass($this->{attrs}, 'WYSIWYG_LITERAL')) { > if ($tag eq 'DIV' || $tag eq 'P') { > $text = ''; > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > $text .= $kid->stringify(); > + $kid = $kid->{next}; > } > } else { > _removeClass($this->{attrs}, 'WYSIWYG_LITERAL'); > @@ -334,7 +409,7 @@ > my $flags = 0; > > my $protected = ($options & $WC::PROTECTED) || > - _hasClass($this->{attrs}, 'WYSIWYG_PROTECTED') || 0; > + hasClass($this->{attrs}, 'WYSIWYG_PROTECTED') || 0; > > if ($protected) { > # Expand brs, which are used in the protected encoding in place of > @@ -342,7 +417,8 @@ > $options |= $WC::BR2NL | $WC::KEEP_WS; > } > > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > my( $f, $t ) = $kid->generate( $options ); > if (!($options & $WC::KEEP_WS) > && $text && $text =~ /\w$/ && $t =~ /^\w/) { > @@ -352,6 +428,7 @@ > } > $text .= $t; > $flags |= $f; > + $kid = $kid->{next}; > } > if ($protected) { > $text =~ s/[$WC::PON$WC::POFF]//g; > @@ -428,13 +505,18 @@ > my $f; > my $text = ''; > my $pendingDT = 0; > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > # be tolerant of dl, ol and ul with no li > if( $kid->{tag} =~ m/^[dou]l$/i ) { > $text .= $kid->_convertList( $indent.$WC::TAB ); > + $kid = $kid->{next}; > next; > } > - next unless $kid->{tag} =~ m/^(dt|dd|li)$/i; > + unless ($kid->{tag} =~ m/^(dt|dd|li)$/i) { > + $kid = $kid->{next}; > + next; > + } > if( $isdl && ( lc( $kid->{tag} ) eq 'dt' )) { > # DT, set the bullet type for subsequent DT > $basebullet = $kid->_flatten( $WC::NO_BLOCK_TML ); > @@ -444,6 +526,7 @@ > $basebullet =~ s/^\s+//; > $basebullet = '$ '.$basebullet; > $pendingDT = 1; # remember in case there is no DD > + $kid = $kid->{next}; > next; > } > my $bullet = $basebullet; > @@ -451,7 +534,8 @@ > $bullet = $kid->{attrs}->{type}.'.'; > } > my $spawn = ''; > - foreach my $grandkid ( @{$kid->{children}} ) { > + my $grandkid = $kid->{head}; > + while ($grandkid) { > my $t; > if( $grandkid->{tag} =~ /^[dou]l$/i ) { > #$spawn = _trim( $spawn ); > @@ -461,11 +545,13 @@ > $t =~ s/$WC::CHECKn/ /g; > } > $spawn .= $t; > + $grandkid = $grandkid->{next}; > } > #$spawn = _trim($spawn); > $text .= $WC::CHECKn.$indent.$bullet.$WC::CHECKs.$spawn.$WC::CHECKn; > $pendingDT = 0; > $basebullet = '' if $isdl; > + $kid = $kid->{next}; > } > if( $pendingDT ) { > # DT with no corresponding DD > @@ -479,18 +565,19 @@ > sub _isConvertableList { > my( $this, $options ) = @_; > > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > # check for malformed list. We can still handle it, > # by simply ignoring illegal text. > # be tolerant of dl, ol and ul with no li > if( $kid->{tag} =~ m/^[dou]l$/i ) { > return 0 unless $kid->_isConvertableList( $options ); > - next; > + } elsif( $kid->{tag} =~ m/^(dt|dd|li)$/i ) { > + unless( $kid->_isConvertableListItem( $options, $this )) { > + return 0; > + } > } > - next unless( $kid->{tag} =~ m/^(dt|dd|li)$/i ); > - unless( $kid->_isConvertableListItem( $options, $this )) { > - return 0; > - } > + $kid = $kid->{next}; > } > return 1; > } > @@ -507,7 +594,8 @@ > return 0 unless( lc( $this->{tag} ) eq 'li' ); > } > > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > if( $kid->{tag} =~ /^[oud]l$/i ) { > unless( $kid->_isConvertableList( $options )) { > return 0; > @@ -518,6 +606,7 @@ > return 0; > } > } > + $kid = $kid->{next}; > } > return 1; > } > @@ -526,18 +615,17 @@ > # can be converted to TML. > sub _isConvertableTable { > my( $this, $options, $table ) = @_; > - my @process = ( @{$this->{children}} ); > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > if( $kid->{tag} =~ /^(colgroup|thead|tbody|tfoot|col)$/i ) { > return 0 unless( $kid->_isConvertableTable( $options, $table )); > - } elsif( !$kid->{tag} ) { > - next; > - } else { > + } elsif( $kid->{tag} ) { > return 0 unless( lc( $kid->{tag} ) eq 'tr' ); > my $row = $kid->_isConvertableTableRow( $options ); > return 0 unless $row; > push( @$table, $row ); > } > + $kid = $kid->{next}; > } > return 1; > } > @@ -560,7 +648,8 @@ > > my @row; > my $ignoreCols = 0; > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > if (lc($kid->{tag}) eq 'th') { > ( $flags, $text ) = $kid->_flatten( $options ); > $text = _TDtrim( $text ); > @@ -569,6 +658,7 @@ > ( $flags, $text ) = $kid->_flatten( $options ); > $text = _TDtrim( $text ); > } elsif( !$kid->{tag} ) { > + $kid = $kid->{next}; > next; > } else { > # some other sort of (unexpected) tag > @@ -609,6 +699,7 @@ > push( @row, '' ); > $ignoreCols--; > } > + $kid = $kid->{next}; > } > return \@row; > } > @@ -624,7 +715,7 @@ > $td->{attrs}->{style} =~ /text-align\s*:\s*(left|right|center)/ ) { > return $1; > } > - if (_hasClass($td->{attrs}, qr/align-(left|right|center)/)) { > + if (hasClass($td->{attrs}, qr/align-(left|right|center)/)) { > return $1; > } > } > @@ -637,7 +728,7 @@ > my( $flags, $contents ) = $this->_flatten( $options ); > return ( 0, undef ) if( $flags & $WC::BLOCK_TML ); > my $notoc = ''; > - if(_hasClass($this->{attrs}, 'notoc')) { > + if(hasClass($this->{attrs}, 'notoc')) { > $notoc = '!!'; > } > $contents =~ s/^\s+/ /; > @@ -953,7 +1044,7 @@ > sub _handleP { > my( $this, $options ) = @_; > > - if (_hasClass($this->{attrs}, 'TMLverbatim')) { > + if (hasClass($this->{attrs}, 'TMLverbatim')) { > return $this->_verbatim($options); > } > > @@ -972,7 +1063,7 @@ > my( $this, $options ) = @_; > > my $tag = 'pre'; > - if( _hasClass($this->{attrs}, 'TMLverbatim')) { > + if( hasClass($this->{attrs}, 'TMLverbatim')) { > return $this->_verbatim($options); > } > unless( $options & $WC::NO_BLOCK_TML ) { > > Modified: twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/WC.pm > =================================================================== > --- twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/WC.pm 2007-09-28 21:13:25 UTC (rev 15086) > +++ twiki/branches/MAIN/twikiplugins/WysiwygPlugin/lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/WC.pm 2007-09-29 09:11:38 UTC (rev 15087) > @@ -162,35 +162,58 @@ > sub cleanNode { > } > > +sub hasClass { > + return 0; > +} > + > sub cleanParseTree { > my( $this, $opts ) = @_; > > - $this->cleanNode($opts); > + my @jobs = ( $this ); > > - # thread siblings and parents > - my $prev; > - foreach my $kid (@{$this->{children}}) { > - $kid->{parent} = $this; > - $kid->{prev} = $prev; > - $prev->{next} = $kid if $prev; > - $kid->cleanParseTree($opts); > - $prev = $kid; > + while (scalar(@jobs)) { > + my $node = shift(@jobs); > + $node->cleanNode($opts); > + > + my $prev; > + my $kid = $node->{head}; > + while ($kid) { > + push(@jobs, $kid); > + $kid = $kid->{next}; > + } > } > - return ($this->{children}->[0], $this->{children}->[0]); > + return ($this->{head}, $this->{head}); > } > > sub stringify { > return ''; > } > > +sub _remove { > + my ($this) = @_; > + if ($this->{prev}) { > + $this->{prev}->{next} = $this->{next}; > + } else { > + $this->{parent}->{head} = $this->{next}; > + } > + if ($this->{next}) { > + $this->{next}->{prev} = $this->{prev}; > + } else { > + $this->{parent}->{tail} = $this->{prev}; > + } > + $this->{parent} = $this->{prev} = $this->{next} = undef; > +} > + > # Determine if the node - and all it's child nodes - satisfy the criteria > # for an HTML inline element. > sub isInline { > # This impl is actually for Nodes; Leaf overrides it > my $this = shift; > return 0 if $isOnlyBlockType{uc($this->{tag})}; > - foreach my $kid ( @{$this->{children}} ) { > + my $kid = $this->{head}; > + while ($kid) { > return 0 unless $kid->isInline(); > + $kid = $kid->{next}; > } > return 1; > } > @@ -199,20 +222,16 @@ > # This impl is actually for Nodes; Leaf overrides it > my $this = shift; > return 0 if $isOnlyBlockType{uc($this->{tag})}; > - if (scalar(@{$this->{children}})) { > - my $kid = $this->{children}->[0]; > - return 0 unless $kid->isInline(); > - } > + return 1 unless ($this->{head}); > + return 0 unless $this->{head}->isInline(); > return 1; > } > > sub isRightInline { > my $this = shift; > return 0 if $isOnlyBlockType{uc($this->{tag})}; > - if (scalar(@{$this->{children}})) { > - my $kid = $this->{children}->[$#{$this->{children}}]; > - return 0 unless $kid->isInline(); > - } > + return 1 unless $this->{tail}; > + return 0 unless $this->{tail}->isInline(); > return 1; > } > > > Modified: twiki/branches/MAIN/twikiplugins/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm > =================================================================== > --- twiki/branches/MAIN/twikiplugins/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm 2007-09-28 21:13:25 UTC (rev 15086) > +++ twiki/branches/MAIN/twikiplugins/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm 2007-09-29 09:11:38 UTC (rev 15087) > @@ -1330,6 +1330,18 @@ > </table> > HEXPT > }, > + { > + exec => $HTML2TML | $ROUNDTRIP, > + name => 'collapse', > + html => <<COLLAPSE, > +blah<pre class="TMLverbatim">flub</pre> <pre class="TMLverbatim">wheep</pre> <pre class="TMLverbatim">spit</pre>blah > +COLLAPSE > + tml => <<ESPALLOC, > +blah<verbatim>flub > +wheep > +spit</verbatim>blah > +ESPALLOC > + }, > ]; > > sub gen_compare_tests { > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > TWiki-Dev mailing list > TWi...@li... > https://lists.sourceforge.net/lists/listinfo/twiki-dev > > > |