(bug 40306) Only convert align to float for table.
authorAntoine Musso <hashar@free.fr>
Mon, 17 Sep 2012 20:16:34 +0000 (22:16 +0200)
committerAntoine Musso <hashar@free.fr>
Tue, 18 Sep 2012 12:44:50 +0000 (14:44 +0200)
Align should be converted to text-align for all the elements specified
in $presentationalAttribs mapping. Table however is an exception, it
applies to alignment of the block (instead of the content).

Follow up I108cbd10 / 27a4d74bd7.

Change-Id: Iee17d4ef1a6a9b46d88a330cfc9179bccfe93247

includes/Sanitizer.php
tests/phpunit/includes/SanitizerTest.php

index 734c4ec..224b2d1 100644 (file)
@@ -692,7 +692,9 @@ class Sanitizer {
                                }
                        }
 
-                       if ( $attribute === 'align' && !in_array( $element, $cells ) ) {
+                       // Table align is special, it's about block alignment instead of
+                       // content align (see also bug 40306)
+                       if ( $attribute === 'align' && in_array( $element, $table ) ) {
                                if ( $value === 'center' ) {
                                        $style .= ' margin-left: auto;';
                                        $property = 'margin-right';
index c929989..d67f905 100644 (file)
@@ -136,10 +136,26 @@ class SanitizerTest extends MediaWikiTestCase {
                        array( 'nowrap=""', 'td', ' style="white-space: nowrap;"', 'nowrap="" is considered true, not false' ),
                        array( 'NOWRAP="true"', 'td', ' style="white-space: nowrap;"', 'nowrap attribute works when uppercase.' ),
                        array( 'NoWrAp="true"', 'td', ' style="white-space: nowrap;"', 'nowrap attribute works when mixed-case.' ),
-                       array( 'align="right"', 'td', ' style="text-align: right;"', 'align on table cells gets converted to text-align' ),
-                       array( 'align="center"', 'td', ' style="text-align: center;"', 'align on table cells gets converted to text-align' ),
-                       array( 'align="left"', 'div', ' style="float: left;"', 'align=(left|right) on non-cells gets converted to float' ),
-                       array( 'align="center"', 'div', ' style="margin-left: auto; margin-right: auto;"', 'align="center" on non-cells' ),
+                       array( 'align="right"', 'td', ' style="text-align: right;"'   , 'align on table cells gets converted to text-align' ),
+                       array( 'align="center"', 'td', ' style="text-align: center;"' , 'align on table cells gets converted to text-align' ),
+                       array( 'align="left"'  , 'div', ' style="text-align: left;"'  , 'align=(left|right) on div elements gets converted to text-align' ),
+                       array( 'align="center"', 'div', ' style="text-align: center;"', 'align="center" on div elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'p',   ' style="text-align: left;"'  , 'align on p elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'h1',  ' style="text-align: left;"'  , 'align on h1 elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'h1',  ' style="text-align: left;"'  , 'align on h1 elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'caption',' style="text-align: left;"','align on caption elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'tfoot',' style="text-align: left;"' , 'align on tfoot elements gets converted to text-align' ),
+                       array( 'align="left"'  , 'tbody',' style="text-align: left;"' , 'align on tbody elements gets converted to text-align' ),
+
+                       # <tr>
+                       array( 'align="right"' , 'tr', ' style="text-align: right;"' , 'align on table row get converted to text-align' ),
+                       array( 'align="center"', 'tr', ' style="text-align: center;"', 'align on table row get converted to text-align' ),
+                       array( 'align="left"'  , 'tr', ' style="text-align: left;"'  , 'align on table row get converted to text-align' ),
+
+                       #table
+                       array( 'align="left"'  , 'table', ' style="float: left;"'    , 'align on table converted to float' ),
+                       array( 'align="center"', 'table', ' style="margin-left: auto; margin-right: auto;"', 'align center on table converted to margins' ),
+                       array( 'align="right"' , 'table', ' style="float: right;"'   , 'align on table converted to float' ),
                );
        }