mewebstudio / Purifier

HTMLPurifier for Laravel 5/6/7/8/9/10/11
MIT License
1.88k stars 230 forks source link

Support addAttribute via config file #17

Open viglucci opened 9 years ago

viglucci commented 9 years ago

With the vanilla HTML Purifier, if we wanted to add support for the allowfullscreen attribute on iframes we could add the attribute to the config like so:

$def = $config->getHTMLDefinition(true);
//add attribute allowfullscreen to iframe element
//allow values of true, false, and empty
$def->addAttribute('iframe', 'allowfullscreen', 'Enum#true,false,');

http://htmlpurifier.org/docs/enduser-customize.html#addAttribute

Could this be added and supported via a config file?

Madnx commented 9 years ago

In case you still want that feature, I just added it in my fork.

saqueib commented 8 years ago

@codel Thanks for adding this feature. But I cant find any documentation to addElement.

I want to add these tags u, strike, pre, code and blockquote. How can i do this, an example will be very helpful.

here is my config files settings.default

'default' => [
            'HTML.Doctype'             => 'XHTML 1.0 Strict',
            'HTML.Allowed'             => 'div,b,strong,i,em,a[href|title],strike,u,ul,ol,code,pre, blockquote,li,p,br,span[style],img[width|height|alt|src]',
            'CSS.AllowedProperties'    => 'text-align',
            'AutoFormat.AutoParagraph' => true,
            'AutoFormat.RemoveEmpty'   => true,
],
JackPoint commented 8 years ago

I need a target="_blank" in my urls. I cannot add it to the HTML.Allowed. I also need support for this.

itbdw commented 8 years ago

@JackPoint

        'default'          => [
            'HTML.Doctype'             => 'HTML 4.01 Transitional',
            'Attr.AllowedFrameTargets' => '_blank',
            'Attr.AllowedRel'          => 'nofollow',

            'HTML.Allowed'             => 'h2,strike,blockquote,u,div,b,strong,i,em,a[href|title|target|rel],ul,ol,li,p,br,span,img[width|height|alt|src]',
            'CSS.AllowedProperties'    => 'font,font-weight,font-style,text-decoration,padding-left,text-align',
            'AutoFormat.AutoParagraph' => false,
            'AutoFormat.RemoveEmpty'   => true,
        ],
JackPoint commented 8 years ago

@itbdw great that works for me! Thanks.

Sly-Ripper commented 8 years ago

Is it possible to do this now? I need to restrict classes used in tags.

gfabrizi commented 7 years ago

@itbdw you saved my day!!!