Skip to content

Commit

Permalink
Item1396: Item9305: Item10089: Item11592: Item11722: Item11784: Item1…
Browse files Browse the repository at this point in the history
…1814: Item11818: Item11819:

Sync up Trunk to Release11.

git-svn-id: http://svn.foswiki.org/branches/Release01x01@14786 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed May 10, 2012
1 parent cb139be commit 97cb76f
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 83 deletions.
Empty file added WysiwygPlugin/TIDY
Empty file.
9 changes: 9 additions & 0 deletions WysiwygPlugin/data/System/WysiwygPlugin.txt
Expand Up @@ -188,6 +188,15 @@ Many thanks to the following sponsors for supporting this work:
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | |
| 1.1.6 | Foswikitask:Item1396: Process TML links as HTML links %BR%\
Foswikitask:Item9305: TMCE should honor NOAUTOLINK preference and noautolink blocks. %BR%\
Foswikitask:Item10089: Allow TMCE to recognize TML links as HTML links. %BR%\
Foswikitask:Item11592: Protect Glue format markup in macros. %BR%\
Foswikitask:Item11722: Don't merge verbatim blocks if they have different classes. %BR%\
Foswikitask:Item11784: Handle colors implemented using CSS classes. %BR%\
Foswikitask:Item11814: Preserve URI Encoding in links. %BR%\
Foswikitask:Item11818: !WikiWords escaped with ! are show as linking. %BR%\
Foswikitask:Item11819: TMCE is failing to protect newlines. |
| 1.1.5 (06 Apr 2012) | Foswikitask:Item11603: protect inline script and style tags from wysiwyg. %BR%\
Foswikitask:Item11440: protect tags inside pre.%BR%\
Foswikitask:Item9259: Protect TML tables from corrupting embedded html markup.%BR%\
Expand Down
2 changes: 1 addition & 1 deletion WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin.pm
Expand Up @@ -31,7 +31,7 @@ our $SHORTDESCRIPTION = 'Translator framework for WYSIWYG editors';
our $NO_PREFS_IN_TOPIC = 1;
our $VERSION = '$Rev$';

our $RELEASE = '1.1.5';
our $RELEASE = '1.1.6';

our %xmltag;

Expand Down
4 changes: 3 additions & 1 deletion WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/Constants.pm
Expand Up @@ -15,7 +15,9 @@ our %ALWAYS_BLOCK = map { $_ => 1 }
HR ISINDEX MENU NOFRAMES NOSCRIPT OL P PRE TABLE UL );
our $ALWAYS_BLOCK_S = join( '|', keys %ALWAYS_BLOCK );

our $STARTWW = qr/^|(?<=[ \t\n\(\!])|(?<=<p>)|(?<= <\/span>)/om;
# STARTWW should match Foswiki::Render, execpt need to include protected whitespace spans.
our $STARTWW =
qr/^|(?<=[ \t\n\(])|(?<=<p>)|(?<=nbsp;<\/span>)|(?<=160;<\/span>)/om;
our $ENDWW = qr/$|(?=[ \t\n\,\.\;\:\!\?\)])|(?=<\/p>)|(?=<span\b[^>]*> )/om;
our $PROTOCOL = qr/^(file|ftp|gopher|https?|irc|news|nntp|telnet|mailto):/;

Expand Down
82 changes: 64 additions & 18 deletions WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm
Expand Up @@ -147,6 +147,7 @@ sub hasClass {
return hasClass( $this->{attrs}, $class );
}
return 0 unless defined $this->{class};

return $this->{class} =~ /\b$class\b/ ? 1 : 0;
}

Expand All @@ -163,6 +164,7 @@ sub _removeClass {
return _removeClass( $this->{attrs}, $class );
}
return 0 unless hasClass( $this, $class );

$this->{class} =~ s/\b$class\b//;
$this->{class} =~ s/\s+/ /g;
$this->{class} =~ s/^\s+//;
Expand Down Expand Up @@ -289,6 +291,7 @@ s/$WC::CHECKw(($WC::PON|$WC::POFF)?[$WC::CHECKn$WC::CHECKs$WC::NBSP $WC::NBBR])/

# isolate $NBBR and convert to \n.
unless ($protect) {

$tml =~ s/\n$WC::NBBR/$WC::NBBR$WC::NBBR/go;
$tml =~ s/$WC::NBBR\n/$WC::NBBR$WC::NBBR/go;
$tml =~ s/$WC::NBBR( |$WC::NBSP)+$WC::NBBR/$WC::NBBR$WC::NBBR/go;
Expand All @@ -308,6 +311,7 @@ s/$WC::CHECKw(($WC::PON|$WC::POFF)?[$WC::CHECKn$WC::CHECKs$WC::NBSP $WC::NBBR])/
$tml =~ s.($WC::NBBR$WC::NBBR$WC::NBBR$WC::NBBR+).
"\n" x ((length($1) + 1) / 2 + 1)
.geo;

}

# isolate $CHECKn and convert to $NBBR
Expand Down Expand Up @@ -347,14 +351,16 @@ s/$WC::CHECKw(($WC::PON|$WC::POFF)?[$WC::CHECKn$WC::CHECKs$WC::NBSP $WC::NBBR])/
$tml =~ s/<br( \/)?>\n/\n/g;
}

#print STDERR WC::debugEncode($before);
#print STDERR " -> '",WC::debugEncode($tml),"'\n";
#print STDERR " -> [",WC::debugEncode($tml),"]\n";
$text .= $tml;
}

# Collapse adjacent tags
foreach my $tag (qw(noautolink verbatim literal)) {
$text =~ s#</$tag>(\s*)<$tag>#$1#gs;
# SMELL: Can't collapse verbatim based upon simple close/open compare
# because the previous opening verbatim tag might have different
# class from the next one.
foreach my $tag (qw(noautolink literal)) {
$text =~ s#</$tag>(\h*)<$tag>#$1#gs;
}

# Top and tail, and terminate with a single newline
Expand All @@ -366,6 +372,17 @@ s/$WC::CHECKw(($WC::PON|$WC::POFF)?[$WC::CHECKn$WC::CHECKs$WC::NBSP $WC::NBBR])/
return $text;
}

sub _compareClass {
my ( $node1, $node2 ) = @_;

my $n1Class = $node1->{attrs}->{class} || '';
my $n1Sort = join( ' ', sort( split( / /, $n1Class ) ) );
my $n2Class = $node2->{attrs}->{class} || '';
my $n2Sort = join( ' ', sort( split( / /, $n2Class ) ) );

return ( $n1Sort eq $n2Sort );
}

# collapse adjacent nodes together, if they share the same class
sub _collapseOneClass {
my $node = shift;
Expand All @@ -379,11 +396,13 @@ sub _collapseOneClass {
&& (
( !$next->{tag} && $next->{text} =~ /^\s*$/ )
|| ( $node->{tag} eq $next->{tag}
&& $next->hasClass($class) )
&& $next->hasClass($class)
&& ( _compareClass( $node, $next ) ) )
)
)
{
push( @edible, $next );

$collapsible ||= $next->hasClass($class);
$next = $next->{next};
}
Expand Down Expand Up @@ -414,6 +433,10 @@ sub _collapse {
my @jobs = ($this);
while ( scalar(@jobs) ) {
my $node = shift(@jobs);

# SMELL: Not sure if we really still have to collapse consecutive verbatim.
# Extra whitespace to separate verbatim blocks is removed, and they will
# still eventually be merged.
_collapseOneClass( $node, 'TMLverbatim' );
_collapseOneClass( $node, 'WYSIWYG_STICKY' );
if ( $node->{tag} eq 'p'
Expand Down Expand Up @@ -629,14 +652,17 @@ sub _htmlParams {
my @classes;
$v =~ s/^\s*(.*?)\s*$/$1/;
CLASS: for my $class ( split /\s+/, $v ) {

next CLASS unless $class =~ /\S/;

next CLASS if $tml2htmlClass{$class};

# if cleaning aggressively, remove class attributes
# except for the JQuery "Chili" classes
next CLASS
if ( $options & $WC::VERY_CLEAN
and not $jqueryChiliClass{$class} );
if ( $options & $WC::VERY_CLEAN
and not $jqueryChiliClass{$class}
and not $class =~ /^foswiki/ );

push @classes, $class;
}
Expand Down Expand Up @@ -1281,6 +1307,7 @@ sub _verbatim {
# &nbsp; decodes to \240, which we want to make a space.
$text =~ s/\240/$WC::NBSP/g;
my $p = _htmlParams( $this->{attrs}, $options );

return ( $flags, "<$tag$p>$text</$tag>" );
}

Expand Down Expand Up @@ -1375,6 +1402,10 @@ sub _handleA {
# there's text and an href
my $href = $this->{attrs}->{href};

my $forceTML =
( $this->{attrs}->{class}
&& $this->{attrs}->{class} =~ m/\bTMLlink\b/ );

# decode URL params in the href
$href =~ s/%([0-9A-F]{2})/chr(hex($1))/gei;
if ( $this->{context} && $this->{context}->{rewriteURL} ) {
Expand All @@ -1392,7 +1423,9 @@ sub _handleA {
$cleantext =~ s/^$this->{context}->{web}\.//;

# if the clean text is the known topic we can ignore it
if ( ( $cleantext eq $href || $href =~ /\.$cleantext$/ ) ) {
if ( ( $cleantext eq $href || $href =~ /\.$cleantext$/ )
&& !$forceTML )
{
return ( 0,
$WC::CHECK1
. $nop
Expand All @@ -1402,15 +1435,29 @@ sub _handleA {
. $WC::CHECK2 );
}
}

if ( $href =~ /${WC::PROTOCOL}[^?]*$/ && $text eq $href ) {
if ( $href =~ /${WC::PROTOCOL}[^?]*$/
&& $text eq $href
&& !$forceTML )
{
return ( 0, $WC::CHECK1 . $nop . $text . $WC::CHECK2 );
}
if ( $text eq $href ) {
return ( 0, $WC::CHECKw . '[' . $nop . '[' . $href . ']]' );
return ( 0,
$WC::CHECKw . '[' . $nop . '[' . $this->{attrs}{href} . ']]' );
}

# we must quote square brackets in [[...][...]] notation
$text =~ s/[[]/&#91;/g;
$text =~ s/[]]/&#93;/g;
$this->{attrs}{href} =~ s/[[]/%5B/g;
$this->{attrs}{href} =~ s/[]]/%5D/g;

return ( 0,
$WC::CHECKw . '[' . $nop . '[' . $href . '][' . $text . ']]' );
$WC::CHECKw . '['
. $nop . '['
. $this->{attrs}{href} . ']['
. $text
. ']]' );
}
elsif ( $this->{attrs}->{name} ) {

Expand Down Expand Up @@ -1760,7 +1807,7 @@ sub _handleSPAN {
$this->_flatten( $options | $WC::KEEP_WS | $WC::KEEP_ENTITIES );

#die Data::Dumper::Dumper($kids);
if ( $kids eq ' ' ) {
if ( $kids eq '&nbsp;' ) {

# The space was not changed
# So restore the encoded whitespace
Expand Down Expand Up @@ -1799,11 +1846,10 @@ sub _handleSPAN {
delete $atts{class};
}

if ( $options & $WC::VERY_CLEAN ) {

# remove style attribute if cleaning aggressively.
# delete $atts{style} if defined $atts{style};
}
# if ( $options & $WC::VERY_CLEAN ) {
# remove style attribute if cleaning aggressively.
# delete $atts{style} if defined $atts{style};
# }

# ignore the span tag if there are no other attrs
if ( scalar( keys %atts ) == 0 ) {
Expand Down

0 comments on commit 97cb76f

Please sign in to comment.