我试图让HTML净化器过滤器中的元素的rel属性。我按照本指南http://htmlpurifier.org/docs/enduser-customize.html这里是我的代码:将属性添加到HTML净化器过滤器?
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('HTML.DefinitionID', 'enduser-customize.html tutorial');
$config->set('HTML.DefinitionRev', 1);
$config->set('Cache.DefinitionImpl', null); // remove this later!
$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'href*', 'URI');
$def->addAttribute('a', 'rel', 'CDATA');
$purifier = new HTMLPurifier($config);
然而,HTML净化器还过滤掉所有属性相对......我有点困惑的问题可能是什么。
当我使用:
$config->set('Attr', 'AllowedRel', array('something'));
我得到这个错误:
Notice: Using deprecated API: use
$config->set('Attr.AllowedRel', ...)
instead on line 191 in fileC:\wamp\www\neonet\application\modules\admin\controllers\IndexController.php
inC:\wamp\www\neonet\library\My\htmlpurifier-4.0.0-standalone\HTMLPurifier.standalone.php
on line 1819
编辑:
新代码:
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$config->set('Attr.AllowedRel', array('something'));
$purifier = new HTMLPurifier($config);
当我使用:
<href="/" rel="something">anchor</a>
Rel属性仍然被过滤。
是的,但是当我尝试使用它时,出现错误,请参阅上文,我编辑了我的帖子。 – 2009-11-10 18:00:39
确定忽略最后一条评论,我使用的是弃用的API ...但它仍然无效。 – 2009-11-10 18:04:18
谢谢,我会改变文档类型。 – 2009-11-11 12:28:27