Changeset 10527


Ignore:
Timestamp:
01/13/11 18:38:28 (16 months ago)
Author:
MichaelTempest
Message:

Item2174: Now that WysiwygPlugin preserves leading whitepsace, newlines are even more important than they were before.

Loss of newlines after lists causes topic-rot if the paragraph after the list has leading whitespace. For example:

  • foo

bar

... must not become

  • foo bar

This change prevents loss of that now-crucial newline.

Location:
trunk/WysiwygPlugin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm

    r10344 r10527  
    15901590    my ( $this, $options ) = @_; 
    15911591 
     1592    my $nbnl = $this->hasClass('WYSIWYG_NBNL'); 
     1593 
    15921594    if ( $this->hasClass('WYSIWYG_WARNING') ) { 
    15931595        return ( 0, '' ); 
     
    16231625        $pre = $WC::NBBR; 
    16241626    } 
     1627    $pre = $WC::NBBR . $pre if $nbnl; 
    16251628    return ( $f | $WC::BLOCK_TML, $pre . $kids . $WC::NBBR ); 
    16261629} 
  • trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm

    r10083 r10527  
    564564 
    565565            # Blank line 
     566            my $class = ''; 
     567            if (not $inParagraph) { 
     568                $class = 'WYSIWYG_NBNL'; 
     569            } 
     570            $class = " class='$class'" if $class; 
     571 
    566572            push( @result, '</p>' ) if $inParagraph; 
    567573            $inParagraph = 0; 
    568             $line        = '<p>'; 
     574 
     575            $line = '<p' . $class . '>'; 
     576 
    569577            $this->_addListItem( \@result, '', '', '' ) if $inList; 
    570578            $inList      = 0; 
     579 
    571580            $inParagraph = 1; 
    572581 
     
    661670            $this->_addListItem( \@result, '', '', '' ) if $inList; 
    662671            $inList = 0; 
    663             if ( $inParagraph and @result and $result[-1] !~ /<p>$/ ) { 
     672            if ( $inParagraph and @result and $result[-1] !~ /<p(?: class='[^']+')?>$/ ) { 
    664673 
    665674                # This is the second (or later) line of a paragraph 
    666675 
    667676                my $whitespace = "\n"; 
     677                if ($line =~  m/^$TT1(\d+)$TT2/ 
     678                        and $this->{refs}->[$1]->{text} =~ /^\n?%/ ) { 
     679                    # The newline is already protected 
     680                    $whitespace = ""; 
     681                } 
    668682                if ( $line =~ s/^(\s+)// ) { 
    669683                    $whitespace .= $1; 
    670684                } 
    671                 $line = $this->_hideWhitespace($whitespace) . $line; 
     685                $line = $this->_hideWhitespace($whitespace) . $line if length($whitespace); 
    672686            } 
    673687            unless ( $inParagraph or $inDiv ) { 
  • trunk/WysiwygPlugin/test/unit/WysiwygPlugin/BrowserTranslatorTests.pm

    r9886 r10527  
    136136%SEARCH{search="Sven"}% 
    137137HERE 
    138         finaltml => <<'HERE', 
    139 --- 
    140  
    141 %SEARCH{search="Sven"}% 
    142 HERE 
    143138        html => <<'HERE', 
    144139<hr class="TMLhr" /> 
    145 <p> 
     140<p class="WYSIWYG_NBNL"> 
    146141<span class="WYSIWYG_PROTECTED"><br />%SEARCH{search=&#34;Sven&#34;}%</span> 
    147142</p> 
  • trunk/WysiwygPlugin/test/unit/WysiwygPlugin/ExtendedTranslatorTests.pm

    r9886 r10527  
    466466Before 
    467467</p> 
    468 <table border="1" cellpadding="0" cellspacing="1"><tr><th>L</th><th>C</th><th>R</th></tr><tr><td> A2</td><td style="text-align: center" class="align-center"> 2</td><td style="text-align: right" class="align-right"> 2</td></tr><tr><td> A3</td><td style="text-align: center" class="align-center"> 3</td><td style="text-align: left" class="align-left"> 3</td></tr><tr><td> A4-6</td><td> four</td><td> four</td></tr><tr><td>^</td><td> five</td><td> five</td></tr></table><p /><table border="1" cellpadding="0" cellspacing="1"><tr><td>^</td><td> six</td><td> six</td></tr></table> 
     468<table border="1" cellpadding="0" cellspacing="1"><tr><th>L</th><th>C</th><th>R</th></tr><tr><td> A2</td><td style="text-align: center" class="align-center"> 2</td><td style="text-align: right" class="align-right"> 2</td></tr><tr><td> A3</td><td style="text-align: center" class="align-center"> 3</td><td style="text-align: left" class="align-left"> 3</td></tr><tr><td> A4-6</td><td> four</td><td> four</td></tr><tr><td>^</td><td> five</td><td> five</td></tr></table><p class="WYSIWYG_NBNL"/><table border="1" cellpadding="0" cellspacing="1"><tr><td>^</td><td> six</td><td> six</td></tr></table> 
    469469<p>After</p> 
    470470HERE 
  • trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm

    r10344 r10527  
    511511        name => 'orderedList_Item1341', 
    512512        html => <<'HERE', 
    513 <ol><li>Sushi</li><li>Banana</li></ol><p /> 
    514 <ol><li type="A">Sushi</li><li type="A">Banana</li></ol><p /> 
    515 <ol><li type="i">Sushi</li><li type="i">Banana</li></ol><p /> 
    516 <ol><li type="I">Sushi</li><li type="I">Banana</li></ol><p /> 
     513<ol><li>Sushi</li><li>Banana</li></ol><p class="WYSIWYG_NBNL"/> 
     514<ol><li type="A">Sushi</li><li type="A">Banana</li></ol><p class="WYSIWYG_NBNL"/> 
     515<ol><li type="i">Sushi</li><li type="i">Banana</li></ol><p class="WYSIWYG_NBNL"/> 
     516<ol><li type="I">Sushi</li><li type="I">Banana</li></ol><p class="WYSIWYG_NBNL"/> 
    517517<ol><li>Sushi</li><li type="A">Sushi</li><li type="i">Sushi</li></ol> 
    518518HERE 
     
    554554TML 
    555555        html => <<'HTML', 
    556 <ul><li>&nbsp;</li><li>alpha</li><li>&nbsp;</li><li>beta</li><li>&nbsp;</li></ul><p /> 
    557 <ol><li>&nbsp;</li><li>charlie</li><li>&nbsp;</li></ol><p /> 
     556<ul><li>&nbsp;</li><li>alpha</li><li>&nbsp;</li><li>beta</li><li>&nbsp;</li></ul> 
     557<p class="WYSIWYG_NBNL"/> 
     558<ol><li>&nbsp;</li><li>charlie</li><li>&nbsp;</li></ol> 
     559<p class="WYSIWYG_NBNL"/> 
    558560<ol><li type="i">angel</li><li type="i">&nbsp;</li></ol> 
    559561<p>blah</p> 
     
    16831685Paraone', 
    16841686        html => '<ul><li>list</li></ul>Paraone', 
     1687    }, 
     1688    { 
     1689        name => 'blankLineAndParaAfterList', 
     1690        exec => $TML2HTML | $ROUNDTRIP, 
     1691        tml  => '   * list 
     1692 
     1693Paraone', 
     1694        html => '<ul><li>list' 
     1695          . '</li></ul><p class="WYSIWYG_NBNL">Paraone</p>', 
     1696    }, 
     1697    { 
     1698        name => 'blankLineAndParaWithLeadingSpacesAfterList', 
     1699        exec => $ROUNDTRIP, 
     1700        tml  => <<'TML', 
     1701   * list 
     1702 
     1703     Paraone 
     1704TML 
    16851705    }, 
    16861706    { 
     
    26902710        html => <<'HERE', 
    26912711<hr class="TMLhr" /> 
    2692 <p> 
     2712<p class="WYSIWYG_NBNL"> 
    26932713<span class="WYSIWYG_PROTECTED"><br />%SEARCH{search=&#34;Sven&#34;}%</span> 
    26942714</p> 
Note: See TracChangeset for help on using the changeset viewer.