From: Gabriel Wicke Date: Tue, 20 May 2014 16:14:21 +0000 (-0700) Subject: Update list item newline handling to follow Parsoid's model X-Git-Tag: 1.31.0-rc.0~15440^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=b33b5d5840fe0c59d776e78755b0c8a5e712a805;p=lhc%2Fweb%2Fwiklou.git Update list item newline handling to follow Parsoid's model This improves on commit 34bd573144883af9ace7ead32d3be8f692431718 by matching Parsoid's newline handling in the PHP parser. It is the outcome of a discussion with Erwin, where we agreed that * foo * bar should produce See the discussion in https://gerrit.wikimedia.org/r/#/c/94443/ The original rendering issue this tried to address is no longer present after a change to the template. The pure CSS solution is now working. Bug: 39617 Bug: 56809 Change-Id: Ib7aa9449bbd994cb23b83b3f23cff944b1cddadf --- diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index d2a20df971..4385dd661c 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2327,13 +2327,13 @@ class Parser { $result = $this->closeParagraph(); if ( '*' === $char ) { - $result .= ""; } elseif ( '#' === $char ) { - $text = "\n"; + $text = ""; } elseif ( ':' === $char ) { if ( $this->mDTopen ) { $this->mDTopen = false; - $text = "\n"; + $text = ""; } else { - $text = "\n"; + $text = ""; } } else { return ''; } - return $text . "\n"; + return $text; } /**#@-*/ @@ -2488,6 +2488,9 @@ class Parser { } # Open prefixes where appropriate. + if ( $lastPrefix && $prefixLength > $commonPrefixLength ) { + $output .= "\n"; + } while ( $prefixLength > $commonPrefixLength ) { $char = substr( $prefix, $commonPrefixLength, 1 ); $output .= $this->openList( $char ); @@ -2501,6 +2504,9 @@ class Parser { } ++$commonPrefixLength; } + if ( !$prefixLength && $lastPrefix ) { + $output .= "\n"; + } $lastPrefix = $prefix2; } @@ -2582,12 +2588,18 @@ class Parser { $this->mInPre = false; } if ( $paragraphStack === false ) { - $output .= $t . "\n"; + $output .= $t; + if ( $prefixLength === 0 ) { + $output .= "\n"; + } } } while ( $prefixLength ) { $output .= $this->closeList( $prefix2[$prefixLength - 1] ); --$prefixLength; + if ( !$prefixLength ) { + $output .= "\n"; + } } if ( $this->mLastSection != '' ) { $output .= 'mLastSection . '>'; diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 569c165321..941a6a0bfa 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -413,12 +413,8 @@ Simple list * Item 1 * Item 2 !! html - + !! end @@ -441,38 +437,21 @@ Italics and bold * plain l'''italic''plain * plain l''''bold''' plain !! html - + !! end @@ -1215,24 +1194,12 @@ nowiki 3 *There is not nowiki. *There is nowiki. !! html -
-
There is not nowiki. -
-
There is nowiki. -
-
-
    -
  1. There is not nowiki. -
  2. -
  3. There is nowiki. -
  4. -
- +
There is not nowiki.
+
There is nowiki.
+
  1. There is not nowiki.
  2. +
  3. There is nowiki.
+ !! end @@ -2085,10 +2052,7 @@ Templates: Strip leading and trailing whitespace from named-param values

b

c

- + !! end @@ -2129,10 +2093,7 @@ Templates: Don't strip whitespace from positional-param values


- +


g
@@ -2733,11 +2694,8 @@ Simple definition
 !! wikitext
 ; name : Definition
 !! html
-
-
name 
-
Definition -
-
+
name 
+
Definition
!! end @@ -2746,10 +2704,7 @@ Definition list for indentation only !! wikitext : Indented text !! html -
-
Indented text -
-
+
Indented text
!! end @@ -2758,11 +2713,8 @@ Definition list with no space !! wikitext ;name:Definition !! html -
-
name
-
Definition -
-
+
name
+
Definition
!!end @@ -2771,11 +2723,8 @@ Definition list with URL link !! wikitext ; http://example.com/ : definition !! html -
-
http://example.com/ 
-
definition -
-
+
http://example.com/ 
+
definition
!! end @@ -2784,11 +2733,8 @@ Definition list with bracketed URL link !! wikitext ;[http://www.example.com/ Example]:Something about it !! html -
-
Example
-
Something about it -
-
+
Example
+
Something about it
!! end @@ -2797,11 +2743,8 @@ Definition list with wikilink containing colon !! wikitext ; [[Help:FAQ]]: The least-read page on Wikipedia !! html -
-
Help:FAQ
-
The least-read page on Wikipedia -
-
+
Help:FAQ
+
The least-read page on Wikipedia
!! end @@ -2811,11 +2754,8 @@ Definition list with news link containing colon !! wikitext ; news:alt.wikipedia.rox: This isn't even a real newsgroup! !! html -
-
news:alt.wikipedia.rox
-
This isn't even a real newsgroup! -
-
+
news:alt.wikipedia.rox
+
This isn't even a real newsgroup!
!! end @@ -2824,10 +2764,7 @@ Malformed definition list with colon !! wikitext ; news:alt.wikipedia.rox -- don't crash or enter an infinite loop !! html -
-
news:alt.wikipedia.rox -- don't crash or enter an infinite loop -
-
+
news:alt.wikipedia.rox -- don't crash or enter an infinite loop
!! end @@ -2836,11 +2773,8 @@ Definition lists: colon in external link text !! wikitext ; [http://www.wikipedia2.org/ Wikipedia : The Next Generation]: OK, I made that up !! html -
-
Wikipedia : The Next Generation
-
OK, I made that up -
-
+
Wikipedia : The Next Generation
+
OK, I made that up
!! end @@ -2849,10 +2783,7 @@ Definition lists: colon in HTML attribute !! wikitext ;bold !! html -
-
bold -
-
+
bold
!! end @@ -2861,11 +2792,8 @@ Definition lists: self-closed tag !! wikitext ;one
two : two-line fun !! html -
-
one
two 
-
two-line fun -
-
+
one
two 
+
two-line fun
!! end @@ -2897,15 +2825,9 @@ Definition and unordered list using wiki syntax nested in unordered list using h !! html !! end @@ -2917,11 +2839,8 @@ Definition list with empty definition and following paragraph ; term: Paragraph text !! html -
-
term
-
-
-
+
term
+

Paragraph text

!! end @@ -2929,17 +2848,9 @@ Paragraph text !! test Nested definition lists using html syntax !! wikitext -
-
-
Foo
-
-
-!! html -
-
-
Foo
-
-
+
x
+
a
+
b
!! end @@ -2950,14 +2861,9 @@ Definition Lists: No nesting: Multiple dd's :a :b !! html -
-
x -
-
a -
-
b -
-
+
x
+
a
+
b
!! end @@ -2968,18 +2874,9 @@ Definition Lists: Indentation: Regular ::i2 :::i3 !! html -
-
i1 -
-
i2 -
-
i3 -
-
-
-
-
-
+
i1 +
i2 +
i3
!! end @@ -2989,17 +2886,8 @@ Definition Lists: Indentation: Missing 1st level ::i2 :::i3 !! html -
-
-
i2 -
-
i3 -
-
-
-
-
-
+
i2 +
i3
!! end @@ -3008,16 +2896,7 @@ Definition Lists: Indentation: Multi-level indent !! wikitext :::i3 !! html -
-
-
-
i3 -
-
-
-
-
-
+
i3
!! end @@ -3139,17 +3018,11 @@ Table / list interaction: indented table with lists in table contents a - + c - + !! end @@ -3172,27 +3045,15 @@ Table / list interaction: lists nested in tables nested in indented lists
-
-
a -
-
b -
-
+
a
+
b
-
    -
  • c -
  • -
  • d -
  • -
+
  • c
  • +
  • d
- + !!end @@ -3280,18 +3141,8 @@ Definition Lists: Nesting: Test 4 ::;t3 :::d3 !! html -
-
-
-
t3 -
-
d3 -
-
-
-
-
-
+
t3
+
d3
!! end @@ -3306,22 +3157,9 @@ Definition Lists: Mixed Lists: Test 1 ::* bar :; baz !! html/php -
-
-
    -
  • foo -
  • -
  • bar -
  • -
-
-
-
-
baz -
-
-
-
+
  • foo
  • +
  • bar
+
baz
!! html/parsoid
@@ -3345,15 +3183,8 @@ Definition Lists: Mixed Lists: Test 2 *: d1 *: d2 !! html -
    -
  • -
    d1 -
    -
    d2 -
    -
    -
  • -
+
  • d1
    +
    d2
!! end @@ -3364,21 +3195,8 @@ Definition Lists: Mixed Lists: Test 3 *::: d1 *::: d2 !! html -
    -
  • -
    -
    -
    d1 -
    -
    d2 -
    -
    -
    -
    -
    -
    -
  • -
+
  • d1
    +
    d2
!! end @@ -3389,17 +3207,10 @@ Definition Lists: Mixed Lists: Test 4 *;d1 :d2 *;d3 :d4 !! html -
    -
  • -
    d1 
    -
    d2 -
    +
    • d1 
      +
      d2
      d3 
      -
      d4 -
      -
      -
    • -
    +
    d4
!! end @@ -3410,17 +3221,8 @@ Definition Lists: Mixed Lists: Test 5 *:d1 *:: d2 !! html -
    -
  • -
    d1 -
    -
    d2 -
    -
    -
    -
    -
  • -
+
  • d1 +
    d2
!! end @@ -3431,23 +3233,8 @@ Definition Lists: Mixed Lists: Test 6 #*:d1 #*::: d3 !! html -
    -
    • -
    • -
      d1 -
      -
      -
      d3 -
      -
      -
      -
      -
      -
      -
    • -
    -
  1. -
+
    • d1 +
      d3
!! end @@ -3458,15 +3245,8 @@ Definition Lists: Mixed Lists: Test 7 :* d1 :* d2 !! html -
-
    -
  • d1 -
  • -
  • d2 -
  • -
-
-
+
  • d1
  • +
  • d2
!! end @@ -3477,20 +3257,8 @@ Definition Lists: Mixed Lists: Test 8 :* d1 ::* d2 !! html -
-
    -
  • d1 -
  • -
-
-
    -
  • d2 -
  • -
-
-
-
-
+
  • d1
+
  • d2
!! end @@ -3500,14 +3268,8 @@ Definition Lists: Mixed Lists: Test 9 !! wikitext *;foo :bar !! html -
    -
  • -
    foo 
    -
    bar -
    -
    -
  • -
+
  • foo 
    +
    bar
!! end @@ -3517,17 +3279,8 @@ Definition Lists: Mixed Lists: Test 10 !! wikitext *#;foo :bar !! html -
    -
    1. -
    2. -
      foo 
      -
      bar -
      -
      -
    3. -
    -
  • -
+
    1. foo 
      +
      bar
!! end @@ -3542,37 +3295,10 @@ Definition Lists: Mixed Lists: Test 11 *#*#;*;;foo :bar *#*#;boo :baz !! html/php -
    -
    1. -
      • -
        1. -
        2. -
          foo 
          -
            -
          • -
            -
            bar -
            -
            -
          -
          -
        3. -
      - -
-
-
boo 
-
baz -
-
- - - - - - - - + !! html/parsoid + !! html/parsoid