HTMLPurifier 删除 <a name="#someanchorname"></a> - 如何阻止这种情况发生?

HTMLPurifier removing <a name="#someanchorname"></a> - how to stop this from happening?

使用 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 如果这意味着我必须明确说明每个 other 潜在的 tag/attribute 我会使用。

Guidance/help 非常感谢。现在已经为此战斗了一个小时。

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

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