mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
Implement Bdo module. Also added some documentation and missing values, as well as support for attr_collection additions.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@713 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
cfe50ff8ae
commit
315c55eeb1
@ -36,6 +36,13 @@ class HTMLPurifier_AttrCollection
|
||||
|
||||
function setup($attr_types, $modules) {
|
||||
$info =& $this->info;
|
||||
foreach ($modules as $module) {
|
||||
foreach ($module->attr_collection as $coll_i => $coll) {
|
||||
foreach ($coll as $attr_i => $attr) {
|
||||
$info[$coll_i][$attr_i] = $attr;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($info as $name => $attr) {
|
||||
// merge attribute collections that include others
|
||||
$this->performInclusions($info[$name]);
|
||||
|
@ -626,9 +626,23 @@ class HTMLPurifier_ElementDef
|
||||
*/
|
||||
var $child;
|
||||
|
||||
/**
|
||||
* Abstract string representation of internal ChildDef rules
|
||||
* @public
|
||||
*/
|
||||
var $content_model;
|
||||
|
||||
/**
|
||||
* Value of $child->type, used to determine which ChildDef to use
|
||||
* @public
|
||||
*/
|
||||
var $content_model_type;
|
||||
|
||||
/**
|
||||
* Does the element have a content model (#PCDATA | Inline)*? This
|
||||
* is important for chameleon ins and del processing.
|
||||
* @public
|
||||
*/
|
||||
var $descendants_are_inline;
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,7 @@ class HTMLPurifier_HTMLModule
|
||||
var $elements = array();
|
||||
var $info = array();
|
||||
var $content_sets = array();
|
||||
var $attr_collection = array();
|
||||
}
|
||||
|
||||
?>
|
35
library/HTMLPurifier/HTMLModule/Bdo.php
Normal file
35
library/HTMLPurifier/HTMLModule/Bdo.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/HTMLModule.php';
|
||||
|
||||
/**
|
||||
* XHTML 1.1 Bi-directional Text Module, defines elements that
|
||||
* declare directionality of content. Text Extension Module.
|
||||
*/
|
||||
class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
|
||||
var $elements = array('bdo');
|
||||
var $info = array();
|
||||
var $content_sets = array('Inline' => 'bdo');
|
||||
var $attr_collection = array(
|
||||
'I18N' => array('dir' => false)
|
||||
);
|
||||
|
||||
function HTMLPurifier_HTMLModule_Bdo() {
|
||||
$dir = new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false);
|
||||
$this->attr_collection['I18N']['dir'] = $dir;
|
||||
$this->info['bdo'] = new HTMLPurifier_ElementDef();
|
||||
$this->info['bdo']->attr = array(
|
||||
0 => array('Core'),
|
||||
'dir' => $dir
|
||||
);
|
||||
$this->info['bdo']->content_model = '#PCDATA | Inline';
|
||||
$this->info['bdo']->content_model_type = 'optional';
|
||||
$this->info['bdo']->content_model_type = 'optional';
|
||||
$this->info['bdo']->attr_transform_post[] = new HTMLPurifier_AttrTransform_BdoDir();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -33,6 +33,7 @@ class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule
|
||||
$this->info['dt']->content_model_type = 'optional';
|
||||
$this->info['dl']->content_model = 'dt | dd';
|
||||
$this->info['dl']->content_model_type = 'required';
|
||||
$this->info['li']->auto_close = array('li' => true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,6 +47,11 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule
|
||||
$this->info[$element]->content_model_type = 'optional';
|
||||
}
|
||||
}
|
||||
$this->info['p']->auto_close = array_flip(array(
|
||||
'address', 'blockquote', 'dd', 'dir', 'div', 'dl', 'dt',
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'ol', 'p', 'pre',
|
||||
'table', 'ul'
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ require_once 'HTMLPurifier/HTMLModule/Hypertext.php';
|
||||
require_once 'HTMLPurifier/HTMLModule/List.php';
|
||||
require_once 'HTMLPurifier/HTMLModule/Presentation.php';
|
||||
require_once 'HTMLPurifier/HTMLModule/Edit.php';
|
||||
require_once 'HTMLPurifier/HTMLModule/Bdo.php';
|
||||
|
||||
/**
|
||||
* Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition
|
||||
@ -30,6 +31,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
||||
$this->modules['List'] = new HTMLPurifier_HTMLModule_List();
|
||||
$this->modules['Presentation'] = new HTMLPurifier_HTMLModule_Presentation();
|
||||
$this->modules['Edit'] = new HTMLPurifier_HTMLModule_Edit();
|
||||
$this->modules['Bdo'] = new HTMLPurifier_HTMLModule_Bdo();
|
||||
|
||||
$this->attr_types = new HTMLPurifier_AttrTypes();
|
||||
$this->attr_collection = new HTMLPurifier_AttrCollection();
|
||||
@ -102,6 +104,35 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
||||
}
|
||||
}
|
||||
|
||||
$this->setupAttrTransform($config);
|
||||
$this->setupBlockWrapper($config);
|
||||
$this->setupParent($config);
|
||||
|
||||
}
|
||||
|
||||
function setupAttrTransform($config) {
|
||||
$this->info_attr_transform_post[] = new HTMLPurifier_AttrTransform_Lang();
|
||||
}
|
||||
|
||||
function setupBlockWrapper($config) {
|
||||
$block_wrapper = $config->get('HTML', 'BlockWrapper');
|
||||
if (isset($this->content_sets['Block'][$block_wrapper])) {
|
||||
$this->info_block_wrapper = $block_wrapper;
|
||||
} else {
|
||||
trigger_error('Cannot use non-block element as block wrapper.',
|
||||
E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
function setupParent($config) {
|
||||
$parent = $config->get('HTML', 'Parent');
|
||||
if (isset($this->info[$parent])) {
|
||||
$this->info_parent = $parent;
|
||||
} else {
|
||||
trigger_error('Cannot use unrecognized element as parent.',
|
||||
E_USER_ERROR);
|
||||
}
|
||||
$this->info_parent_def = $this->info[$this->info_parent];
|
||||
}
|
||||
|
||||
function getChildDef($def) {
|
||||
@ -130,10 +161,11 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
||||
|
||||
function convertToLookup($string) {
|
||||
$array = explode('|', str_replace(' ', '', $string));
|
||||
$ret = array();
|
||||
foreach ($array as $i => $k) {
|
||||
$array[$i] = true;
|
||||
$ret[$k] = true;
|
||||
}
|
||||
return $array;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user