mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-10 01:06:20 +02:00
[1.7.0] Convert Image, Legacy and List to use new format.
- Make attribute array parameter optional - Optimize contents parsing for keywords git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1041 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@ -18,16 +18,16 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
|
||||
var $content_sets = array('Inline' => 'img');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Image() {
|
||||
$this->info['img'] = new HTMLPurifier_ElementDef();
|
||||
$this->info['img']->attr = array(
|
||||
0 => array('Common'),
|
||||
'alt' => 'Text',
|
||||
'height' => 'Length',
|
||||
'longdesc' => 'URI',
|
||||
'src' => new HTMLPurifier_AttrDef_URI(true), // embedded
|
||||
'width' => 'Length'
|
||||
$this->addElement(
|
||||
'img', true, 'Inline', 'Empty', 'Common',
|
||||
array(
|
||||
'alt' => 'Text',
|
||||
'height' => 'Length',
|
||||
'longdesc' => 'URI',
|
||||
'src' => new HTMLPurifier_AttrDef_URI(true), // embedded
|
||||
'width' => 'Length'
|
||||
)
|
||||
);
|
||||
$this->info['img']->content_model_type = 'empty';
|
||||
$this->info['img']->attr_transform_post[] =
|
||||
new HTMLPurifier_AttrTransform_ImgRequired();
|
||||
}
|
||||
|
@ -22,22 +22,22 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
|
||||
// incomplete
|
||||
|
||||
var $name = 'Legacy';
|
||||
var $elements = array('u', 's', 'strike');
|
||||
var $non_standalone_elements = array('li', 'ol', 'address', 'blockquote');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Legacy() {
|
||||
// setup new elements
|
||||
foreach ($this->elements as $name) {
|
||||
$this->info[$name] = new HTMLPurifier_ElementDef();
|
||||
// for u, s, strike, as more elements get added, add
|
||||
// conditionals as necessary
|
||||
$this->info[$name]->content_model = 'Inline | #PCDATA';
|
||||
$this->info[$name]->content_model_type = 'optional';
|
||||
$this->info[$name]->attr[0] = array('Common');
|
||||
}
|
||||
$this->addElement(
|
||||
'u', true, 'Inline', 'Inline', 'Common'
|
||||
);
|
||||
$this->addElement(
|
||||
's', true, 'Inline', 'Inline', 'Common'
|
||||
);
|
||||
$this->addElement(
|
||||
'strike', true, 'Inline', 'Inline', 'Common'
|
||||
);
|
||||
|
||||
// setup modifications to old elements
|
||||
foreach ($this->non_standalone_elements as $name) {
|
||||
// perhaps we could make some convenience functions for these...
|
||||
$elements = array('li', 'ol', 'address', 'blockquote');
|
||||
foreach ($elements as $name) {
|
||||
$this->info[$name] = new HTMLPurifier_ElementDef();
|
||||
$this->info[$name]->standalone = false;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
|
||||
var $name = 'List';
|
||||
var $elements = array('dl', 'dt', 'dd', 'ol', 'ul', 'li');
|
||||
|
||||
// According to the abstract schema, the List content set is a fully formed
|
||||
// one or more expr, but it invariably occurs in an optional declaration
|
||||
@ -19,26 +18,31 @@ class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule
|
||||
// Furthermore, the actual XML Schema may disagree. Regardless,
|
||||
// we don't have support for such nested expressions without using
|
||||
// the incredibly inefficient and draconic Custom ChildDef.
|
||||
var $content_sets = array('List' => 'dl | ol | ul', 'Flow' => 'List');
|
||||
|
||||
var $content_sets = array('Flow' => 'List');
|
||||
|
||||
function HTMLPurifier_HTMLModule_List() {
|
||||
foreach ($this->elements as $element) {
|
||||
$this->info[$element] = new HTMLPurifier_ElementDef();
|
||||
$this->info[$element]->attr = array(0 => array('Common'));
|
||||
if ($element == 'li' || $element == 'dd') {
|
||||
$this->info[$element]->content_model = '#PCDATA | Flow';
|
||||
$this->info[$element]->content_model_type = 'optional';
|
||||
} elseif ($element == 'ol' || $element == 'ul') {
|
||||
$this->info[$element]->content_model = 'li';
|
||||
$this->info[$element]->content_model_type = 'required';
|
||||
}
|
||||
}
|
||||
$this->info['dt']->content_model = '#PCDATA | Inline';
|
||||
$this->info['dt']->content_model_type = 'optional';
|
||||
$this->info['dl']->content_model = 'dt | dd';
|
||||
$this->info['dl']->content_model_type = 'required';
|
||||
// this could be a LOT more robust
|
||||
$this->addElement(
|
||||
'ol', true, 'List', 'Required: li', 'Common'
|
||||
);
|
||||
$this->addElement(
|
||||
'ul', true, 'List', 'Required: li', 'Common'
|
||||
);
|
||||
$this->addElement(
|
||||
'dl', true, 'List', 'Required: dt | dd', 'Common'
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'li', true, false, 'Flow', 'Common'
|
||||
);
|
||||
$this->info['li']->auto_close = array('li' => true);
|
||||
|
||||
$this->addElement(
|
||||
'dd', true, false, 'Flow', 'Common'
|
||||
);
|
||||
$this->addElement(
|
||||
'dt', true, false, 'Inline', 'Common'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user