Purifier icon indicating copy to clipboard operation
Purifier copied to clipboard

Support addAttribute via config file

Open viglucci opened this issue 10 years ago • 7 comments

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?

viglucci avatar Dec 31 '14 19:12 viglucci

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

Madnx avatar May 22 '15 18:05 Madnx

@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,
],

saqueib avatar Dec 11 '15 04:12 saqueib

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

JackPoint avatar Dec 30 '15 19:12 JackPoint

@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,
        ],

itbdw avatar Feb 15 '16 08:02 itbdw

@itbdw great that works for me! Thanks.

JackPoint avatar Feb 15 '16 22:02 JackPoint

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

Sly-Ripper avatar Aug 12 '16 19:08 Sly-Ripper

@itbdw you saved my day!!!

gfabrizi avatar May 15 '17 13:05 gfabrizi