使用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>
.
我还漏掉了什么? 如果这意味着我必须明确地说明每一个 其他 潜在的标签属性,我曾经使用。
Guidancehelp greatly appreciated. 和这个问题斗争了一个小时了。
Attr.EnableID规则默认删除html id属性。 (它看起来也像名字属性一样。)http:/htmlpurifier.orgliveconfigdocplain.html#HTML.EnableAttrID。
为什么会出现这种情况,这里就解释一下。http:/htmlpurifier.orgdocsenduser-id.html。.