首页 > 解决方案 > 无论配置如何,Html 净化器都会删除图像样式,我该如何允许?

问题描述

我正在为 Laravel 使用https://github.com/mewebstudio/Purifier包,我遇到了一个问题,即无论我的配置如何,样式属性总是从输入中删除。这是我的配置

        'HTML.Allowed'  => 'font[color|style],h1[class|style],h2[class|style],h3[class|style],h4[class|style],h5[class|style],div[class|style],b,strong,i,em,a[href|title|class|style],ul,ol,li,p[style|class],br,span[style|class],img[style|width|height|alt|src|class],table[style|class],tbody[style|class],thead[style|class],tr[style|class],td[style|class],th[style|class]',
        'CSS.AllowedProperties'    => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align,width',

这是我的输入:

<img src="http://mywebsite.deve/storage/1278/5f97ed8127418_5f8efd4d61487_image.png" class="img h-auto" style="width: 25%;" alt="" title="" role="">

这就是我在应用净化器的“清洁”后得到的

<img src="http://mywebsite.deve/storage/1278/5f97ed8127418_5f8efd4d61487_image.png" class="img h-auto" alt="">

我的配置错了吗?我已经被这个问题困扰了几个小时了,非常感谢任何帮助。

标签: stylessanitizationhtmlpurifier

解决方案


感谢这篇文章https://github.com/mewebstudio/Purifier/issues/68我终于设法让它工作了。在配置中只需要在 'CSS.AllowedProperties'=> '...' 下添加 'CSS.MaxImgLength' => null


推荐阅读