diff --git a/library/HTMLPurifier/HTMLModule.php b/library/HTMLPurifier/HTMLModule.php
index 5589432e..4a420a7d 100644
--- a/library/HTMLPurifier/HTMLModule.php
+++ b/library/HTMLPurifier/HTMLModule.php
@@ -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
diff --git a/library/HTMLPurifier/HTMLModule/Legacy.php b/library/HTMLPurifier/HTMLModule/Legacy.php
index 930c714a..8563023d 100644
--- a/library/HTMLPurifier/HTMLModule/Legacy.php
+++ b/library/HTMLPurifier/HTMLModule/Legacy.php
@@ -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;
}
diff --git a/library/HTMLPurifier/HTMLModule/Target.php b/library/HTMLPurifier/HTMLModule/Target.php
index 1c2104ba..6cb8e510 100644
--- a/library/HTMLPurifier/HTMLModule/Target.php
+++ b/library/HTMLPurifier/HTMLModule/Target.php
@@ -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()
);
}
diff --git a/tests/HTMLPurifier/HTMLModuleTest.php b/tests/HTMLPurifier/HTMLModuleTest.php
index ba13a49e..3aff9cc3 100644
--- a/tests/HTMLPurifier/HTMLModuleTest.php
+++ b/tests/HTMLPurifier/HTMLModuleTest.php
@@ -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);
+
+ }
+
}
?>
\ No newline at end of file