Changeset 3396
- Timestamp:
- 04/10/09 10:37:08 (3 years ago)
- Location:
- trunk/WysiwygPlugin
- Files:
-
- 6 edited
-
data/System/WysiwygPlugin.txt (modified) (1 diff)
-
lib/Foswiki/Plugins/WysiwygPlugin/Constants.pm (modified) (5 diffs)
-
lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm (modified) (3 diffs)
-
lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm (modified) (2 diffs)
-
test/unit/WysiwygPlugin/TranslatorTests.pm (modified) (1 diff)
-
test/unit/WysiwygPlugin/WysiwygPluginTests.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WysiwygPlugin/data/System/WysiwygPlugin.txt
r3047 r3396 166 166 | Plugin Version: | %$VERSION% | 167 167 | Change History: | | 168 | 10 Apr 2009 | Foswikitask:Item1394: fixed colour handling | 168 169 | 03 Dec 2008 | Foswikitask:Item6041: fixed empty bullet list problem. Foswiki version | 169 170 | 22 Oct 2008 | Fixed TWikibug:Item5961 (emphasis), TWikibug:Item6089 (backslash in verbatim) | -
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/Constants.pm
r2957 r3396 4 4 5 5 use strict; 6 7 our ( %ALWAYS_BLOCK, $ALWAYS_BLOCK_S, $STARTWW, $ENDWW, $PROTOCOL );8 6 9 7 # HTML elements that are strictly block type, as defined by … … 11 9 # Block type elements do not require 12 10 # <br /> to be generated for newlines on the boundary - see WC::isInline. 13 %ALWAYS_BLOCK = map { $_ => 1 }11 our %ALWAYS_BLOCK = map { $_ => 1 } 14 12 qw( ADDRESS BLOCKQUOTE CENTER DIR DIV DL FIELDSET FORM H1 H2 H3 H4 H5 H6 15 13 HR ISINDEX MENU NOFRAMES NOSCRIPT OL P PRE TABLE UL ); 16 $ALWAYS_BLOCK_S = join( '|', keys %ALWAYS_BLOCK ); 17 18 $STARTWW = qr/^|(?<=[ \t\n\(\!])/om; 19 $ENDWW = qr/$|(?=[ \t\n\,\.\;\:\!\?\)])/om; 20 $PROTOCOL = qr/^(file|ftp|gopher|https?|irc|news|nntp|telnet|mailto):/; 21 22 our (%KNOWN_COLOUR); 23 24 # Colours with colour settings in DefaultPreferences. WTF does Foswiki see 25 # fit to *redefine* the standard colors? e.g. ORANGE below is *not* orange. 26 # For goodness sakes! 27 %KNOWN_COLOUR = ( 14 our $ALWAYS_BLOCK_S = join( '|', keys %ALWAYS_BLOCK ); 15 16 our $STARTWW = qr/^|(?<=[ \t\n\(\!])/om; 17 our $ENDWW = qr/$|(?=[ \t\n\,\.\;\:\!\?\)])/om; 18 our $PROTOCOL = qr/^(file|ftp|gopher|https?|irc|news|nntp|telnet|mailto):/; 19 20 # Colours with colour settings in DefaultPreferences. 21 our @TML_COLOURS = ( 22 'BLACK', 'MAROON', 'PURPLE', 'PINK', 'RED', 'ORANGE', 23 'YELLOW', 'LIME', 'AQUA', 'AQUAMARINE', 'GREEN', 'OLIVE', 24 'BROWN', 'NAVY', 'TEAL', 'BLUE', 'GRAY', 'SILVER', 25 'WHITE', 26 ); 27 28 # Map of possible colours back to TML %COLOUR%...%ENDCOLOR% 29 our %HTML2TML_COLOURMAP = ( 28 30 BLACK => 'BLACK', 29 31 '#000000' => 'BLACK', … … 32 34 PURPLE => 'PURPLE', 33 35 '#800080' => 'PURPLE', 34 PINK=> 'PINK',36 FUCHSIA => 'PINK', 35 37 '#FF00FF' => 'PINK', 36 38 RED => 'RED', … … 38 40 ORANGE => 'ORANGE', 39 41 '#FF6600' => 'ORANGE', 40 '#FFA500' => 'ORANGE', # HTML standard41 42 YELLOW => 'YELLOW', 42 43 '#FFFF00' => 'YELLOW', … … 52 53 BROWN => 'BROWN', 53 54 '#996633' => 'BROWN', 54 '#A52A2A' => 'BROWN', # HTML standard55 55 NAVY => 'NAVY', 56 56 '#000080' => 'NAVY', -
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; -
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm
r2957 r3396 260 260 261 261 # Handle colour tags specially (hack, hack, hackity-HACK!) 262 my $colourMatch = join( '|', grep( /^[A-Z]/, keys %WC::KNOWN_COLOUR ) ); 263 while ( $text =~ 264 s#%($colourMatch)%(.*?)%ENDCOLOR%#<font color="\L$1\E">$2</font>#og ) 265 { 266 } 262 my $colourMatch = join( '|', grep( /^[A-Z]/, @WC::TML_COLOURS ) ); 263 $text =~ s#%($colourMatch)%(.*?)%ENDCOLOR%# 264 _getNamedColour($1, $2)#oge; 267 265 268 266 # Convert Foswiki tags to spans outside protected text … … 508 506 } 509 507 508 sub _getNamedColour { 509 my ( $name, $t ) = @_; 510 my $epr = Foswiki::Func::getPreferencesValue($name); 511 512 # Match <font color="x" and style="color:x" 513 if ( 514 defined $epr 515 && ( $epr =~ /color=["'](#?\w+)['"]/ 516 || $epr =~ /color\s*:\s*(#?\w+)/ ) 517 ) 518 { 519 return "<span class='WYSIWYG_COLOR' style='color:$1'>$t</span>"; 520 } 521 522 # Can't map to a 'real' colour; leave the variables 523 return '%' . $name . '%' . $t . '%ENDCOLOR%'; 524 } 525 510 526 sub _addClass { 511 527 if ( $_[0] ) { -
trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm
r2957 r3396 1557 1557 exec => $HTML2TML, 1558 1558 html => <<HERE, 1559 <font color="red" class="WYSIWYG_COLO UR">red</font>1559 <font color="red" class="WYSIWYG_COLOR">red</font> 1560 1560 <font style="color:green">green</font> 1561 1561 <font style="border:1;color:blue">blue</font> 1562 <font class="WYSIWYG_COLO UR" style="border:1;color:yellow">yellow</font>1562 <font class="WYSIWYG_COLOR" style="border:1;color:yellow">yellow</font> 1563 1563 <font color="brown">brown</font> 1564 1564 HERE -
trunk/WysiwygPlugin/test/unit/WysiwygPlugin/WysiwygPluginTests.pm
r2996 r3396 162 162 # Strip ASCII header 163 163 $this->assert_matches( qr/Content-Type: *text\/plain; *charset=UTF-8/i, 164 $out, 165 anal($out) ); 164 $out, anal($out) ); 166 165 $out =~ s/^.*?\r\n\r\n//s; 167 166 … … 217 216 # Strip ASCII header 218 217 $this->assert_matches( qr/Content-Type: *text\/plain; *charset=UTF-8/, 219 $out, 220 anal($out) ); 218 $out, anal($out) ); 221 219 $out =~ s/^.*?\r\n\r\n//s; 222 220
Note: See TracChangeset
for help on using the changeset viewer.
