# 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;
$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;
$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 {