I have a Laravel website and I'm using the stevebauman/purify v6 package to clean and validate content on the frontend. However I have a little problem. When I have an id in an html tag, it removes it or rather it just doesn't display it.
This is what I tried so far:
- Updated the allowed.HTML in
config/purify.phplike this
'HTML.Allowed' => 'h1[id],h2[id],h3[id],h4[id],h5[id],h6[id],b,strong,blockquote,code,pre[class|id],i,em,a[href|title|id],ul,ol,li,p[style|id],br,span[id],img[width|height|alt|src|class|id]',
- I also added this line to the config file:
'Attr.AllowedFrameTargets' => array('_blank', '_self', '_parent', '_top', 'id'),
- In
app/Providers/AppServiceProvider.phpI added the class:
public function register()
{
$this->app->register(\Stevebauman\Purify\PurifyServiceProvider::class);
}
- I also made sure to empty the cache
php artisan config:cache
I'm displaying the content in my view like this:
{!! \Purify::clean($post->content) !!}
Unfortunately the IDs are not displayed on the frontend.
HTML Purifier disallows
idattributes by default. You need to explicitly allow them with an additional toggle: Attr.EnableID: