Skip to content
Permalink
Browse files

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. 


git-svn-id: http://svn.foswiki.org/trunk@5573 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information...
MichaelTempest MichaelTempest
MichaelTempest authored and MichaelTempest committed Nov 18, 2009
1 parent 401136a commit d57d8e71b961cee29a96c8721f4f64cc39437a95
@@ -140,7 +140,7 @@ Plugins that extend the syntax using macros, such as =%MYMACRO%=, should work fi
*Implementors note* plugins that use XML-like tags may call [[%SCRIPTURLPATH{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::Plugins::WysiwygPlugin][Foswiki::Plugins::WysiwygPlugin::addXMLTag()]] from their =initPlugin= handlers to make WysiwygPlugin protect the content between XML-like tags, just like it does for macros.

---+++ Overlapping styles
Because Foswiki uses a "best guess" approach to some formatting, it allows overlapping of tags in a way forbidden by HTML, and it is impossible to guarantee 100% that formating in the original Foswiki document will still be there when the same document is loaded and then saved through the WysiwygPlugin. The most obvious case of this is to do with styles. For example, the sentence
Because Foswiki uses a "best guess" approach to some formatting, it allows overlapping of tags in a way forbidden by HTML, and it is impossible to guarantee 100% that formatting in the original Foswiki document will still be there when the same document is loaded and then saved through the WysiwygPlugin. The most obvious case of this is to do with styles. For example, the sentence
<verbatim>
*bold _bold-italic* italic_
</verbatim>
@@ -154,6 +154,12 @@ which gets translated back to TML as
</verbatim>
which is correct by construction, but does not render correctly in Foswiki. This problem is unfortunately unavoidable due to the way TML works.

---+++ Rowspan processing needs %SYSTEMWEB%.TablePlugin

WysiwygPlugin is able to convert tables with cells that span rows into TML. This requires syntax provided by the %SYSTEMWEB%.TablePlugin (that is, the =| ^ |= markup). WysiwygPlugin will therefore only perform row-span related conversion if %SYSTEMWEB%.TablePlugin is enabled. %SYSTEMWEB%.TablePlugin is enabled by default and hence WysiwygPlugin converts tables with cells that span rows between TML and HTML by default.

If %SYSTEMWEB%.TablePlugin is *not* enabled, then TML table cells containing only =^= are not converted to rowspans, and HTML tables containing rowspans are not converted to TML.

---++ Plugin Info

This plugin is brought to you by a [[http://wikiring.com][WikiRing <a href="http://wikiring.com"><img src="%ATTACHURLPATH%/wikiringlogo20x20.png" title="WikiRing: Professional Wiki Innovation and Support" /></a>]] partner - working together to improve your wiki experience!
@@ -169,6 +175,7 @@ Many thanks to the following sponsors for supporting this work:
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | |
| 18 Nov 2009 | Foswikitask:Item2369: Convert tables with cells that span rows |
| 22 Oct 2009 | Foswikitask:Item2183: Protect div style= by default |
| 18 Sep 2009 | Foswikitask:Item1980: Prevent dataloss when saving a topic in Wysiwyg where there are a pair of sticky tags inside verbatim tags |
| 28 Jun 2009 | Foswikitask:Item1770: Protect XML tags registered by plugins, and not just the content between them (Michael Tempest) |
@@ -822,7 +822,7 @@ sub _isConvertableListItem {
return 1;
}

# probe down into a list type to determine if it
# probe down into a table to determine if it
# can be converted to TML.
sub _isConvertableTable {
my ( $this, $options, $table ) = @_;
@@ -831,6 +831,9 @@ sub _isConvertableTable {
return 0;
}

my $rowspan = undef;
$rowspan = [] if Foswiki::Func::getContext()->{'TablePluginEnabled'};

my $kid = $this->{head};
while ($kid) {
if ( $kid->{tag} =~ /^(colgroup|thead|tbody|tfoot|col)$/ ) {
@@ -842,14 +845,21 @@ sub _isConvertableTable {
unless ( $kid->{tag} eq 'tr' ) {
return 0;
}
my $row = $kid->_isConvertableTableRow($options);
my $row = $kid->_isConvertableTableRow( $options, $rowspan );
unless ($row) {
return 0;
}
push( @$table, $row );
}
$kid = $kid->{next};
}

if ( $rowspan and grep { $_ } @$rowspan ) {

# One or more cells span rows past the last row in the table.
# This is a defect in the HTML table which TML cannot represent.
return 0;
}
return 1;
}

@@ -864,17 +874,23 @@ s/(<br \/>|<br>|$WC::NBSP|$WC::NBBR|$WC::CHECKn|$WC::CHECKs|$WC::CHECKw|$WC::CHE
return $td;
}

# probe down into a list item to determine if the
# probe down into a table row to determine if the
# containing table can be converted to TML.
sub _isConvertableTableRow {
my ( $this, $options ) = @_;
my ( $this, $options, $rowspan ) = @_;

return 0 if ( $this->_isProtectedByAttrs() );

my ( $flags, $text );
my @row;
my $ignoreCols = 0;
my $kid = $this->{head};
my $colIdx = 0;
while ( $rowspan and $rowspan->[$colIdx] ) {
push @row, $WC::NBSP . '^' . $WC::NBSP;
$rowspan->[$colIdx]--;
$colIdx++;
}
while ($kid) {
if ( $kid->{tag} eq 'th' ) {
$kid->_moveClassToSpan('WYSIWYG_TT');
@@ -912,7 +928,8 @@ sub _isConvertableTableRow {
$text .= $WC::NBSP;
}
if ( $kid->{attrs}->{rowspan} && $kid->{attrs}->{rowspan} > 1 ) {
return 0;
return 0 unless $rowspan;
$rowspan->[$colIdx] = $kid->{attrs}->{rowspan} - 1;
}
}
$text =~ s/&nbsp;/$WC::NBSP/g;
@@ -936,9 +953,21 @@ sub _isConvertableTableRow {

# Pad to allow wikiwords to work
push( @row, $text );
$colIdx++;
while ( $ignoreCols > 1 ) {
if ( $rowspan and $rowspan->[$colIdx] ) {

# rowspan and colspan into the same cell
return 0;
}
push( @row, '' );
$ignoreCols--;
$colIdx++;
}
while ( $rowspan and $rowspan->[$colIdx] ) {
push @row, $WC::NBSP . '^' . $WC::NBSP;
$rowspan->[$colIdx]--;
$colIdx++;
}
$kid = $kid->{next};
}
@@ -1564,19 +1593,8 @@ sub _handleTABLE {
unless $this->_isConvertableTable( $options | $WC::NO_BLOCK_TML,
\@table );

my $maxrow = 0;
my $row;
foreach $row (@table) {
my $rw = scalar(@$row);
$maxrow = $rw if ( $rw > $maxrow );
}
foreach $row (@table) {
while ( scalar(@$row) < $maxrow ) {
push( @$row, '' );
}
}
my $text = $WC::CHECKn;
foreach $row (@table) {
foreach my $row (@table) {

# isConvertableTableRow has already formatted the cell
$text .= $WC::CHECKn . '|' . join( '|', @$row ) . '|' . $WC::CHECKn;

0 comments on commit d57d8e7

Please sign in to comment.
You can’t perform that action at this time.