Ignore:
Timestamp:
11/18/09 06:27:14 (3 years ago)
Author:
MichaelTempest
Message:

Item2369: Add rowspan support to the WYSIWYG editor
This also fixed a bug in how Web.WikiWord links are rendered, if the link is the only text in the table cell.

Tables are no longer "normalised" when converting from HTML to TML by appending |'s so that every row has the same number of |'s. The logic to do so when supporting rowspans is complex (read: likely to be buggy) and the "normalisation" feature is seldom used (it only had any effect if the HTML has a table with a hole in it.) Taking out the normalisation does not result in loss of content.

File:
1 edited

Legend:

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

    r3986 r5573  
    823823} 
    824824 
    825 # probe down into a list type to determine if it 
     825# probe down into a table to determine if it 
    826826# can be converted to TML. 
    827827sub _isConvertableTable { 
     
    831831        return 0; 
    832832    } 
     833 
     834    my $rowspan = undef; 
     835    $rowspan    = [] if Foswiki::Func::getContext()->{'TablePluginEnabled'}; 
    833836 
    834837    my $kid = $this->{head}; 
     
    843846                return 0; 
    844847            } 
    845             my $row = $kid->_isConvertableTableRow($options); 
     848            my $row = $kid->_isConvertableTableRow( $options, $rowspan ); 
    846849            unless ($row) { 
    847850                return 0; 
     
    850853        } 
    851854        $kid = $kid->{next}; 
     855    } 
     856 
     857    if ( $rowspan and grep { $_ } @$rowspan ) { 
     858 
     859        # One or more cells span rows past the last row in the table. 
     860        # This is a defect in the HTML table which TML cannot represent. 
     861        return 0; 
    852862    } 
    853863    return 1; 
     
    865875} 
    866876 
    867 # probe down into a list item to determine if the 
     877# probe down into a table row to determine if the 
    868878# containing table can be converted to TML. 
    869879sub _isConvertableTableRow { 
    870     my ( $this, $options ) = @_; 
     880    my ( $this, $options, $rowspan ) = @_; 
    871881 
    872882    return 0 if ( $this->_isProtectedByAttrs() ); 
     
    876886    my $ignoreCols = 0; 
    877887    my $kid        = $this->{head}; 
     888    my $colIdx     = 0; 
     889    while ( $rowspan and $rowspan->[$colIdx] ) { 
     890        push @row, $WC::NBSP . '^' . $WC::NBSP; 
     891        $rowspan->[$colIdx]--; 
     892        $colIdx++; 
     893    } 
    878894    while ($kid) { 
    879895        if ( $kid->{tag} eq 'th' ) { 
     
    913929            } 
    914930            if ( $kid->{attrs}->{rowspan} && $kid->{attrs}->{rowspan} > 1 ) { 
    915                 return 0; 
     931                return 0 unless $rowspan; 
     932                $rowspan->[$colIdx] = $kid->{attrs}->{rowspan} - 1; 
    916933            } 
    917934        } 
     
    937954        # Pad to allow wikiwords to work 
    938955        push( @row, $text ); 
     956        $colIdx++; 
    939957        while ( $ignoreCols > 1 ) { 
     958            if ( $rowspan and $rowspan->[$colIdx] ) { 
     959 
     960                # rowspan and colspan into the same cell 
     961                return 0; 
     962            } 
    940963            push( @row, '' ); 
    941964            $ignoreCols--; 
     965            $colIdx++; 
     966        } 
     967        while ( $rowspan and $rowspan->[$colIdx] ) { 
     968            push @row, $WC::NBSP . '^' . $WC::NBSP; 
     969            $rowspan->[$colIdx]--; 
     970            $colIdx++; 
    942971        } 
    943972        $kid = $kid->{next}; 
     
    15651594        \@table ); 
    15661595 
    1567     my $maxrow = 0; 
    1568     my $row; 
    1569     foreach $row (@table) { 
    1570         my $rw = scalar(@$row); 
    1571         $maxrow = $rw if ( $rw > $maxrow ); 
    1572     } 
    1573     foreach $row (@table) { 
    1574         while ( scalar(@$row) < $maxrow ) { 
    1575             push( @$row, '' ); 
    1576         } 
    1577     } 
    15781596    my $text = $WC::CHECKn; 
    1579     foreach $row (@table) { 
     1597    foreach my $row (@table) { 
    15801598 
    15811599        # isConvertableTableRow has already formatted the cell 
Note: See TracChangeset for help on using the changeset viewer.