mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
Factor some stuff into the Definition, add more docs.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@134 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
558c49a92d
commit
2b5589c884
@ -7,11 +7,33 @@ require_once 'HTMLPurifier/ChildDef.php';
|
||||
require_once 'HTMLPurifier/Generator.php';
|
||||
require_once 'HTMLPurifier/Token.php';
|
||||
|
||||
/**
|
||||
* Defines the purified HTML type with large amounts of objects.
|
||||
*
|
||||
* The main function of this object is its $info array, which is an
|
||||
* associative array of all the child and attribute definitions for
|
||||
* each allowed element. It also contains special use information (always
|
||||
* prefixed by info) for intelligent tag closing and global attributes.
|
||||
*
|
||||
* Planned improvements include attribute transformation objects as well as
|
||||
* migration of auto-tag-closing from HTMLPurifier_Strategy_MakeWellFormed
|
||||
* (these can likely just be extensions of ElementDef).
|
||||
*
|
||||
* After development drops off, the definition generation will be moved to
|
||||
* a maintenance script and we will stipulate that definition be created
|
||||
* by a factory method that unserializes a serialized version of Definition.
|
||||
* Customization would entail copying the maintenance script, making the
|
||||
* necessary changes, generating the serialized object, and then hooking it
|
||||
* in via the factory method. We would also offer a LiveDefinition for
|
||||
* automatic recompilation, suggesting that we would have a DefinitionGenerator.
|
||||
*/
|
||||
|
||||
class HTMLPurifier_Definition
|
||||
{
|
||||
|
||||
var $generator;
|
||||
var $info = array();
|
||||
|
||||
// used solely by HTMLPurifier_Strategy_MakeWellFormed
|
||||
var $info_closes_p = array(
|
||||
// these are all block elements: blocks aren't allowed in P
|
||||
'address' => true,
|
||||
@ -34,8 +56,13 @@ class HTMLPurifier_Definition
|
||||
'table' => true,
|
||||
'ul' => true
|
||||
);
|
||||
|
||||
// used solely by HTMLPurifier_Strategy_ValidateAttributes
|
||||
var $info_global_attr = array();
|
||||
|
||||
// used solely by HTMLPurifier_Strategy_FixNesting
|
||||
var $info_parent = 'div';
|
||||
|
||||
function instance() {
|
||||
static $instance = null;
|
||||
if (!$instance) {
|
||||
|
@ -14,8 +14,10 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
||||
|
||||
function execute($tokens) {
|
||||
// insert implicit "parent" node, will be removed at end
|
||||
array_unshift($tokens, new HTMLPurifier_Token_Start('div'));
|
||||
$tokens[] = new HTMLPurifier_Token_End('div');
|
||||
$parent_name = $this->definition->info_parent;
|
||||
|
||||
array_unshift($tokens, new HTMLPurifier_Token_Start($parent_name));
|
||||
$tokens[] = new HTMLPurifier_Token_End($parent_name);
|
||||
|
||||
for ($i = 0, $size = count($tokens) ; $i < $size; ) {
|
||||
|
||||
|
@ -61,6 +61,8 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
||||
if (!empty($current_nesting)) {
|
||||
$current_parent = array_pop($current_nesting);
|
||||
|
||||
// this ought to be moved to definition
|
||||
|
||||
// check if we're closing a P tag
|
||||
if ($current_parent->name == 'p' &&
|
||||
isset($this->definition->info_closes_p[$token->name])
|
||||
|
Loading…
Reference in New Issue
Block a user