- 如何阻止这种情况发生?,anchor,htmlpurifier"/>

首页 > 解决方案 > HTMLPurifier 移除- 如何阻止这种情况发生?

问题描述

使用 htmlpurifier 4.10,锚名称标签被从文本中删除。

当前配置:

    $class_file         = 'static/htmlpurifier-4.10.0-lite/library/HTMLPurifier.auto.php';
    $class_html_cleaner = 'HTMLPurifier';
    require_once($class_file);

    // Initiate config 
    $config     = HTMLPurifier_Config::createDefault();
    $config->set('AutoFormat.AutoParagraph', FALSE);
    $config->set('AutoFormat.RemoveEmpty', TRUE);
    $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', TRUE);

    // initiate class
    $purifier   = new HTMLPurifier($config);

    // clean passed HTML
    $html       = $purifier->purify($html);

添加配置HTML.Allowed

    $config->set('AutoFormat.AutoParagraph', FALSE);
    $config->set('AutoFormat.RemoveEmpty', TRUE);
    $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', TRUE);
    $config->set('HTML.Allowed', 'a[href|target|name|id|class]'); 

什么都不做,名称标签仍然被删除。

删除三个AutoFormat选项,所以我只有这个:

    $config->set('HTML.Allowed', 'a[href|target|name|id|class]'); 

也去除了name属性,但至少现在我发布的名称标签返回为<a></a>.

我在这里还缺少什么?如果这意味着我必须明确说明我将使用的所有其他潜在标签/属性,我 宁愿不使用 HTML.Allowed 。

非常感谢指导/帮助。已经为此奋斗了一个小时。

标签: anchorhtmlpurifier

解决方案


Attr.EnableID 规则默认删除 html id 属性。(它看起来也像名称属性。) http://htmlpurifier.org/live/configdoc/plain.html#HTML.EnableAttrID

为什么会发生在这里解释,http://htmlpurifier.org/docs/enduser-id.html


推荐阅读