0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-10 07:38:41 +00:00

Implement List module.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@709 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-02-04 01:52:13 +00:00
parent 43b157cf4d
commit 80243f377c
6 changed files with 56 additions and 5 deletions

View File

@ -357,6 +357,11 @@ class HTMLPurifier_HTMLDefinition
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// info[]->type : defines the type of the element (block or inline) // info[]->type : defines the type of the element (block or inline)
// unknown until proven inline/block
foreach ($this->info as $i => $x) {
$this->info[$i]->type = 'unknown';
}
// reuses $e_Inline and $e_Block // reuses $e_Inline and $e_Block
foreach ($e_Inline->elements as $name => $bool) { foreach ($e_Inline->elements as $name => $bool) {
if ($name == '#PCDATA') continue; if ($name == '#PCDATA') continue;
@ -642,13 +647,13 @@ class HTMLPurifier_ElementDef
var $child; var $child;
var $content_model; var $content_model;
var $content_model_type = 'optional'; var $content_model_type;
/** /**
* Type of the tag: inline or block or unknown? * Type of the tag: inline or block or unknown?
* @public * @public
*/ */
var $type = 'unknown'; var $type;
/** /**
* Lookup table of tags excluded from all descendants of this tag. * Lookup table of tags excluded from all descendants of this tag.
@ -658,4 +663,4 @@ class HTMLPurifier_ElementDef
} }
?> ?>

View File

@ -26,6 +26,7 @@ class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule
//'type' => 'ContentType', //'type' => 'ContentType',
); );
$this->info['a']->content_model = '#PCDATA | Inline'; $this->info['a']->content_model = '#PCDATA | Inline';
$this->info['a']->content_model_type = 'optional';
$this->info['a']->excludes = array('a' => true); $this->info['a']->excludes = array('a' => true);
} }

View File

@ -0,0 +1,40 @@
<?php
require_once 'HTMLPurifier/HTMLModule.php';
/**
* XHTML 1.1 List Module, defines list-oriented elements.
*/
class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule
{
var $elements = array('dl', 'dt', 'dd', 'ol', 'ul', 'li');
var $info = array();
// technically speaking, the List content set is a fully formed
// one or more expr, but it invariably occurs in an optional declaration
// so we're not going to do that subtlety. It might cause trouble
// if a user defines "List" and expects that multiple lists are
// allowed to be specified, but then again, that's not very intuitive.
var $content_sets = array('List' => 'dl | ol | ul', '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';
}
}
?>

View File

@ -40,8 +40,10 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule
$this->info[$element]->content_model_type = 'strictblockquote'; $this->info[$element]->content_model_type = 'strictblockquote';
} elseif ($element == 'div') { } elseif ($element == 'div') {
$this->info[$element]->content_model = '#PCDATA | Flow'; $this->info[$element]->content_model = '#PCDATA | Flow';
$this->info[$element]->content_model_type = 'optional';
} else { } else {
$this->info[$element]->content_model = '#PCDATA | Inline'; $this->info[$element]->content_model = '#PCDATA | Inline';
$this->info[$element]->content_model_type = 'optional';
} }
} }
} }

View File

@ -29,6 +29,7 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
$ret .= $this->element('caption', 'Environment'); $ret .= $this->element('caption', 'Environment');
$ret .= $this->row('Parent of fragment', $def->info_parent); $ret .= $this->row('Parent of fragment', $def->info_parent);
$ret .= $this->renderChildren($def->info_parent_def->child);
$ret .= $this->row('Strict mode', $def->strict); $ret .= $this->row('Strict mode', $def->strict);
if ($def->strict) $ret .= $this->row('Block wrap name', $def->info_block_wrapper); if ($def->strict) $ret .= $this->row('Block wrap name', $def->info_block_wrapper);
@ -37,8 +38,6 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
$ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0); $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0);
$ret .= $this->end('tr'); $ret .= $this->end('tr');
$ret .= $this->renderChildren($def->info_parent_def->child);
$ret .= $this->start('tr'); $ret .= $this->start('tr');
$ret .= $this->element('th', 'Tag transforms'); $ret .= $this->element('th', 'Tag transforms');
$list = array(); $list = array();

View File

@ -4,9 +4,11 @@ require_once 'HTMLPurifier/HTMLDefinition.php';
require_once 'HTMLPurifier/AttrTypes.php'; require_once 'HTMLPurifier/AttrTypes.php';
require_once 'HTMLPurifier/AttrCollection.php'; require_once 'HTMLPurifier/AttrCollection.php';
require_once 'HTMLPurifier/HTMLModule.php'; require_once 'HTMLPurifier/HTMLModule.php';
require_once 'HTMLPurifier/HTMLModule/Text.php'; require_once 'HTMLPurifier/HTMLModule/Text.php';
require_once 'HTMLPurifier/HTMLModule/Hypertext.php'; require_once 'HTMLPurifier/HTMLModule/Hypertext.php';
require_once 'HTMLPurifier/HTMLModule/List.php';
/** /**
* Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition * Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition
@ -22,6 +24,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
$this->modules['Text'] = new HTMLPurifier_HTMLModule_Text(); $this->modules['Text'] = new HTMLPurifier_HTMLModule_Text();
$this->modules['Hypertext'] = new HTMLPurifier_HTMLModule_Hypertext(); $this->modules['Hypertext'] = new HTMLPurifier_HTMLModule_Hypertext();
$this->modules['List'] = new HTMLPurifier_HTMLModule_List();
$this->attr_types = new HTMLPurifier_AttrTypes(); $this->attr_types = new HTMLPurifier_AttrTypes();
$this->attr_collection = new HTMLPurifier_AttrCollection(); $this->attr_collection = new HTMLPurifier_AttrCollection();
@ -107,6 +110,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
case 'custom': case 'custom':
return new HTMLPurifier_ChildDef_Custom($value); return new HTMLPurifier_ChildDef_Custom($value);
} }
if ($value) return new HTMLPurifier_ChildDef_Optional($value);
return HTMLPurifier_ChildDef_Empty(); return HTMLPurifier_ChildDef_Empty();
} }