mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 16:31:53 +00:00
[1.6.0] Add support for border attribute transform
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@920 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
a16d6c4342
commit
85374d330f
1
NEWS
1
NEWS
@ -12,6 +12,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
1.6.0, unknown release date
|
1.6.0, unknown release date
|
||||||
! Support for all deprecated attributes via attribute transformations
|
! Support for all deprecated attributes via attribute transformations
|
||||||
+ bgcolor in td, th, tr and table
|
+ bgcolor in td, th, tr and table
|
||||||
|
+ border in img
|
||||||
+ (incomplete)
|
+ (incomplete)
|
||||||
|
|
||||||
1.5.1, unknown release date
|
1.5.1, unknown release date
|
||||||
|
@ -272,7 +272,7 @@ Mozilla on inside and needs -moz-outline, no IE support.</td></tr>
|
|||||||
<tr class="impl-yes"><td rowspan="3">bgcolor</td><td>TABLE</td><td>Superset style 'background-color'</td></tr>
|
<tr class="impl-yes"><td rowspan="3">bgcolor</td><td>TABLE</td><td>Superset style 'background-color'</td></tr>
|
||||||
<tr class="impl-yes"><td>TR</td><td>Superset style 'background-color'</td></tr>
|
<tr class="impl-yes"><td>TR</td><td>Superset style 'background-color'</td></tr>
|
||||||
<tr class="impl-yes"><td>TD, TH</td><td>Superset style 'background-color'</td></tr>
|
<tr class="impl-yes"><td>TD, TH</td><td>Superset style 'background-color'</td></tr>
|
||||||
<tr><td>border</td><td>IMG</td><td>Near equivalent style 'border-width', as it only applies when link present</td></tr>
|
<tr class="impl-yes"><td>border</td><td>IMG</td><td>Equivalent style <code>border:[number]px solid</code></td></tr>
|
||||||
<tr><td>clear</td><td>BR</td><td>Near-equiv style 'clear', transform 'all' into 'both'</td></tr>
|
<tr><td>clear</td><td>BR</td><td>Near-equiv style 'clear', transform 'all' into 'both'</td></tr>
|
||||||
<tr class="impl-no"><td>compact</td><td>DL, OL, UL</td><td>Boolean, needs custom CSS class; rarely used anyway</td></tr>
|
<tr class="impl-no"><td>compact</td><td>DL, OL, UL</td><td>Boolean, needs custom CSS class; rarely used anyway</td></tr>
|
||||||
<tr class="required impl-yes"><td>dir</td><td>BDO</td><td>Required, insert ltr (or configuration value) if none</td></tr>
|
<tr class="required impl-yes"><td>dir</td><td>BDO</td><td>Required, insert ltr (or configuration value) if none</td></tr>
|
||||||
|
28
library/HTMLPurifier/AttrTransform/Border.php
Normal file
28
library/HTMLPurifier/AttrTransform/Border.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-transform that changes deprecated border attribute to CSS.
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrTransform_Border
|
||||||
|
extends HTMLPurifier_AttrTransform {
|
||||||
|
|
||||||
|
function transform($attr, $config, &$context) {
|
||||||
|
|
||||||
|
if (!isset($attr['border'])) return $attr;
|
||||||
|
|
||||||
|
$border_width = $attr['border'];
|
||||||
|
unset($attr['border']);
|
||||||
|
// some validation should happen here
|
||||||
|
|
||||||
|
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
|
||||||
|
$attr['style'] = "border:{$border_width}px solid;" . $attr['style'];
|
||||||
|
|
||||||
|
return $attr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -9,6 +9,7 @@ require_once 'HTMLPurifier/TagTransform/Font.php';
|
|||||||
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform/BgColor.php';
|
require_once 'HTMLPurifier/AttrTransform/BgColor.php';
|
||||||
|
require_once 'HTMLPurifier/AttrTransform/Border.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proprietary module that transforms deprecated elements into Strict
|
* Proprietary module that transforms deprecated elements into Strict
|
||||||
@ -22,7 +23,7 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
|||||||
|
|
||||||
// we're actually modifying these elements, not defining them
|
// we're actually modifying these elements, not defining them
|
||||||
var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
|
var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
|
||||||
'blockquote', 'table', 'td', 'th', 'tr');
|
'blockquote', 'table', 'td', 'th', 'tr', 'img');
|
||||||
|
|
||||||
var $info_tag_transform = array(
|
var $info_tag_transform = array(
|
||||||
// placeholders, see constructor for definitions
|
// placeholders, see constructor for definitions
|
||||||
@ -80,6 +81,8 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
|||||||
$this->info['td']->attr_transform_pre['bgcolor'] =
|
$this->info['td']->attr_transform_pre['bgcolor'] =
|
||||||
$this->info['th']->attr_transform_pre['bgcolor'] = new HTMLPurifier_AttrTransform_BgColor();
|
$this->info['th']->attr_transform_pre['bgcolor'] = new HTMLPurifier_AttrTransform_BgColor();
|
||||||
|
|
||||||
|
$this->info['img']->attr_transform_pre['border'] = new HTMLPurifier_AttrTransform_Border();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var $defines_child_def = true;
|
var $defines_child_def = true;
|
||||||
|
40
tests/HTMLPurifier/AttrTransform/BorderTest.php
Normal file
40
tests/HTMLPurifier/AttrTransform/BorderTest.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform/Border.php';
|
||||||
|
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
||||||
|
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$this->obj = new HTMLPurifier_AttrTransform_Border();
|
||||||
|
}
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
$this->assertResult( array() );
|
||||||
|
|
||||||
|
$this->assertResult(
|
||||||
|
array('border' => '1'),
|
||||||
|
array('style' => 'border:1px solid;')
|
||||||
|
);
|
||||||
|
|
||||||
|
// once again, no validation done here, we expect CSS validator
|
||||||
|
// to catch it
|
||||||
|
$this->assertResult(
|
||||||
|
array('border' => '10%'),
|
||||||
|
array('style' => 'border:10%px solid;')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResult(
|
||||||
|
array('border' => '23', 'style' => 'font-weight:bold;'),
|
||||||
|
array('style' => 'border:23px solid;font-weight:bold;')
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -35,6 +35,7 @@ $test_files[] = 'AttrDef/URITest.php';
|
|||||||
$test_files[] = 'AttrDefTest.php';
|
$test_files[] = 'AttrDefTest.php';
|
||||||
$test_files[] = 'AttrTransform/BdoDirTest.php';
|
$test_files[] = 'AttrTransform/BdoDirTest.php';
|
||||||
$test_files[] = 'AttrTransform/BgColorTest.php';
|
$test_files[] = 'AttrTransform/BgColorTest.php';
|
||||||
|
$test_files[] = 'AttrTransform/BorderTest.php';
|
||||||
$test_files[] = 'AttrTransform/ImgRequiredTest.php';
|
$test_files[] = 'AttrTransform/ImgRequiredTest.php';
|
||||||
$test_files[] = 'AttrTransform/LangTest.php';
|
$test_files[] = 'AttrTransform/LangTest.php';
|
||||||
$test_files[] = 'AttrTransform/TextAlignTest.php';
|
$test_files[] = 'AttrTransform/TextAlignTest.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user