mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-03 20:58:11 +02:00
Basic color keywords translated into hexadecimal values.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@323 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
1
NEWS
1
NEWS
@@ -6,6 +6,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
- Malformed UTF-8 and non-SGML character detection and cleaning implemented
|
- Malformed UTF-8 and non-SGML character detection and cleaning implemented
|
||||||
- API documentation completed
|
- API documentation completed
|
||||||
- Shorthand CSS properties implemented: font
|
- Shorthand CSS properties implemented: font
|
||||||
|
- Basic color keywords translated into hexadecimal values
|
||||||
|
|
||||||
1.0.0beta, released 2006-08-16
|
1.0.0beta, released 2006-08-16
|
||||||
- First public release, most functionality implemented. Notable omissions are:
|
- First public release, most functionality implemented. Notable omissions are:
|
||||||
|
@@ -8,11 +8,38 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
class HTMLPurifier_AttrDef_Color extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_Color extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color keyword lookup table.
|
||||||
|
* @todo Extend it to include all usually allowed colors.
|
||||||
|
*/
|
||||||
|
var $colors = array(
|
||||||
|
'maroon' => '#800000',
|
||||||
|
'red' => '#F00',
|
||||||
|
'orange' => '#FFA500',
|
||||||
|
'yellow' => '#FF0',
|
||||||
|
'olive' => '#808000',
|
||||||
|
'purple' => '#800080',
|
||||||
|
'fuchsia' => '#F0F',
|
||||||
|
'white' => '#FFF',
|
||||||
|
'lime' => '#0F0',
|
||||||
|
'green' => '#008000',
|
||||||
|
'navy' => '#000080',
|
||||||
|
'blue' => '#00F',
|
||||||
|
'aqua' => '#0FF',
|
||||||
|
'teal' => '#008080',
|
||||||
|
'black' => '#000',
|
||||||
|
'silver' => '#C0C0C0',
|
||||||
|
'gray' => '#808080'
|
||||||
|
);
|
||||||
|
|
||||||
function validate($color, $config, &$context) {
|
function validate($color, $config, &$context) {
|
||||||
|
|
||||||
$color = trim($color);
|
$color = trim($color);
|
||||||
if (!$color) return false;
|
if (!$color) return false;
|
||||||
|
|
||||||
|
$lower = strtolower($color);
|
||||||
|
if (isset($this->colors[$lower])) return $this->colors[$lower];
|
||||||
|
|
||||||
if ($color[0] === '#') {
|
if ($color[0] === '#') {
|
||||||
// hexadecimal handling
|
// hexadecimal handling
|
||||||
$hex = substr($color, 1);
|
$hex = substr($color, 1);
|
||||||
|
@@ -23,6 +23,9 @@ class HTMLPurifier_AttrDef_ColorTest extends HTMLPurifier_AttrDefHarness
|
|||||||
$this->assertDef('rgb(200%, -10%, 0%)', 'rgb(100%,0%,0%)');
|
$this->assertDef('rgb(200%, -10%, 0%)', 'rgb(100%,0%,0%)');
|
||||||
$this->assertDef('rgb(256,-23,34)', 'rgb(255,0,34)');
|
$this->assertDef('rgb(256,-23,34)', 'rgb(255,0,34)');
|
||||||
|
|
||||||
|
// color keywords, of course
|
||||||
|
$this->assertDef('red', '#F00');
|
||||||
|
|
||||||
// maybe hex transformations would be another nice feature
|
// maybe hex transformations would be another nice feature
|
||||||
// at the very least transform rgb percent to rgb integer
|
// at the very least transform rgb percent to rgb integer
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user