mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 21:57:26 +02:00
Add Percentage, and font-size (not all styles fully realized yet though).
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@242 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -151,7 +151,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
<tr class="css1"><td>font</td><td>SHORTHAND</td></tr>
|
<tr class="css1"><td>font</td><td>SHORTHAND</td></tr>
|
||||||
<tr class="css1"><td>font-family</td><td>CSS validator may complain if fallback font
|
<tr class="css1"><td>font-family</td><td>CSS validator may complain if fallback font
|
||||||
family not specified</td></tr>
|
family not specified</td></tr>
|
||||||
<tr class="css1"><td>font-size</td><td>COMPOSITE(<absolute-size>,
|
<tr class="css1 impl-yes"><td>font-size</td><td>COMPOSITE(<absolute-size>,
|
||||||
<relative-size>, <length>, <percentage>)</td></tr>
|
<relative-size>, <length>, <percentage>)</td></tr>
|
||||||
<tr class="css1 impl-yes"><td>font-style</td><td>ENUM(normal, italic, oblique)</td></tr>
|
<tr class="css1 impl-yes"><td>font-style</td><td>ENUM(normal, italic, oblique)</td></tr>
|
||||||
<tr class="css1 impl-yes"><td>font-variant</td><td>ENUM(normal, small-caps)</td></tr>
|
<tr class="css1 impl-yes"><td>font-variant</td><td>ENUM(normal, small-caps)</td></tr>
|
||||||
|
34
library/HTMLPurifier/AttrDef/Percentage.php
Normal file
34
library/HTMLPurifier/AttrDef/Percentage.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
require_once 'HTMLPurifier/AttrDef/Number.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrDef_Percentage extends HTMLPurifier_AttrDef
|
||||||
|
{
|
||||||
|
|
||||||
|
var $number_def;
|
||||||
|
|
||||||
|
function HTMLPurifier_AttrDef_Percentage($non_negative = false) {
|
||||||
|
$this->number_def = new HTMLPurifier_AttrDef_Number($non_negative);
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate($string, $config, &$context) {
|
||||||
|
|
||||||
|
$string = $this->parseCDATA($string);
|
||||||
|
|
||||||
|
if ($string === '') return false;
|
||||||
|
$length = strlen($string);
|
||||||
|
if ($length === 1) return false;
|
||||||
|
if ($string[$length - 1] !== '%') return false;
|
||||||
|
|
||||||
|
$number = substr($string, 0, $length - 1);
|
||||||
|
$number = $this->number_def->validate($number, $config, $context);
|
||||||
|
|
||||||
|
if ($number === false) return false;
|
||||||
|
return "$number%";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -77,12 +77,21 @@ class HTMLPurifier_CSSDefinition
|
|||||||
new HTMLPurifier_AttrDef_CSSLength()
|
new HTMLPurifier_AttrDef_CSSLength()
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->info['font-size'] = new HTMLPurifier_AttrDef_Composite(array(
|
||||||
|
new HTMLPurifier_AttrDef_Enum(array('xx-small', 'x-small',
|
||||||
|
'small', 'medium', 'large', 'x-large', 'xx-large',
|
||||||
|
'larger', 'smaller')),
|
||||||
|
new HTMLPurifier_AttrDef_Percentage(),
|
||||||
|
new HTMLPurifier_AttrDef_CSSLength()
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// this could use specialized code
|
// this could use specialized code
|
||||||
$this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum(
|
$this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300',
|
array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300',
|
||||||
'400', '500', '600', '700', '800', '900'), false);
|
'400', '500', '600', '700', '800', '900'), false);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,9 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
|
|||||||
$this->assertDef('letter-spacing:2px;');
|
$this->assertDef('letter-spacing:2px;');
|
||||||
$this->assertDef('word-spacing:normal;');
|
$this->assertDef('word-spacing:normal;');
|
||||||
$this->assertDef('word-spacing:3em;');
|
$this->assertDef('word-spacing:3em;');
|
||||||
|
$this->assertDef('font-size:200%;');
|
||||||
|
$this->assertDef('font-size:larger;');
|
||||||
|
$this->assertDef('font-size:12pt;');
|
||||||
|
|
||||||
// duplicates
|
// duplicates
|
||||||
$this->assertDef('text-align:right;text-align:left;',
|
$this->assertDef('text-align:right;text-align:left;',
|
||||||
|
26
tests/HTMLPurifier/AttrDef/PercentageTest.php
Normal file
26
tests/HTMLPurifier/AttrDef/PercentageTest.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef/Percentage.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrDef_PercentageTest extends HTMLPurifier_AttrDefHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
$this->def = new HTMLPurifier_AttrDef_Percentage();
|
||||||
|
|
||||||
|
$this->assertDef('10%');
|
||||||
|
$this->assertDef('1.607%');
|
||||||
|
$this->assertDef('-567%');
|
||||||
|
|
||||||
|
$this->assertDef(' 100% ', '100%');
|
||||||
|
|
||||||
|
$this->assertDef('5', false);
|
||||||
|
$this->assertDef('asdf', false);
|
||||||
|
$this->assertDef('%', false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -69,6 +69,7 @@ $test_files[] = 'AttrDef/ColorTest.php';
|
|||||||
$test_files[] = 'AttrDef/IntegerTest.php';
|
$test_files[] = 'AttrDef/IntegerTest.php';
|
||||||
$test_files[] = 'AttrDef/NumberTest.php';
|
$test_files[] = 'AttrDef/NumberTest.php';
|
||||||
$test_files[] = 'AttrDef/CSSLengthTest.php';
|
$test_files[] = 'AttrDef/CSSLengthTest.php';
|
||||||
|
$test_files[] = 'AttrDef/PercentageTest.php';
|
||||||
$test_files[] = 'IDAccumulatorTest.php';
|
$test_files[] = 'IDAccumulatorTest.php';
|
||||||
$test_files[] = 'TagTransformTest.php';
|
$test_files[] = 'TagTransformTest.php';
|
||||||
$test_files[] = 'AttrTransform/LangTest.php';
|
$test_files[] = 'AttrTransform/LangTest.php';
|
||||||
|
Reference in New Issue
Block a user