RFC T157418: Trim whitespace in table cells, list items, headings
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 8e5dcbd..e545887 100644 (file)
@@ -1113,7 +1113,11 @@ class Parser {
                                        $line = "</{$last_tag}>{$line}";
                                }
                                array_pop( $tr_attributes );
-                               $outLine = $line . str_repeat( '</dd></dl>', $indent_level );
+                               if ( $indent_level > 0 ) {
+                                       $outLine = rtrim( $line ) . str_repeat( '</dd></dl>', $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;
@@ -1868,8 +1874,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,6 +4056,7 @@ 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
+               # This regexp also trims whitespace in the heading's content
                $matches = [];
                $numMatches = preg_match_all(
                        '/<H(?P<level>[1-6])(?P<attrib>.*?>)\s*(?P<header>[\s\S]*?)\s*<\/H[1-6] *>/i',