Index: skins/chick/main.css =================================================================== --- skins/chick/main.css (revision 105869) +++ skins/chick/main.css (working copy) @@ -27,12 +27,12 @@ border: none; vertical-align: middle; } -p { +p, div.paragraph { margin: 0.4em 0em 0.5em 0em; line-height: 1.5em; } -p img { margin: 0; } +p img, div.paragraph img { margin: 0; } hr { height: 1px; @@ -189,7 +189,7 @@ font-size: 95%; padding: 0 0.9em 0 0.9em; } -#siteNotice p { margin: 0; padding: 0; } +#siteNotice p, div.paragraph { margin: 0; padding: 0; } .error { color: red; font-size: larger; @@ -240,13 +240,13 @@ border: 0.5em solid white; border-width: 0.5em 0 0.8em 1.4em; } -div.floatright p { font-style: italic; } +div.floatright p, div.floatright div.paragraph { font-style: italic; } /* @noflip */div.floatleft, table.floatleft { margin: 0.3em 0.5em 0.5em 0; border: 0.5em solid white; border-width: 0.5em 1.4em 0.8em 0; } -div.floatleft p { font-style: italic; } +div.floatleft p, div.floatleft div.paragraph { font-style: italic; } /* thumbnails */ div.thumb { margin-bottom: 0.5em; Index: skins/nostalgia/screen.css =================================================================== --- skins/nostalgia/screen.css (revision 105869) +++ skins/nostalgia/screen.css (working copy) @@ -43,7 +43,7 @@ overflow: auto; } -p.subtitle { +p.subtitle, div.paragraph.subtitle { padding-top: 0; margin-top: 0; } Index: skins/monobook/main.css =================================================================== --- skins/monobook/main.css (revision 105869) +++ skins/monobook/main.css (working copy) @@ -98,7 +98,7 @@ #localNotice { margin: 0; } -#siteNotice p { +#siteNotice p, #siteNotice div.paragraph { margin: 0; padding: 0; } @@ -843,7 +843,7 @@ padding: 2px; } -#powersearch p { +#powersearch p, #powersearch div.paragraph { margin-top:0px; } Index: skins/modern/main.css =================================================================== --- skins/modern/main.css (revision 105869) +++ skins/modern/main.css (working copy) @@ -282,7 +282,7 @@ display: none; } -p { +p, div.paragraph { margin: 1em 0 1em 0; } @@ -477,14 +477,14 @@ margin: 0 0 .5em .5em; border: 0; } -div.floatright p { +div.floatright p, div.floatright div.paragraph { font-style: italic; } /* @noflip */div.floatleft, table.floatleft { margin: 0 .5em .5em 0; border: 0; } -div.floatleft p { +div.floatleft p, div.floatleft div.paragraph { font-style: italic; } @@ -646,7 +646,7 @@ margin-bottom: 1em; } -.previewnote p { +.previewnote p, .previewnote div.paragraph { margin: 0; padding: 0; } @@ -833,7 +833,7 @@ background: url(footer-grad.png) repeat-x bottom left; } -.mw-topbox p { +.mw-topbox p, .mw-topbox div.paragraph { padding: 0 0 0 0; margin: 0 0 0 0; } Index: skins/common/oldshared.css =================================================================== --- skins/common/oldshared.css (revision 105869) +++ skins/common/oldshared.css (working copy) @@ -39,7 +39,7 @@ } /* @noflip */ -div.floatright p { +div.floatright p, div.floatright div.paragraph { font-style: italic; } @@ -51,7 +51,7 @@ } /* @noflip */ -div.floatleft p { +div.floatleft p, div.floatleft div.paragraph { font-style: italic; } Index: skins/common/commonPrint.css =================================================================== --- skins/common/commonPrint.css (revision 105869) +++ skins/common/commonPrint.css (working copy) @@ -26,7 +26,8 @@ position: relative; margin: 0.5em 0 0.8em 1.4em; } -div.floatright p { +div.floatright p, +div.floatright div.paragraph { font-style: italic; } div.floatleft { @@ -35,7 +36,8 @@ position: relative; margin: 0.5em 1.4em 0.8em 0; } -div.floatleft p { +div.floatleft p, +div.floatleft div.paragraph { font-style: italic; } div.center { @@ -152,7 +154,7 @@ font-weight: bold; } -p { +p, div.paragraph { margin: 1em 0; line-height: 1.2em; } @@ -351,7 +353,7 @@ h2, h3, h4, h5, h6, h7 { page-break-after: avoid; } -p { +p, div.paragraph { widows: 3; orphans: 3; } Index: skins/common/shared.css =================================================================== --- skins/common/shared.css (revision 105869) +++ skins/common/shared.css (working copy) @@ -318,7 +318,12 @@ p.mw-protect-editreasons, p.mw-filedelete-editreasons, p.mw-delete-editreasons, -p.mw-revdel-editreasons { +p.mw-revdel-editreasons, +div.paragraph.mw-ipb-conveniencelinks, +div.paragraph.mw-protect-editreasons, +div.paragraph.mw-filedelete-editreasons, +div.paragraph.mw-delete-editreasons, +div.paragraph.mw-revdel-editreasons { font-size: 90%; text-align: right; } @@ -562,7 +567,8 @@ margin-bottom: 1em; } -.previewnote p { +.previewnote p, +.previewnote div.paragraph { text-indent: 3em; margin: 0.8em 0; } Index: skins/common/wikistandard.css =================================================================== --- skins/common/wikistandard.css (revision 105869) +++ skins/common/wikistandard.css (working copy) @@ -152,11 +152,13 @@ background-color: gray; } -p.subpages { +p.subpages, +div.paragraph.subpages { font-size: small; } -p.subtitle { +p.subtitle, +div.paragraph.subtitle { padding-top: 0; margin-top: 0; } Index: skins/simple/main.css =================================================================== --- skins/simple/main.css (revision 105869) +++ skins/simple/main.css (working copy) @@ -102,11 +102,11 @@ img { border: none; } -p { +p, div.paragraph { margin: 0.4em 0em 0.5em 0em; line-height: 1.5em; } -p img { +p img, div.paragraph img { margin: 0; } @@ -290,14 +290,14 @@ margin: 0; border-width: 0.5em 0 0.8em 1.4em; } -div.floatright p { +div.floatright p, div.floatright div.paragraph { font-style: italic; } /* @noflip */div.floatleft, table.floatleft { margin: 0.3em 0.5em 0.5em 0; border-width: 0.5em 1.4em 0.8em 0; } -div.floatleft p { +div.floatleft p, div.floatleft div.paragraph { font-style: italic; } Index: skins/cologneblue/screen.css =================================================================== --- skins/cologneblue/screen.css (revision 105869) +++ skins/cologneblue/screen.css (working copy) @@ -39,20 +39,20 @@ z-index: 99; } -#article, #article td, #article th, #article p { +#article, #article td, #article th, #article p, #article div.paragraph { font-family: Verdana, Arial, sans-serif; font-size: 10pt; color: black; } -#article p { +#article p, #article div.paragraph { padding-top: 0; padding-bottom: 0; margin-top: 1ex; margin-bottom: 0; } -p, pre, td, th, li, dd, dt { +p, div.paragraph, pre, td, th, li, dd, dt { line-height: 12pt; } @@ -182,7 +182,7 @@ margin-bottom: 0; } -#article p.subtitle { +#article p.subtitle, #article div.paragraph { color: #666666; font-size: 11pt; font-weight: bold; Index: tests/parser/parserTests.txt =================================================================== --- tests/parser/parserTests.txt (revision 105869) +++ tests/parser/parserTests.txt (working copy) @@ -198,7 +198,6 @@ !! result
asdf
 
- !! end !! test @@ -243,11 +242,9 @@ c !! result

a +

 b 
+

c

-
 b 
-
-

c -

!! end !! test @@ -371,8 +368,7 @@ !! result
Blah
-
-
+ !! end @@ -386,8 +382,8 @@ !! result
- Blah -
+
Blah
+
!! end @@ -2056,8 +2052,8 @@ !! result

-foo
bar - +

foo


bar +

!! end ### @@ -2759,8 +2755,8 @@ {{paramtest| param =[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]}} !! result -This is a test template with parameter
File:Noimage.png
- +
This is a test template with parameter
+
!! end !! article @@ -2897,8 +2893,7 @@ foo {{table}} !! result

foo -

- +

1 2 @@ -2917,8 +2912,7 @@ {{table}} !! result

foo -

- +

1 2 @@ -4130,11 +4124,9 @@ !! result

[edit] Headline 1

Some text -

-

[edit] Headline 2

+

[edit] Headline 2

More -

-

[edit] Smaller headline

+

[edit] Smaller headline

Blah blah

!! end @@ -4179,8 +4171,7 @@
[edit] Skipping a level

[edit] Headline 2

Some text -

-

[edit] Another headline

+

[edit] Another headline

!! end @@ -4454,8 +4445,7 @@ !! result

[edit] =

The line above must have a trailing space! -

-

[edit] =

+

[edit] =

But just in case it doesn't...

!! end @@ -4481,8 +4471,7 @@ section 5 !! result

The tooltips shall not show entities to the user (ie. be double escaped) -

-

Contents

+

Contents

[edit] text > text

section 1 -

-

[edit] text < text

+

[edit] text < text

section 2 -

-

[edit] text & text

+

[edit] text & text

section 3 -

-

[edit] text ' text

+

[edit] text ' text

section 4 -

-

[edit] text " text

+

[edit] text " text

section 5

!! end @@ -4681,8 +4666,8 @@ !! input [[Media:Foobar.jpg|Safe Link
" onmouseover="alert(document.cookie)" onfoo="
]] !! result -Safe Link<div style="display:none">" onmouseover="alert(document.cookie)" onfoo="</div> - + !! end !! test @@ -5220,8 +5205,8 @@ string(5) "" array(0) { } -</tag> - +

</tag> +

!! end !! test @@ -5271,8 +5256,8 @@ ["foo"]=> string(3) "bar" } -text - +

text +

!! end #
should be output literally since there is no matching tag that begins it @@ -5322,8 +5307,7 @@ !! result -


-

+


!! end # Nested template calls; this case was broken by Parser.php rev 1.506, @@ -5359,7 +5343,7 @@ !! input
!! result -
+

!! end @@ -5705,7 +5689,7 @@ http://__TOC__ !! result

[edit] onmouseover=

-http://

Contents

+

http://

Contents

@@ -5773,8 +5757,7 @@ {| !!result

http://===r:::https://b -

- +

@@ -5796,12 +5779,11 @@ | !! result -{{{| +

{{{| }}}} >
- -MOVE YOUR MOUSE CURSOR OVER THIS TEXT -

+

MOVE YOUR MOUSE CURSOR OVER THIS TEXT +

@@ -5856,7 +5838,7 @@ !! input http://example.com
junk
!! result -http://example.com
junk
+

http://example.com

junk
!!end @@ -5987,9 +5969,7 @@ !! input {{Special:Prefixindex/Xyzzyx}} !! result -


-

-
Xyzzyx
+


Xyzzyx
!! end @@ -6000,12 +5980,8 @@ {{Special:Prefixindex/Xyzzyx}} {{Special:Prefixindex/Xyzzyx}} !! result -


-

-
Xyzzyx
-


-

-
Xyzzyx
+


Xyzzyx
+


Xyzzyx
!! end @@ -6935,13 +6911,9 @@
  • Talk:Parser_test
  • Parser test
  • Parser_test -
  • -
  • +
  • Talk
  • Talk -
  • Talk -
  • -
  • -
  • Template:Dynamic +
  • Template:Dynamic
  • !! end @@ -6971,8 +6943,7 @@
    Image2.gif

    |||| -

    -
    +

  • Image3
    @@ -6983,15 +6954,13 @@
    Image4

    300px| centre -

    -
    +

  • Image5.svg
    +

  • * image6
    @@ -7019,8 +6988,7 @@
    Nonexistant.jpg

    caption -

    -
    +

  • Nonexistant.jpg
    @@ -7031,8 +6999,7 @@

    some caption Main Page -

    -
    +

  • Foobar.jpg
    @@ -7043,8 +7010,7 @@
    This is a foo-bar.

    Blabla|blabla. -

    -
    +

  • @@ -7063,15 +7029,13 @@
    galleryalt

    inneralt -

    -
    +

  • galleryalt

    This is a test template -

    -
    +

  • @@ -7093,30 +7057,26 @@

    Nonexistant.jpg
    caption -

    -
    +

  • Nonexistant.jpg
    +

  • Foobar.jpg
    some caption Main Page -

    -
    +

  • Foobar.jpg
    +

  • @@ -7190,8 +7150,7 @@ __NEWSECTIONLINK__ __FORCETOC__ !! result -


    -

    +


    !! end !! test @@ -7669,14 +7628,16 @@ baz !! result
    -foo -
    +

    foo +

    bar -

    -
    baz
    +

    baz
     
    !! end +------- +------- + !! test Bug 8293: Use of center tag ruins paragraph formatting !! input @@ -7690,11 +7651,9 @@ !! result

    foo -

    -
    +

    bar -

    -
    baz
    +

    baz
     
    !! end @@ -8006,8 +7965,7 @@ y !! result

    x -

    - +

    1 2 @@ -8082,8 +8040,7 @@ ==heading== !! result

    [[link -

    -

    [edit] heading

    +

    [edit] heading

    !! end @@ -8094,8 +8051,7 @@ =heading= !! result

    {{foo| -

    -

    heading

    +

    heading

    !! end @@ -8106,8 +8062,7 @@ ==heading== !! result

    {{foo| -

    -

    [edit] heading

    +

    [edit] heading

    !! end @@ -8129,7 +8084,7 @@ Line two !! result
    Line one -Line two
    +

    Line two

    !! end @@ -8143,8 +8098,7 @@ !! result

    Line one -

    -Line two
    +

    Line two

    !! end @@ -8158,8 +8112,7 @@ !! result
    Line one

    Line two -

    -
    +

    !! end @@ -8175,8 +8128,7 @@

    Line one

    Line two -

    -
    +

    !! end @@ -8197,11 +8149,8 @@ # Bug 6200:
    should behave like
    with respect to line breaks !! test Bug 6200: paragraphs inside blockquotes (no extra line breaks) -!! options -disabled !! input
    Line one - Line two
    !! result
    Line one @@ -8211,8 +8160,6 @@ !! test Bug 6200: paragraphs inside blockquotes (extra line break on open) -!! options -disabled !! input
    Line one @@ -8221,15 +8168,12 @@ !! result

    Line one -

    -Line two
    +

    Line two

    !! end !! test Bug 6200: paragraphs inside blockquotes (extra line break on close) -!! options -disabled !! input
    Line one @@ -8238,15 +8182,12 @@ !! result
    Line one

    Line two -

    -
    +

    !! end !! test Bug 6200: paragraphs inside blockquotes (extra line break on open and close) -!! options -disabled !! input
    Line one @@ -8257,8 +8198,7 @@

    Line one

    Line two -

    -
    +

    !! end @@ -8270,7 +8210,7 @@ Line two
    !! result
    Line one -Line two
    +

    Line two

    !! end @@ -8284,8 +8224,7 @@ !! result

    Line one -

    -Line two
    +

    Line two

    !! end @@ -8299,8 +8238,7 @@ !! result
    Line one

    Line two -

    -
    +

    !! end @@ -8316,8 +8254,7 @@

    Line one

    Line two -

    -
    +

    !! end @@ -8774,8 +8711,7 @@

    Quuz

    !! result

    Baz -

    -

    Quuz

    +

    Quuz

    !! end Index: includes/parser/Parser.php =================================================================== --- includes/parser/Parser.php (revision 105869) +++ includes/parser/Parser.php (working copy) @@ -2030,7 +2030,7 @@ * @return Boolean */ function areSubpagesAllowed() { - # Some namespaces don't allow subpages + // Some namespaces don't allow subpages return MWNamespace::hasSubpages( $this->mTitle->getNamespace() ); } @@ -2055,7 +2055,7 @@ function closeParagraph() { $result = ''; if ( $this->mLastSection != '' ) { - $result = 'mLastSection . ">\n"; + $result = 'mLastSection . ">"; } $this->mInPre = false; $this->mLastSection = ''; @@ -2185,16 +2185,69 @@ $textLines = StringUtils::explode( "\n", $text ); $lastPrefix = $output = ''; - $this->mDTopen = $inBlockElem = false; + $this->mDTopen = false; $prefixLength = 0; - $paragraphStack = false; + // 0 = always start paragraph for a piece of text or inline tag + // 1 = some text of current paragraph already printed inline, + // so persist 1 across newline and print text from there inline also + // 2 = print text inline if there is some, but reset to 0 at newline if not + $dontStartParagraph = 0; + + // the output position of last paragraph start + $lastParagraphPos = NULL; + + // 'p' = inside a paragraph + // 'div' = inside a
    + // 'pre' = inside preformatted lines (with space at beginning) + $this->mLastSection = ''; + + // true = inside a
     tag
    +		$this->mInPre = false;
    +
    +		// > 0   = inside a $noPre tag
    +		$inNoPre = 0;
    +
    +		// 
    can itself contain paragraphs, so this is a stack of them + $nestedSections = array(); + + // empty lines counter + $emptyLines = 0; + + // Block elements force to close current paragraph + $closesParagraph = array( + 'div' => 1, + 'center' => 1, + 'table' => 1, + 'caption' => 1, + 'tr' => 1, + 'td' => 1, + 'th' => 1, + 'h1' => 1, + 'h2' => 1, + 'h3' => 1, + 'h4' => 1, + 'h5' => 1, + 'h6' => 1, + 'hr' => 1, + 'ul' => 1, + 'ol' => 1, + 'li' => 1, + 'pre' => 1, + 'p' => 1, + 'blockquote' => 1, + 'script' => 1, + ); + + // These elements disallow preformatting by adding space at the beginning of line + $noPre = array( + 'table' => 1, + 'pre' => 1, + ); + foreach ( $textLines as $oLine ) { - # Fix up $linestart if ( !$linestart ) { - $output .= $oLine; - $linestart = true; - continue; + $dontStartParagraph = 1; } # * = ul # # = ol @@ -2202,11 +2255,9 @@ # : = dd $lastPrefixLength = strlen( $lastPrefix ); - $preCloseMatch = preg_match( '/<\\/pre/i', $oLine ); - $preOpenMatch = preg_match( '/
     element, scan for and figure out what prefixes are there.
    -			if ( !$this->mInPre ) {
    -				# Multiple prefixes may abut each other for nested lists.
    +			// If at line start and not in a 
     element, scan for and figure out what prefixes are there.
    +			if ( $linestart && !$this->mInPre ) {
    +				// Multiple prefixes may abut each other for nested lists.
     				$prefixLength = strspn( $oLine, '*#:;' );
     				$prefix = substr( $oLine, 0, $prefixLength );
     
    @@ -2216,7 +2267,6 @@
     				#  elements.
     				$prefix2 = str_replace( ';', ':', $prefix );
     				$t = substr( $oLine, $prefixLength );
    -				$this->mInPre = (bool)$preOpenMatch;
     			} else {
     				# Don't interpret any other prefixes in preformatted text
     				$prefixLength = 0;
    @@ -2227,8 +2277,9 @@
     			# List generation
     			if ( $prefixLength && $lastPrefix === $prefix2 ) {
     				# Same as the last item, so no need to deal with nesting or opening stuff
    +				$output .= $this->closeParagraph();
    +				$dontStartParagraph = 2;
     				$output .= $this->nextItem( substr( $prefix, -1 ) );
    -				$paragraphStack = false;
     
     				if ( substr( $prefix, -1 ) === ';') {
     					# The one nasty exception: definition lists work like this:
    @@ -2241,12 +2292,17 @@
     						$output .= $term . $this->nextItem( ':' );
     					}
     				}
    +
    +				// Reset linestart to false to ignore heading space
    +				$linestart = false;
    +				$emptyLines = 0;
     			} elseif ( $prefixLength || $lastPrefixLength ) {
    +				$output .= $this->closeParagraph();
    +				$dontStartParagraph = $prefixLength ? 2 : 0;
     				# 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 ) {
    @@ -2274,71 +2330,148 @@
     					++$commonPrefixLength;
     				}
     				$lastPrefix = $prefix2;
    +
    +				// Reset linestart to false to ignore heading space
    +				$linestart = !$prefixLength;
    +				$emptyLines = 0;
     			}
     
    -			# If we have no prefixes, go to paragraph mode.
    -			if ( 0 == $prefixLength ) {
    -				wfProfileIn( __METHOD__."-paragraph" );
    -				# No prefix (not in list)--go to paragraph mode
    -				# XXX: use a stack for nestable elements like span, table and div
    -				$openmatch = preg_match('/(?:mUniqPrefix.'-pre|<\\/li|<\\/ul|<\\/ol|<\\/?center)/iS', $t );
    -				if ( $openmatch or $closematch ) {
    -					$paragraphStack = false;
    -					# TODO bug 5718: paragraph closed
    -					$output .= $this->closeParagraph();
    -					if ( $preOpenMatch and !$preCloseMatch ) {
    -						$this->mInPre = true;
    -					}
    -					$inBlockElem = !$closematch;
    -				} elseif ( !$inBlockElem && !$this->mInPre ) {
    -					if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' || trim( $t ) != '' ) ) {
    -						# pre
    -						if ( $this->mLastSection !== 'pre' ) {
    -							$paragraphStack = false;
    -							$output .= $this->closeParagraph().'
    ';
    -							$this->mLastSection = 'pre';
    +			// Go to paragraph mode.
    +			wfProfileIn( __METHOD__."-paragraph" );
    +			if ( $linestart && $inNoPre <= 0 && ' ' == substr( $t, 0, 1 ) &&
    +				( $this->mLastSection === 'pre' || trim( $t ) != '' ) ) {
    +				// 
    formatted text
    +				$emptyLines = 0;
    +				if ( $this->mLastSection !== 'pre' ) {
    +					$output .= $this->closeParagraph().'
    ';
    +					$this->mLastSection = 'pre';
    +				}
    +				$output .= substr( $t, 1 ) . "\n";
    +			} elseif ( !$this->mInPre && trim( $t ) === '' ) {
    +				// close paragraph
    +				$output .= $this->closeParagraph();
    +				$dontStartParagraph = 0;
    +				$emptyLines++;
    +				if ( $emptyLines > 1 ) {
    +					// start a new paragraph
    +					$lastParagraphPos = strlen( $output );
    +					$this->mLastSection = 'p';
    +					$output .= '


    '; + $emptyLines = 0; + } + } else { + $emptyLines = 0; + while ( strlen( $t ) ) { + // match html tag or preformatted block hidden by link holder + // does not influence on paragraphs in any way, so we don't match it + if ( preg_match('/<(\/?)([a-z][a-z0-9]*).*?(\/?)>|('.$this->mUniqPrefix. + '-pre.*?'.self::MARKER_SUFFIX.')/iS', $t, $m, PREG_OFFSET_CAPTURE ) ) { + $textBefore = substr( $t, 0, $m[0][1] ); + $t = substr( $t, $m[0][1] + strlen( $m[0][0] ) ); + if ( $m[2][0] && !$closesParagraph[ $m[2][0] ] ) { + $textBefore .= $m[0][0]; + $m[0][0] = ''; } - $t = substr( $t, 1 ); } else { - # paragraph - if ( trim( $t ) === '' ) { - if ( $paragraphStack ) { - $output .= $paragraphStack.'
    '; - $paragraphStack = false; - $this->mLastSection = 'p'; - } else { - if ( $this->mLastSection !== 'p' ) { + $textBefore = $t; + $t = ''; + } + $match = $m[0][0]; + $close = $m[1][0]; + $tag = $m[2][0]; + $empty = $m[3][0]; + $uniq = $m[4][0]; + if ( $textBefore !== '' ) { + // Here is the place where the text gets inside

    aragraphs + if ( trim( $textBefore ) !== '' ) { + if ( !$this->mInPre && !$dontStartParagraph ) { + if ( $this->mLastSection == 'pre' ) { $output .= $this->closeParagraph(); - $this->mLastSection = ''; - $paragraphStack = '

    '; - } else { - $paragraphStack = '

    '; } + if ( !$this->mLastSection && !$this->mInPre ) { + $lastParagraphPos = strlen( $output ); + $output .= '

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

    '; - $this->mLastSection = 'p'; + elseif ( $dontStartParagraph == 2 ) { + $dontStartParagraph = 1; } } + $output .= $textBefore; } + if ( $this->mInPre && $close && $tag == 'pre' ) { + // this is

    closing tag + $this->mInPre = false; + $inNoPre--; + } elseif ( $uniq ) { + // UNIQ
     closes paragraph
    +						$output .= $this->closeParagraph();
    +					} elseif ( $closesParagraph[ $tag ] ) {
    +						// block element closes current paragraph
    +						if ( $tag != 'div' ) {
    +							// 
    does not close the paragraph, + // but turns it into a
    + $output .= $this->closeParagraph(); + } elseif ( !$empty ) { + //
    is the only case of nested "paragraphs" + if ( $close ) { + //
    - close current nesting level + $output .= $this->closeParagraph(); + list( $this->mLastSection, $inNoPre ) = array_pop( $nestedSections ); + } else { + //
    - start a nested level + if ( $this->mLastSection == 'p' && $tag == 'div' ) { + //
    can not be used inside

    + // so turn last

    into a

    + $output = + substr( $output, 0, $lastParagraphPos ) . + '
    ' . + substr( $output, $lastParagraphPos+3 ); + $this->mLastSection = 'div'; + } + $nestedSections[] = array( $this->mLastSection, $inNoPre ); + $this->mLastSection = ''; + $inNoPre = 0; + } + } + // if not an enclosed XML element + if ( !$empty ) { + if ( $noPre[ $tag ] ) { + $inNoPre += $close ? -1 : 1; + } + if ( !$close ) { + if ( !$this->mLastSection ) { + // do not start paragraph right after opening block + // element tag on the same line. I.e.
    A
    is parsed + // into
    A
    , and
    \nA
    is parsed + // into

    A

    + $dontStartParagraph = 2; + } + if ( $tag == 'pre' && !$empty ) { + $this->mInPre = true; + } + } elseif ( $dontStartParagraph ) { + // Current block element is closed + $dontStartParagraph = 2; + } + } + } + if ( $match !== '' ) { + $output .= $match; + } } - wfProfileOut( __METHOD__."-paragraph" ); + $output .= "\n"; + // If line ended after opening block element tag with no text after it + // => allow to start a paragraph from next line + // If there was some text (dontStartParagraph == 1) + // => do not start a paragraph from next line + if ( $dontStartParagraph == 2 ) { + $dontStartParagraph = 0; + } } - # somewhere above we forget to get out of pre block (bug 785) - if ( $preCloseMatch && $this->mInPre ) { - $this->mInPre = false; - } - if ( $paragraphStack === false ) { - $output .= $t."\n"; - } + wfProfileOut( __METHOD__."-paragraph" ); + $linestart = true; } while ( $prefixLength ) { $output .= $this->closeList( $prefix2[$prefixLength-1] );