Index: test/unit/WysiwygPlugin/TranslatorTests.pm =================================================================== --- test/unit/WysiwygPlugin/TranslatorTests.pm (revision 8812) +++ test/unit/WysiwygPlugin/TranslatorTests.pm (working copy) @@ -93,9 +93,6 @@ Move !ItTest/site/ToWeb5 leaving web5 as !MySQL host
HERE - finaltml => <<'HERE', -Move !ItTest/site/ToWeb5 leaving web5 as !MySQL host -HERE }, { exec => $ROUNDTRIP, @@ -114,7 +111,6 @@ name => 'currentWebLinkAtStart', tml => 'Current.LinkAtStart', html => $linkon . 'Current.LinkAtStart' . $linkoff, - finaltml => 'Current.LinkAtStart', }, { exec => $ROUNDTRIP, @@ -151,7 +147,6 @@ reminded about${linkon}http://www.koders.com${linkoff} HERE tml => '*reminded about http://www.koders.com*', - finaltml => '*reminded about http://www.koders.com*', }, { exec => $ROUNDTRIP, @@ -418,7 +413,7 @@ { exec => $ROUNDTRIP | $TML2HTML, name => 'simpleHR', - html => '--
', + html => '--
', tml => <<'HERE', --- ------- @@ -427,7 +422,7 @@ HERE finaltml => <<'HERE', --- ---- +------- -- HERE @@ -783,8 +778,20 @@ 'Inside @@ -1098,10 +1108,21 @@ SnideOutside', - finaltml => 'Outside
+ }, + { + exec => $HTML2TML, + name => 'nestedIndentedPre2', + html => 'Outside +Outside', }, { + exec => $HTML2TML, + name => 'indentedPre1', + html => 'OutsideInside Snide ++ Outside', + tml => 'Outside+ Inside + +SnideOutside', }, { @@ -1117,8 +1138,18 @@
+ Inside +Outside', + tml => 'Outside
+ Inside +Outside', + }, + { exec => $ROUNDTRIP, - name => 'indentedPre', + name => 'indentedPre2', html => 'Outside
InsideOutside', @@ -1127,28 +1158,38 @@ Inside Outside', - finaltml => 'Outside
- Inside -Outside', }, { exec => $TML2HTML | $ROUNDTRIP, - name => 'NAL', + name => 'NAL1', html => '
Outside <noautolink> Inside </noautolink> Outside
', + tml => 'OutsideOutside' +. encodedWhitespace('ns1') +. '<noautolink>' +. encodedWhitespace('ns1') +. 'Inside' +. encodedWhitespace('ns1') +. '</noautolink>' +. encodedWhitespace('ns1') +. 'Outside
', tml => 'OutsideOutside <noautolink class="foswikiAlert">
</noautolink> Outside
', + tml => 'OutsideOutside' +. encodedWhitespace('n') +. '<noautolink class="foswikiAlert">
+</noautolink>' +. encodedWhitespace('ns1') +. 'Outside +
', tml => 'Outside-Paraone -Paratwo +Paraone' +. encodedWhitespace('n') +. 'Paratwo
Parathree @@ -1560,7 +1621,8 @@ Parafour', - finaltml => 'Paraone Paratwo + finaltml => 'Paraone +Paratwo Parathree @@ -1706,9 +1768,11 @@ html => '
<section>
C -</section> -X
+C' +. encodedWhitespace('n') +. '</section>' +. encodedWhitespace('n') +. 'X
', finaltml => <No more
-DECAPS +', }, { exec => $ROUNDTRIP, @@ -2365,14 +2433,16 @@ edit Blah BLAH - html => <<'BLAH', --Blah -<a href="%SCRIPTURLPATH{"edit"}%/%WEB%/%TOPIC%?t=%GM%NOP%TIME{"$epoch"}%">edit</a> -Blah + html => +'
+Blah' +. encodedWhitespace('n') +. '<a href="%SCRIPTURLPATH{"edit"}%/%WEB%/%TOPIC%?t=%GM%NOP%TIME{"$epoch"}%">edit</a>' +. encodedWhitespace('n') +. 'Blah
-BLAH +', }, { name => 'Item4903', @@ -2525,18 +2595,15 @@ &><" HERE - html => <-&><" + html => +'
<img src="ball&co<ck>s">&><"
+<smeg>' +. encodedWhitespace('n') +. '
' +. encodedWhitespace('n') +. '&><" -HERE - finaltml => <
<img src="ball&co<ck>s">&><"
@@ -2574,7 +2635,6 @@ { name => "Item5961", exec => $HTML2TML | $ROUNDTRIP, - html => 'one', html => ' zero one two tre', tml => @@ -2608,11 +2668,6 @@ %SEARCH{search="Sven"}% HERE - finaltml => <<'HERE', ---- - -%SEARCH{search="Sven"}% -HERE html => <<'HERE',
@@ -2691,6 +2746,32 @@ ''. '
' }, + { + name => "whitespaceEncoding", + exec => $TML2HTML | $ROUNDTRIP, + tml => <<'HERE', +a a + b + * c + d +e +HERE + html => '' + . 'a' + . encodedWhitespace('s2') + . 'a' + . encodedWhitespace('ns1') + . 'b' + . '
' + . '
' + . 'e' + . '
', + }, { name => "failsTML2HTML", exec => 0,#$TML2HTML | $HTML2TML | $ROUNDTRIP, @@ -2704,6 +2785,13 @@ }, ]; +sub encodedWhitespace { + my $encoded = shift; + return ' '; +} + # Run from BEGIN sub gen_file_tests { foreach my $d (@INC) { @@ -2828,6 +2916,7 @@ my $html = eval { $txer->convert( $tml, $this->TML_HTMLconverterOptions() ); }; $html = $@ if $@; + #print STDERR "'$html'\n"; $txer = new Foswiki::Plugins::WysiwygPlugin::HTML2TML(); my $tx = $txer->convert( $html, $this->HTML_TMLconverterOptions() ); Index: test/unit/WysiwygPlugin/ExtendedTranslatorTests.pm =================================================================== --- test/unit/WysiwygPlugin/ExtendedTranslatorTests.pm (revision 8810) +++ test/unit/WysiwygPlugin/ExtendedTranslatorTests.pm (working copy) @@ -100,12 +100,14 @@ . $protecton . '<customtag>' . $protectoff - . 'some > text' + . 'some >' + . TranslatorTests::encodedWhitespace('s2') + . 'text' . $protecton . '</customtag>' . $protectoff . '', tml => ')|(?<= <\/span>)/om;
+our $ENDWW = qr/$|(?=[ \t\n\,\.\;\:\!\?\)])|(?=<\/p>)|(?=]*> )/om;
our $PROTOCOL = qr/^(file|ftp|gopher|https?|irc|news|nntp|telnet|mailto):/;
# Colours with colour settings in DefaultPreferences.
Index: lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm
===================================================================
--- lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm (revision 8810)
+++ lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm (working copy)
@@ -372,8 +372,8 @@
$text = $this->_takeOutCustomTags($text);
- $text =~ s/\\\n/ /g;
$text =~ s/\t/ /g;
+ $text =~ s/( +\\\n)/$this->_hideWhitespace($1)/ge;
# Remove PRE to prevent TML interpretation of text inside it
$text = $this->_liftOutBlocks( $text, 'pre', {} );
@@ -438,8 +438,7 @@
$text =~ s/$TT0([$Foswiki::regex{mixedAlphaNum}]+;)/&$1/go;
# Horizontal rule
- my $hr = CGI::hr( { class => 'TMLhr' } );
- $text =~ s/^---+$/$hr/gm;
+ $text =~ s/^(---+)$/_encodeHr($1)/gme;
# Wrap tables with macros before or after them in a $/ ) {
+ # This is the second (or later) line of a paragraph
+
+ my $whitespace = "\n";
+ if ($line =~ s/^(\s+)//) {
+ $whitespace .= $1;
+ }
+ $line = $this->_hideWhitespace($whitespace) . $line;
+ }
unless ( $inParagraph or $inDiv ) {
push( @result, ' ' );
$inParagraph = 1;
}
+ $line =~ s/(\s\s+)/$this->_hideWhitespace($1)/ge;
+ $result[-1] .= $line;
+ $line = '';
}
- push( @result, $line );
+ push( @result, $line ) if length($line) > 0;
}
if ($inTable) {
@@ -688,7 +701,7 @@
# Handle [[][]] and [[]] links
- # We _not_ support [[http://link text]] syntax
+ # We do _not_ support [[http://link text]] syntax
# [[][]]
$text =~ s/(\[\[[^\]]*\](\[[^\]]*\])?\])/$this->_liftOut($1, 'LINK')/ge;
@@ -713,6 +726,42 @@
return $text;
}
+sub _encodeHr {
+ my $dashes = shift;
+ my $style = '';
+ if ( length($dashes) > 3 ) {
+ $style = ' style="{numDashes:' . length($dashes) . '}"';
+ }
+ return '
' ) if $inParagraph;
$inParagraph = 0;
}
@@ -646,13 +647,25 @@
# Other line
$this->_addListItem( \@result, '', '', '' ) if $inList;
$inList = 0;
+ if ( $inParagraph and @result and $result[-1] !~ /
';
+}
+
+sub _hideWhitespace {
+ my $this = shift;
+ my $whitespace = shift;
+
+ $whitespace =~ s/\\/b/g;
+ $whitespace =~ s/\n/n/g;
+ $whitespace =~ s/(\t+)/'t' . length($1)/ge;
+ $whitespace =~ s/( +)/'s' . length($1)/ge;
+
+ return $this->_liftOutGeneral(
+ " ",
+ {
+ tag => 'span',
+ class => "TMLwhitespace",
+ params => "style=\"{encoded:'$whitespace'}\"",
+ }
+ );
+}
+
sub _processTableRow {
my ( $theRow, $inTable, $state ) = @_;