问题描述
使用 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 。
非常感谢指导/帮助。已经为此奋斗了一个小时。
解决方案
Attr.EnableID 规则默认删除 html id 属性。(它看起来也像名称属性。) http://htmlpurifier.org/live/configdoc/plain.html#HTML.EnableAttrID
为什么会发生在这里解释,http://htmlpurifier.org/docs/enduser-id.html。
推荐阅读
- java - 如何在我的 Android 应用中实现 7 天免费试用期的年度订阅的“帐户保留”状态?
- sql - Vb.net 函数不返回 SQL Server 存储过程结果
- python - 将 numpy 数组转换为 html img 标签的 src 可读的字节串
- django - 允许将 django 模型字段修改为某些用户
- javascript - 有没有办法通过 ReactJs 中的动态操作调用来更新 props 变量?
- python-3.x - 带有列表的 Python 平分行为
- c++ - c++ 方法从另一个模板类和命名空间泄漏
- python - findAndModify 不使用索引搜索
- swift - CustomVideoCompositorClass - 绘制时出现 CGContext 错误(CGImage,CGRect)
- laravel - Laravel:选择一对多关系中的第一条记录