X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FBlockLevelPass.php;h=50c7e2376ec00a8996b4022aaaddadda57c3fb2c;hb=ecc63fb7fe1134d064772fa71493575235b809ca;hp=6d6af7716c0d61c80ea1183a6f45757aa70596f9;hpb=73239ee9bdb2598ada26c20a1b0009c501b162bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/BlockLevelPass.php b/includes/parser/BlockLevelPass.php index 6d6af7716c..50c7e2376e 100644 --- a/includes/parser/BlockLevelPass.php +++ b/includes/parser/BlockLevelPass.php @@ -192,8 +192,6 @@ class BlockLevelPass { # happening here is handling of block-level elements p, pre, # and making lists from lines starting with * # : etc. $textLines = StringUtils::explode( "\n", $text ); - # Count this way because $textLines could be an ExplodeIterator - $lineCount = substr_count( $text, "\n" ) + 1; $lastPrefix = $output = ''; $this->DTopen = $inBlockElem = false; @@ -201,9 +199,11 @@ class BlockLevelPass { $pendingPTag = false; $inBlockquote = false; - $nextLineNum = 0; - foreach ( $textLines as $inputLine ) { - $nextLineNum += 1; + for ( $textLines->rewind(); $textLines->valid(); ) { + $inputLine = $textLines->current(); + $textLines->next(); + $notLastLine = $textLines->valid(); + # Fix up $lineStart if ( !$this->lineStart ) { $output .= $inputLine; @@ -380,23 +380,19 @@ class BlockLevelPass { $output .= $pendingPTag . '
'; $pendingPTag = false; $this->lastParagraph = 'p'; - } else { - if ( $this->lastParagraph !== 'p' ) { - $output .= $this->closeParagraph(); - $pendingPTag = '

'; - } else { - $pendingPTag = '

'; - } - } - } else { - if ( $pendingPTag ) { - $output .= $pendingPTag; - $pendingPTag = false; - $this->lastParagraph = 'p'; } elseif ( $this->lastParagraph !== 'p' ) { - $output .= $this->closeParagraph() . '

'; - $this->lastParagraph = 'p'; + $output .= $this->closeParagraph(); + $pendingPTag = '

'; + } else { + $pendingPTag = '

'; } + } elseif ( $pendingPTag ) { + $output .= $pendingPTag; + $pendingPTag = false; + $this->lastParagraph = 'p'; + } elseif ( $this->lastParagraph !== 'p' ) { + $output .= $this->closeParagraph() . '

'; + $this->lastParagraph = 'p'; } } } @@ -410,7 +406,7 @@ class BlockLevelPass { $output .= $t; // Add a newline if there's an open paragraph // or we've yet to reach the last line. - if ( $nextLineNum < $lineCount || $this->hasOpenParagraph() ) { + if ( $notLastLine || $this->hasOpenParagraph() ) { $output .= "\n"; } } else {