Put <dt>/<dd>/<li> in the always-suppressing category of doBlockLevels
authorArlo Breault <abreault@wikimedia.org>
Thu, 12 Jul 2018 18:41:20 +0000 (14:41 -0400)
committerArlo Breault <abreault@wikimedia.org>
Fri, 13 Jul 2018 16:40:49 +0000 (12:40 -0400)
This is a clarification of what already happens in practice for lists
generated from wikitext syntax, since that parsing happens
simultaneously.

Parsoid, for its part, does list handling prior to paragraph wrapping,
so must make use of these definitions.

Further, this helps reduce paragraph wrapping in interstitial spacing of
lists from HTML syntax, as spec'd in the tests, though the possibility
isn't eliminated entirely.

The TOC generation code is altered to reduce the number of newlines
emitted in between list items, since those are now left intact.

Change-Id: I6888b6e8e6768b0737565b87924fefa5a06ebd18

includes/Linker.php
includes/parser/BlockLevelPass.php
tests/parser/parserTests.txt

index e625a02..3f0ecf6 100644 (file)
@@ -1496,7 +1496,7 @@ class Linker {
         * @return string
         */
        public static function tocIndent() {
-               return "\n<ul>";
+               return "\n<ul>\n";
        }
 
        /**
@@ -1527,9 +1527,9 @@ class Linker {
                        $classes .= " tocsection-$sectionIndex";
                }
 
-               // \n<li class="$classes"><a href="#$anchor"><span class="tocnumber">
+               // <li class="$classes"><a href="#$anchor"><span class="tocnumber">
                // $tocnumber</span> <span class="toctext">$tocline</span></a>
-               return "\n" . Html::openElement( 'li', [ 'class' => $classes ] )
+               return Html::openElement( 'li', [ 'class' => $classes ] )
                        . Html::rawElement( 'a',
                                [ 'href' => "#$anchor" ],
                                Html::element( 'span', [ 'class' => 'tocnumber' ], $tocnumber )
index c366903..0553db9 100644 (file)
@@ -293,7 +293,7 @@ class BlockLevelPass {
                                # @todo consider using a stack for nestable elements like span, table and div
 
                                // P-wrapping and indent-pre are suppressed inside, not outside
-                               $blockElems = 'table|h1|h2|h3|h4|h5|h6|pre|p|ul|ol|dl|li';
+                               $blockElems = 'table|h1|h2|h3|h4|h5|h6|pre|p|ul|ol|dl';
                                // P-wrapping and indent-pre are suppressed outside, not inside
                                $antiBlockElems = 'td|th';
 
@@ -301,7 +301,7 @@ class BlockLevelPass {
                                        '/<('
                                                . "({$blockElems})|\\/({$antiBlockElems})|"
                                                // Always suppresses
-                                               . '\\/?(tr)'
+                                               . '\\/?(tr|dt|dd|li)'
                                                . ')\\b/iS',
                                        $t
                                );
index 43b4572..925af6f 100644 (file)
@@ -9932,7 +9932,7 @@ List interrupted by empty line or heading
 
 !!end
 
-!!test
+!! test
 Multiple list tags generated by templates
 !! wikitext
 {{echo|<li>}}a
@@ -9945,6 +9945,7 @@ Multiple list tags generated by templates
 </li>
 </li>
 
+
 !! html+tidy
 <li>a
 </li><li>b
@@ -9954,7 +9955,44 @@ Multiple list tags generated by templates
 <li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"dsr":[0,44,null,null],"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"a\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;li>"}},"i":1}},"b\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;li>"}},"i":2}},"c"]}'>a
 </li><li about="#mwt1">b
 </li><li about="#mwt1" data-parsoid='{"stx":"html","autoInsertedEnd":true,"dsr":[null,44,null,0]}'>c</li>
-!!end
+!! end
+
+!! test
+Multiple newlines in between HTML list items don't induce paragraph wrapping
+!! wikitext
+<ul>
+<li>hi</li>
+
+
+
+
+<li>ho</li>
+</ul>
+
+<dl>
+<dt>hi</dt>
+<dd>ho<div>123</div>
+</dd>
+
+
+</dl>
+!! html/php+tidy
+<ul>
+<li>hi</li>
+
+
+
+
+<li>ho</li>
+</ul>
+<dl>
+<dt>hi</dt>
+<dd>ho<div>123</div>
+</dd>
+
+
+</dl>
+!! end
 
 !!test
 Single-comment whitespace lines dont break lists, and neither do multi-comment whitespace lines