我试图允许在HTML净化过滤器内的元件rel属性。我按照本指南 http://htmlpurifier.org/docs/enduser-customize.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'));

我得到这个错误:

  

注意:使用已弃用的API:在线路1819在文件$config->set('Attr.AllowedRel', ...)使用C:\wamp\www\neonet\application\modules\admin\controllers\IndexController.php上代替线191在C:\wamp\www\neonet\library\My\htmlpurifier-4.0.0-standalone\HTMLPurifier.standalone.php

编辑:

新的代码:

$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属性仍然得到过滤。

有帮助吗?

解决方案

此配置指令可以是感兴趣来你的。至于你的代码,它为我工作;也许你已经魔术引号开启或没有刷新适当缓存? (尝试在这种情况下,碰撞DefinitionRev。)

试图使用rel时等经典错误是,它不与XHTML严格工作;该文档类型没有定义相对,所以Attr.AllowedRel不会做任何事情(这应该在这个文档中被提及,但并非如此。)因此,你必须选择一个不同的文档类型,如果你想保持你的W3C勾选或使用原代码。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top