$result = $this->closeParagraph();
if ( '*' === $char ) { $result .= '<ul><li>'; }
- else if ( '#' === $char ) { $result .= '<ol><li>'; }
- else if ( ':' === $char ) { $result .= '<dl><dd>'; }
- else if ( ';' === $char ) {
+ elseif ( '#' === $char ) { $result .= '<ol><li>'; }
+ elseif ( ':' === $char ) { $result .= '<dl><dd>'; }
+ elseif ( ';' === $char ) {
$result .= '<dl><dt>';
$this->mDTopen = true;
}
/* private */ function nextItem( $char ) {
if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
- else if ( ':' === $char || ';' === $char ) {
+ elseif ( ':' === $char || ';' === $char ) {
$close = '</dd>';
if ( $this->mDTopen ) { $close = '</dt>'; }
if ( ';' === $char ) {
/* private */ function closeList( $char ) {
if ( '*' === $char ) { $text = '</li></ul>'; }
- else if ( '#' === $char ) { $text = '</li></ol>'; }
- else if ( ':' === $char ) {
+ elseif ( '#' === $char ) { $text = '</li></ol>'; }
+ elseif ( ':' === $char ) {
if ( $this->mDTopen ) {
$this->mDTopen = false;
$text = '</dt></dl>';
/**
* Make lists from lines starting with ':', '*', '#', etc. (DBL)
*
+ * @param $linestart bool whether or not this is at the start of a line.
* @private
* @return string the lists rendered as HTML
*/
$linestart = true;
continue;
}
+ // * = ul
+ // # = ol
+ // ; = dt
+ // : = dd
$lastPrefixLength = strlen( $lastPrefix );
$preCloseMatch = preg_match('/<\\/pre/i', $oLine );
$preOpenMatch = preg_match('/<pre/i', $oLine );
+ // If not in a <pre> element, scan for and figure out what prefixes are there.
if ( !$this->mInPre ) {
# Multiple prefixes may abut each other for nested lists.
$prefixLength = strspn( $oLine, '*#:;' );
$prefix = substr( $oLine, 0, $prefixLength );
# eh?
+ // ; and : are both from definition-lists, so they're equivalent
+ // for the purposes of determining whether or not we need to open/close
+ // elements.
$prefix2 = str_replace( ';', ':', $prefix );
$t = substr( $oLine, $prefixLength );
$this->mInPre = (bool)$preOpenMatch;
}
}
} elseif( $prefixLength || $lastPrefixLength ) {
+ // We need to open or close prefixes, or both.
+
# Either open or close a level...
$commonPrefixLength = $this->getCommon( $prefix, $lastPrefix );
$paragraphStack = false;
+ // Close all the prefixes which aren't shared.
while( $commonPrefixLength < $lastPrefixLength ) {
$output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] );
--$lastPrefixLength;
}
+
+ // Continue the current prefix if appropriate.
if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) {
$output .= $this->nextItem( $prefix[$commonPrefixLength-1] );
}
+
+ // Open prefixes where appropriate.
while ( $prefixLength > $commonPrefixLength ) {
$char = substr( $prefix, $commonPrefixLength, 1 );
$output .= $this->openList( $char );
}
$lastPrefix = $prefix2;
}
+
+ // If we have no prefixes, go to paragraph mode.
if( 0 == $prefixLength ) {
wfProfileIn( __METHOD__."-paragraph" );
# No prefix (not in list)--go to paragraph mode