Index: includes/parser/Parser.php =================================================================== --- includes/parser/Parser.php (revision 56991) +++ includes/parser/Parser.php (working copy) @@ -1087,6 +1087,7 @@ } /** + * Processes bolds and italics on a single line. * Helper function for doAllQuotes() */ public function doQuotes( $text ) { @@ -1112,18 +1113,22 @@ $arr[$i-1] .= "'"; $arr[$i] = "'''"; } - # If there are more than 5 apostrophes in a row, assume they're all - # text except for the last 5. - else if ( strlen( $arr[$i] ) > 5 ) + # If there are more than 6 apostrophes in a row, assume they're all + # text except for the last 6. + else if ( strlen( $arr[$i] ) > 6 ) { - $arr[$i-1] .= str_repeat( "'", strlen( $arr[$i] ) - 5 ); - $arr[$i] = "'''''"; + $arr[$i-1] .= str_repeat( "'", strlen( $arr[$i] ) - 6 ); + $arr[$i] = "''''''"; } # Count the number of occurrences of bold and italics mark-ups. # We are not counting sequences of five apostrophes. if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; } else if ( strlen( $arr[$i] ) == 3 ) { $numbold++; } else if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; } + else if ( strlen( $arr[$i] ) == 6 ) { + if ($numitalics&1) { $numitalics++; $numbold++; } + else $numbold+=2; + } } $i++; } @@ -1135,11 +1140,17 @@ if ( ( $numbold % 2 == 1 ) && ( $numitalics % 2 == 1 ) ) { $i = 0; + + #These are indexes to the /next/ array entry than the + #one holding the text matching the condition. $firstsingleletterword = -1; $firstmultiletterword = -1; $firstspace = -1; + foreach ( $arr as $r ) { + #Filter the "'''". Separators are on odd positions. + #$arr[0] will be an empty string if needed. if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) ) { $x1 = substr ($arr[$i-1], -1); @@ -1148,7 +1159,7 @@ if ($firstspace == -1) $firstspace = $i; } else if ($x2 === ' ') { if ($firstsingleletterword == -1) $firstsingleletterword = $i; - } else { + } else if ($arr[$i-1] != "") { if ($firstmultiletterword == -1) $firstmultiletterword = $i; } } @@ -1178,9 +1189,9 @@ } # Now let's actually convert our apostrophic mush to HTML! - $output = ''; - $buffer = ''; - $state = ''; + $output = ''; #Processed text + $buffer = ''; #Content if $state is 'both' + $state = ''; #Flags with the order of open tags: '|b|i|bi|ib|both' $i = 0; foreach ($arr as $r) { @@ -1234,6 +1245,21 @@ else # ($state == '') { $buffer = ''; $state = 'both'; } } + else if (strlen ($r) == 6) + { + if ($state === 'b') + { $output .= ''; $state = 'b'; } + else if ($state === 'i') + { $output .= '\''; $state = 'b'; } + else if ($state === 'bi') + { $output .= '\''; $state = ''; } + else if ($state === 'ib') + { $output .= '\''; $state = ''; } + else if ($state === 'both') + { $output .= ''.$buffer.''; $state = 'ib'; } + else # ($state == '') + { $buffer = ''; $state = ''; } + } } $i++; } Index: maintenance/parserTests.txt =================================================================== --- maintenance/parserTests.txt (revision 56991) +++ maintenance/parserTests.txt (working copy) @@ -5252,19 +5252,17 @@

!! end -# Original result was this: -#

boldboldbolditalics +# This was the original html, but it has also been +#

'bold'boldbolditalics #

-# While that might be marginally more intuitive, maybe, the six-apostrophe -# construct is clearly pathological and the result stated here (which is what -# the parser actually does) is about as reasonable as anything. +# See bug 18765. !!test Mixing markup for italics and bold !! options !! input '''bold''''''bold''bolditalics''''' !! result -

'bold'boldbolditalics +

boldboldbolditalics

!! end @@ -7515,6 +7513,90 @@ #section !! end +!! test +Bold/italic markup handled differently depending on leading whitespace (bug 18765) +!!input +'''Look at ''this edit'''s complicated bold/italic markup!''' + +'''Look at ''this edit'''s complicated bold/italic markup!''' + + '''Look at ''this edit'''s complicated bold/italic markup!''' + + '''Look at ''this edit'''s complicated bold/italic markup!''' + + '''Look at ''this edit'''s complicated bold/italic markup!''' + +{| +| '''Look at ''this edit'''s complicated bold/italic markup!''' +|} + +'''This was Italic'' this was plain''' and this was bold''' +but '''This is bold'' this is bold italic''' and this is bold''' + + +!! result +

Look at this edit's complicated bold/italic markup! +

Look at this edit's complicated bold/italic markup! +

Look at this edit's complicated bold/italic markup! +

Look at this edit's complicated bold/italic markup! +

+
Look at this edit's complicated bold/italic markup!
+
+ + +
Look at this edit's complicated bold/italic markup! +
+

This was Italic this was plain' and this was bold +but This is bold this is bold italic' and this is bold +


+

+!! end + +!! test +Six quotes +!!input +''Italic''''''Bold + +'''Bold''BoldItalic''''''Normal + +''Italic'''BoldItalic''''''Normal + +'''''BoldItalic''''''MoreBoldItalic'' + +''''''Normal +!!result +

Italic'Bold +

BoldBoldItalic'Normal +

ItalicBoldItalic'Normal +

BoldItalicMoreBoldItalic +

Normal +

+!!end + +!! test +Dangling apostrophe with six quotes +!!input +''Italic'''Bold''''''Normal'''Bold'''Normal +!! result +

ItalicBold'NormalBoldNormal +

+!! end + +!! test +Too many quotes +!!input +I '''like'''''quotes''''''''''' +!! result +

I likequotes'''''' +

+!! end + + TODO: more images more tables Index: RELEASE-NOTES =================================================================== --- RELEASE-NOTES (revision 56991) +++ RELEASE-NOTES (working copy) @@ -245,6 +245,8 @@ === Bug fixes in 1.16 === +* (bug 18765) Increased consistency of bold-italic markup for unbalanced quotes. + Improved representation of six quotes (may break existing markup). * (bug 18031) Make namespace selector on Special:Export remember the previous selection * The svn-version version numbers on Special:Version have been removed