$pendingPTag = false;
$inBlockquote = false;
- $lineCount = count( $textLines );
- foreach ( $textLines as $i => $inputLine ) {
+ for ( $textLines->rewind(); $textLines->valid(); ) {
+ $inputLine = $textLines->current();
+ $textLines->next();
+ $notLastLine = $textLines->valid();
+
# Fix up $lineStart
if ( !$this->lineStart ) {
$output .= $inputLine;
$output .= $pendingPTag . '<br />';
$pendingPTag = false;
$this->lastParagraph = 'p';
- } else {
- if ( $this->lastParagraph !== 'p' ) {
- $output .= $this->closeParagraph();
- $pendingPTag = '<p>';
- } else {
- $pendingPTag = '</p><p>';
- }
- }
- } else {
- if ( $pendingPTag ) {
- $output .= $pendingPTag;
- $pendingPTag = false;
- $this->lastParagraph = 'p';
} elseif ( $this->lastParagraph !== 'p' ) {
- $output .= $this->closeParagraph() . '<p>';
- $this->lastParagraph = 'p';
+ $output .= $this->closeParagraph();
+ $pendingPTag = '<p>';
+ } else {
+ $pendingPTag = '</p><p>';
}
+ } elseif ( $pendingPTag ) {
+ $output .= $pendingPTag;
+ $pendingPTag = false;
+ $this->lastParagraph = 'p';
+ } elseif ( $this->lastParagraph !== 'p' ) {
+ $output .= $this->closeParagraph() . '<p>';
+ $this->lastParagraph = 'p';
}
}
}
$output .= $t;
// Add a newline if there's an open paragraph
// or we've yet to reach the last line.
- if ( $i < $lineCount - 1 || $this->hasOpenParagraph() ) {
+ if ( $notLastLine || $this->hasOpenParagraph() ) {
$output .= "\n";
}
} else {