htmlpurifier 自定义属性
如何在 HtmlPurifier 中允许自定义(html5 data-*)属性?
输入:
<img src="/my.jpg" data-type="5" alt="" />
导致错误:
Attribute 'data-type' in element 'img' not supported
(for information on implementing this, see the support forums)
HtmlPurifier 选项设置为:
'HTML.AllowedAttributes' => array('img.src', 'a.href', 'img.data-type')
How to allow custom (html5 data-*) attributes in HtmlPurifier?
Input:
<img src="/my.jpg" data-type="5" alt="" />
leads to an error:
Attribute 'data-type' in element 'img' not supported
(for information on implementing this, see the support forums)
HtmlPurifier options are set to:
'HTML.AllowedAttributes' => array('img.src', 'a.href', 'img.data-type')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTML 净化器定义了符合标准的属性矩阵,并在您尝试使用该矩阵中未定义的属性时发出警告。但是,您可以使用 HTMLDefinition::addAttribute() 函数向默认定义添加新属性,如下所示:
请参阅 HTMLDefinition::addAttribute 了解更多详细信息。
'Text'
这里是属性类型,你可以从 AttrTypes.phpHTML purifier defines the matrix of attributes that are standard compliant and complains when you try to use an attribute that it is not defined in this matrix. However, you can add new attributes to the default definition using the function HTMLDefinition::addAttribute() as follow:
See the definition of HTMLDefinition::addAttribute for more details.
'Text'
here is the attribute type, you can find the default attribute type from AttrTypes.php