HTMLPurifier从name
标记中删除anchor
属性
使用过去的documentation,我已成功创建了一个新元素" include"。
但我无法获取代码以添加name
标记的anchor
属性。我的偏好不是限制name
值。任何帮助将不胜感激。
这是代码:
$config = HTMLPurifier_Config::createDefault();
// custom tag for included files
$config->set('HTML.DefinitionID', 'include');
$config->set('HTML.DefinitionRev', 16);
if ($def = $config->maybeGetRawHTMLDefinition()) {
// this works for adding the include element
$def->addElement('include', 'Block', 'Empty', 'Common', array('file*' => 'URI', 'height' => 'Text', 'width' => 'Text'));
// This doesn't work - among the many things, I've tried...
// 1) trying to get at least name ="target" to work
// $def->addAttribute('a', 'name', 'Enum#target');
// 2) trying to get any text to work
// $def->addAttribute('a', 'name', 'text');
// $def->addAttribute('a', 'name', new HTMLPurifier_AttrDef_Text());
}
$purifier = new HTMLPurifier($config);
答案 0 :(得分:0)
我认为您必须在Name.php中将name属性设置为true,请检查
http://htmlpurifier.org/live/configdoc/plain.html#HTML.Attr.Name.UseCDATA
答案 1 :(得分:0)
看起来有两种选择。一种是使用HTML.Allowed
定义所有元素和标签。更简单的方法是设置允许Attr.EnableID
和id
属性的name
。设置Attr.IDPrefix
将有助于防止名称冲突。这有效:
$config = HTMLPurifier_Config::createDefault();
// allow name and id attributes
$config->set('Attr.EnableID', true);
// prefix all id and names with user_
$config->set('Attr.IDPrefix', 'user_');
// custom tag
$config->set('HTML.DefinitionID', 'include');
$config->set('HTML.DefinitionRev', 2);
if ($def = $config->maybeGetRawHTMLDefinition()) {
$def->addElement('include', 'Block', 'Empty', 'Common', array('file*' => 'URI', 'height' => 'Text', 'width' => 'Text'));
}
$purifier = new HTMLPurifier($config);