Merge "Set the package type to 'mediawiki-core'"
[lhc/web/wiklou.git] / includes / parser / BlockLevelPass.php
index acdc652..c366903 100644 (file)
@@ -291,23 +291,42 @@ class BlockLevelPass {
                        if ( 0 == $prefixLength ) {
                                # No prefix (not in list)--go to paragraph mode
                                # @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';
+                               // P-wrapping and indent-pre are suppressed outside, not inside
+                               $antiBlockElems = 'td|th';
+
                                $openMatch = preg_match(
-                                       '/(?:<table|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|'
-                                               . '<p|<ul|<ol|<dl|<li|<\\/tr|<\\/td|<\\/th)\\b/iS',
+                                       '/<('
+                                               . "({$blockElems})|\\/({$antiBlockElems})|"
+                                               // Always suppresses
+                                               . '\\/?(tr)'
+                                               . ')\\b/iS',
                                        $t
                                );
                                $closeMatch = preg_match(
-                                       '/(?:<\\/table|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'
-                                               . '<td|<th|<\\/?blockquote|<\\/?div|<hr|<\\/pre|<\\/p|<\\/mw:|'
-                                               . Parser::MARKER_PREFIX
-                                               . '-pre|<\\/li|<\\/ul|<\\/ol|<\\/dl|<\\/?center)\\b/iS',
+                                       '/<('
+                                               . "\\/({$blockElems})|({$antiBlockElems})|"
+                                               // Never suppresses
+                                               . '\\/?(center|blockquote|div|hr|mw:)'
+                                               . ')\\b/iS',
                                        $t
                                );
 
+                               // Any match closes the paragraph, but only when `!$closeMatch`
+                               // do we enter block mode.  The oddities with table rows and
+                               // cells are to avoid paragraph wrapping in interstitial spaces
+                               // leading to fostered content.
+
                                if ( $openMatch || $closeMatch ) {
                                        $pendingPTag = false;
-                                       # @todo T7718: paragraph closed
-                                       $output .= $this->closeParagraph();
+                                       // Only close the paragraph if we're not inside a <pre> tag, or if
+                                       // that <pre> tag has just been opened
+                                       if ( !$this->inPre || $preOpenMatch ) {
+                                               // @todo T7718: paragraph closed
+                                               $output .= $this->closeParagraph();
+                                       }
                                        if ( $preOpenMatch && !$preCloseMatch ) {
                                                $this->inPre = true;
                                        }