mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
[1.7.0] Implement addBlankElement for non-standalone elements.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1047 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
e0cf214c44
commit
cb9c96a2b0
@ -158,6 +158,19 @@ class HTMLPurifier_HTMLModule
|
||||
return $this->info[$element];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function that creates a totally blank, non-standalone
|
||||
* element.
|
||||
* @param $element Name of element to create
|
||||
* @return Reference to created element
|
||||
*/
|
||||
function &addBlankElement($element) {
|
||||
$this->elements[] = $element;
|
||||
$this->info[$element] = new HTMLPurifier_ElementDef();
|
||||
$this->info[$element]->standalone = false;
|
||||
return $this->info[$element];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function that registers an element to a content set
|
||||
* @param Element to register
|
||||
|
@ -29,23 +29,22 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
|
||||
$this->addElement('strike', true, 'Inline', 'Inline', 'Common');
|
||||
|
||||
// setup modifications to old elements
|
||||
// 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;
|
||||
}
|
||||
|
||||
$this->info['li']->attr['value'] = new HTMLPurifier_AttrDef_Integer();
|
||||
$this->info['ol']->attr['start'] = new HTMLPurifier_AttrDef_Integer();
|
||||
$li =& $this->addBlankElement('li');
|
||||
$li->attr['value'] = new HTMLPurifier_AttrDef_Integer();
|
||||
|
||||
$this->info['address']->content_model = 'Inline | #PCDATA | p';
|
||||
$this->info['address']->content_model_type = 'optional';
|
||||
$this->info['address']->child = false;
|
||||
$ol =& $this->addBlankElement('ol');
|
||||
$ol->attr['start'] = new HTMLPurifier_AttrDef_Integer();
|
||||
|
||||
$this->info['blockquote']->content_model = 'Flow | #PCDATA';
|
||||
$this->info['blockquote']->content_model_type = 'optional';
|
||||
$this->info['blockquote']->child = false;
|
||||
$address =& $this->addBlankElement('address');
|
||||
$address->content_model = 'Inline | #PCDATA | p';
|
||||
$address->content_model_type = 'optional';
|
||||
$address->child = false;
|
||||
|
||||
$blockquote =& $this->addBlankElement('blockquote');
|
||||
$blockquote->content_model = 'Flow | #PCDATA';
|
||||
$blockquote->content_model_type = 'optional';
|
||||
$blockquote->child = false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,13 +9,12 @@ class HTMLPurifier_HTMLModule_Target extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
|
||||
var $name = 'Target';
|
||||
var $elements = array('a');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Target() {
|
||||
foreach ($this->elements as $e) {
|
||||
$this->info[$e] = new HTMLPurifier_ElementDef();
|
||||
$this->info[$e]->standalone = false;
|
||||
$this->info[$e]->attr = array(
|
||||
$elements = array('a');
|
||||
foreach ($elements as $name) {
|
||||
$e =& $this->addBlankElement($name);
|
||||
$e->attr = array(
|
||||
'target' => new HTMLPurifier_AttrDef_HTML_FrameTarget()
|
||||
);
|
||||
}
|
||||
|
@ -108,6 +108,19 @@ class HTMLPurifier_HTMLModuleTest extends UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
function test_addBlankElement() {
|
||||
|
||||
$module = new HTMLPurifier_HTMLModule();
|
||||
$def =& $module->addBlankElement('a');
|
||||
|
||||
$def2 = new HTMLPurifier_ElementDef();
|
||||
$def2->standalone = false;
|
||||
|
||||
$this->assertReference($module->info['a'], $def);
|
||||
$this->assertIdentical($def, $def2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user