- Timestamp:
- 04/10/09 10:37:08 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm
r2957 r3396 1281 1281 1282 1282 # Try to convert font tags into %COLOUR%..%ENDCOLOR% 1283 # First extract the colour 1283 1284 # First extract the colour from a style= param, if we can. 1284 1285 my $colour; 1285 if ( $atts{style} ) {1286 my $style = $atts{style};1287 if ( $style =~ s/(^|\s|;)color\s*:\s*([^\s;]+);?//i ){1288 $colour = $2;1289 delete $atts{style} if $style =~ /^[\s;]*$/;1290 } 1291 }1292 if ( $atts{color} ) {1286 if ( defined $atts{style} 1287 && $atts{style} =~ s/(^|\s|;)color\s*:\s*(#?\w+)\s*(;|$)// ) 1288 { 1289 $colour = $2; 1290 } 1291 1292 # override it with a color= param, if there is one. 1293 if ( defined $atts{color} ) { 1293 1294 $colour = $atts{color}; 1294 delete $atts{color}; 1295 } 1296 1297 # The presence of the class forces it to be converted to a 1298 # Foswiki variable 1299 if ( !_removeClass( \%atts, 'WYSIWYG_COLOUR' ) ) { 1300 delete $atts{class}; 1301 if ( scalar( keys %atts ) > 0 1302 || !$colour 1303 || $colour !~ /^([a-z]+|#[0-9A-Fa-f]{6})$/i ) 1304 { 1305 return ( 0, undef ); 1306 } 1307 } 1308 1309 # OK, just the colour 1310 $colour = $WC::KNOWN_COLOUR{ uc($colour) }; 1311 if ( !$colour ) { 1312 1313 # Not a recognised colour 1314 return ( 0, undef ); 1315 } 1316 my ( $f, $kids ) = $this->_flatten($options); 1317 return ( $f, '%' . uc($colour) . '%' . $kids . '%ENDCOLOR%' ); 1295 } 1296 1297 # The presence of the WYSIWYG_COLOR class _forces_ the tag to be 1298 # converted to a Foswiki colour macro, as long as the colour is 1299 # recognised. 1300 if ( hasClass( \%atts, 'WYSIWYG_COLOR' ) ) { 1301 my $percentColour = $WC::HTML2TML_COLOURMAP{ uc($colour) }; 1302 if ( defined $percentColour ) { 1303 1304 # All other font information will be lost. 1305 my ( $f, $kids ) = $this->_flatten($options); 1306 return ( $f, '%' . $percentColour . '%' . $kids . '%ENDCOLOR%' ); 1307 } 1308 } 1309 1310 # May still be able to convert if there is no other font information. 1311 delete $atts{class} if defined $atts{class} && $atts{class} =~ /^\s*$/; 1312 delete $atts{style} if defined $atts{style} && $atts{style} =~ /^[\s;]*$/; 1313 delete $atts{color} if defined $atts{color}; 1314 if ( defined $colour && !scalar keys %atts ) { 1315 my $percentColour = $WC::HTML2TML_COLOURMAP{ uc($colour) }; 1316 if ( defined $percentColour ) { 1317 my ( $f, $kids ) = $this->_flatten($options); 1318 return ( $f, '%' . $percentColour . '%' . $kids . '%ENDCOLOR%' ); 1319 } 1320 } 1321 1322 # Either the colour can't be mapped, or we can't do the conversion 1323 # without loss of information 1324 return ( 0, undef ); 1318 1325 } 1319 1326 … … 1456 1463 } 1457 1464 1458 # Remove all other classes 1459 delete $atts{class}; 1465 # If we have WYSIWYG_COLOR and the colour can be mapped, then convert 1466 # to a macro. 1467 if ( _removeClass( \%atts, 'WYSIWYG_COLOR' ) ) { 1468 my $colour; 1469 if ( $atts{style} ) { 1470 my $style = $atts{style}; 1471 if ( $style =~ s/(^|\s|;)color\s*:\s*(#?\w+)\s*(;|$)// ) { 1472 $colour = $2; 1473 } 1474 } 1475 my $percentColour = $WC::HTML2TML_COLOURMAP{ uc($colour) }; 1476 if ( defined $percentColour ) { 1477 my ( $f, $kids ) = $this->_flatten($options); 1478 return ( $f, '%' . $percentColour . '%' . $kids . '%ENDCOLOR%' ); 1479 } 1480 } 1481 1482 # Remove all other (non foswiki) classes 1483 if ( defined $atts{class} && $atts{class} !~ /foswiki/ ) { 1484 delete $atts{class}; 1485 } 1460 1486 1461 1487 if ( $options & $WC::VERY_CLEAN ) { 1462 1488 1463 # remove style attribute if cleaning aggressively. Have to do this 1464 # because Foswiki generates these. 1465 delete $atts{style} if defined $atts{style}; 1489 # remove style attribute if cleaning aggressively. 1490 # delete $atts{style} if defined $atts{style}; 1466 1491 } 1467 1492 … … 1495 1520 return ( 0, undef ) 1496 1521 unless $this->_isConvertableTable( $options | $WC::NO_BLOCK_TML, 1497 \@table );1522 \@table ); 1498 1523 1499 1524 my $maxrow = 0;
Note: See TracChangeset
for help on using the changeset viewer.
