使用:
https://github.com/mewebstudio/Purifier
我无法添加任何自定义属性.
测试了所有可能的变化,但仍然没有.
在配置文件中我看到:
'custom_attributes' => [
['a', 'target', 'Enum#_blank,_self,_target,_top'],
],
但是在测试之后< a target =“_ top”href =“www.example.com”> Example.com< / a>
什么都没发生.
我错过了什么?
我只需要两个带有自定义文本的属性:
data-rel
data-title
请有人帮忙或建议更好的选择.谢谢!
最佳答案 在配置文件中,您应该添加以下内容:
'custom_attributes' => [
['a', 'target', 'Enum#_blank,_self,_target,_top'],
['img', 'data-rel', 'Text'],
['img', 'data-title', 'Text'],
],
请注意,这仅适用于img标记.如果要将这些属性用于另一个标记,可以相应地更改第一个数组元素.
然后在默认配置数组中,您应该实际允许这样的自定义属性:
'default' => [
'HTML.Doctype' => 'XHTML 1.0 Transitional',
'HTML.Allowed' => 'img[width|height|alt|src|class|data-rel|data-title],table,tbody,tr,td[style|rowspan],h1,h2,h3,h4,h5,h6,small,div,b,strong,i,em,u,a[href|title|target],ul,ol,li,p[style|class],br,span[style],sup,sub',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align,vertical-align',
'AutoFormat.AutoParagraph' => false,
'AutoFormat.RemoveEmpty' => false,
],
请注意img元素附近的HTML.Allowed字符串中添加的data-rel,data-title属性.
同样,如果您想要另一个标记的自定义属性,则应在custom_attributes数组和HTML.Allowed字符串中指定它.