X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FParser.php;h=b66031cc8804169f36aed386e585006a781ded2e;hb=80db2d4b9924eb41e1bbf220809d30d46a9ba23a;hp=8e5dcbdab18d9c933563edafa79ecff43c944a47;hpb=12ff4dec05ff8bb1a1910bf6745155b93e1912b5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 8e5dcbdab1..b66031cc88 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1113,7 +1113,11 @@ class Parser { $line = "{$line}"; } array_pop( $tr_attributes ); - $outLine = $line . str_repeat( '', $indent_level ); + if ( $indent_level > 0 ) { + $outLine = rtrim( $line ) . str_repeat( '', $indent_level ); + } else { + $outLine = $line; + } } elseif ( $first_two === '|-' ) { # Now we have a table row $line = preg_replace( '#^\|-+#', '', $line ); @@ -1204,13 +1208,15 @@ class Parser { # be mistaken as delimiting cell parameters # Bug T153140: Neither should language converter markup. if ( preg_match( '/\[\[|-\{/', $cell_data[0] ) === 1 ) { - $cell = "{$previous}<{$last_tag}>{$cell}"; + $cell = "{$previous}<{$last_tag}>" . trim( $cell ); } elseif ( count( $cell_data ) == 1 ) { - $cell = "{$previous}<{$last_tag}>{$cell_data[0]}"; + // Whitespace in cells is trimmed + $cell = "{$previous}<{$last_tag}>" . trim( $cell_data[0] ); } else { $attributes = $this->mStripState->unstripBoth( $cell_data[0] ); $attributes = Sanitizer::fixTagAttributes( $attributes, $last_tag ); - $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}"; + // Whitespace in cells is trimmed + $cell = "{$previous}<{$last_tag}{$attributes}>" . trim( $cell_data[1] ); } $outLine .= $cell; @@ -1465,7 +1471,7 @@ class Parser { /** * @throws MWException * @param array $m - * @return HTML|string + * @return string HTML */ public function magicLinkCallback( $m ) { if ( isset( $m[1] ) && $m[1] !== '' ) { @@ -1617,7 +1623,9 @@ class Parser { public function doHeadings( $text ) { for ( $i = 6; $i >= 1; --$i ) { $h = str_repeat( '=', $i ); - $text = preg_replace( "/^$h(.+)$h\\s*$/m", "\\1", $text ); + // Trim non-newline whitespace from headings + // Using \s* will break for: "==\n===\n" and parse as

=

+ $text = preg_replace( "/^(?:$h)[ \\t]*(.+?)[ \\t]*(?:$h)\\s*$/m", "\\1", $text ); } return $text; } @@ -1868,8 +1876,8 @@ class Parser { $dtrail = ''; - # Set linktype for CSS - if URL==text, link is essentially free - $linktype = ( $text === $url ) ? 'free' : 'text'; + # Set linktype for CSS + $linktype = 'text'; # No link text, e.g. [http://domain.tld/some.link] if ( $text == '' ) { @@ -4050,9 +4058,11 @@ class Parser { # Get all headlines for numbering them and adding funky stuff like [edit] # links - this is for later, but we need the number of headlines right now + # NOTE: white space in headings have been trimmed in doHeadings. They shouldn't + # be trimmed here since whitespace in HTML headings is significant. $matches = []; $numMatches = preg_match_all( - '/[1-6])(?P.*?>)\s*(?P
[\s\S]*?)\s*<\/H[1-6] *>/i', + '/[1-6])(?P.*?>)(?P
[\s\S]*?)<\/H[1-6] *>/i', $text, $matches );