0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-13 00:38:42 +00:00

Reuse attribute definitions to define a few more attributes.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@168 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-08-05 22:14:19 +00:00
parent a4ce51cca2
commit fdc838c75e
2 changed files with 54 additions and 8 deletions

View File

@ -241,13 +241,19 @@ class HTMLPurifier_Definition
// by the transform classes. It will, however, do simple and slightly // by the transform classes. It will, however, do simple and slightly
// complex attribute value substitution // complex attribute value substitution
$e_Text = new HTMLPurifier_AttrDef_Text();
$e_TFrame = new HTMLPurifier_AttrDef_Enum(array('void', 'above',
'below', 'hsides', 'lhs', 'rhs', 'vsides', 'box', 'border'), false);
$e_TRules = new HTMLPurifier_AttrDef_Enum(array('none', 'groups',
'rows', 'cols', 'all'), false);
// attrs, included in almost every single one except for a few, // attrs, included in almost every single one except for a few,
// which manually override these in their local definitions // which manually override these in their local definitions
$this->info_global_attr = array( $this->info_global_attr = array(
// core attrs // core attrs
'id' => new HTMLPurifier_AttrDef_ID(), 'id' => new HTMLPurifier_AttrDef_ID(),
'class' => new HTMLPurifier_AttrDef_Class(), 'class' => new HTMLPurifier_AttrDef_Class(),
'title' => new HTMLPurifier_AttrDef_Text(), 'title' => $e_Text,
// i18n // i18n
'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false), 'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false),
'lang' => new HTMLPurifier_AttrDef_Lang(), 'lang' => new HTMLPurifier_AttrDef_Lang(),
@ -255,13 +261,40 @@ class HTMLPurifier_Definition
); );
// required attribute stipulation handled in attribute transformation // required attribute stipulation handled in attribute transformation
$this->info['bdo']->attr = array(); $this->info['bdo']->attr = array(); // nothing else
$this->info['br']->attr = array( $this->info['br']->attr['dir'] = false;
'dir' => false, $this->info['br']->attr['lang'] = false;
'lang' => false, $this->info['br']->attr['xml:lang'] = false;
'xml:lang' => false,
); $this->info['td']->attr['abbr'] = $e_Text;
$this->info['th']->attr['abbr'] = $e_Text;
$this->info['col']->attr['align'] =
$this->info['colgroup']->attr['align'] =
$this->info['tbody']->attr['align'] =
$this->info['td']->attr['align'] =
$this->info['tfoot']->attr['align'] =
$this->info['th']->attr['align'] =
$this->info['thead']->attr['align'] =
$this->info['tr']->attr['align'] = new HTMLPurifier_AttrDef_Enum(
array('left', 'center', 'right', 'justify', 'char'), false);
$this->info['col']->attr['valign'] =
$this->info['colgroup']->attr['valign'] =
$this->info['tbody']->attr['valign'] =
$this->info['td']->attr['valign'] =
$this->info['tfoot']->attr['valign'] =
$this->info['th']->attr['valign'] =
$this->info['thead']->attr['valign'] =
$this->info['tr']->attr['valign'] = new HTMLPurifier_AttrDef_Enum(
array('top', 'middle', 'bottom', 'baseline'), false);
$this->info['img']->attr['alt'] = $e_Text;
$this->info['table']->attr['frame'] = $e_TFrame;
$this->info['table']->attr['rules'] = $e_TRules;
$this->info['table']->attr['summary'] = $e_Text;
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// UNIMP : info_tag_transform : transformations of tags // UNIMP : info_tag_transform : transformations of tags

View File

@ -63,10 +63,23 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
$inputs[11] = '<span lang="fr">La soupe.</span>'; $inputs[11] = '<span lang="fr">La soupe.</span>';
$expect[11] = '<span lang="fr" xml:lang="fr">La soupe.</span>'; $expect[11] = '<span lang="fr" xml:lang="fr">La soupe.</span>';
// test align (won't work till CSS validation is fixed) // test align (won't work till CSS validation is implemented)
// $inputs[12] = '<h1 align="center">Centered Headline</h1>'; // $inputs[12] = '<h1 align="center">Centered Headline</h1>';
// $expect[12] = '<h1 style="text-align:center;">Centered Headline</h1>'; // $expect[12] = '<h1 style="text-align:center;">Centered Headline</h1>';
// test table
$inputs[13] = <<<HTML
<table frame="above" rules="rows" summary="A test table">
<tr valign="top">
<th abbr="super" align="left">Supercalifragilistic</th>
</tr>
<tr>
<td abbr="one">Cell one</td>
</tr>
</table>
HTML;
$expect[13] = $inputs[13];
$this->assertStrategyWorks($strategy, $inputs, $expect, $config); $this->assertStrategyWorks($strategy, $inputs, $expect, $config);
} }