Welcome! » Log In » Create A New Profile

Negative Margins

Posted by MarkWade508 
Negative Margins
February 08, 2016 09:01AM

What is the easiest way to configure HTMLPurifier to not allow negative margins on elements?

Re: Negative Margins
February 08, 2016 04:44PM

Look at

        $margin =
            $this->info['margin-top'] =
            $this->info['margin-bottom'] =
            $this->info['margin-left'] =
            $this->info['margin-right'] = new HTMLPurifier_AttrDef_CSS_Composite(
                    new HTMLPurifier_AttrDef_CSS_Length(),
                    new HTMLPurifier_AttrDef_CSS_Percentage(),
                    new HTMLPurifier_AttrDef_Enum(array('auto'))

        $this->info['margin'] = new HTMLPurifier_AttrDef_CSS_Multiple($margin);

in CSSDefinition.php you want to pass some bounds to the Length constructor and maybe the others. You can use getCSSDefinition to get a copy of CSSDefinition to modify yourself if you don't want to patch source code.

Your Email:


HTML input is enabled. Make sure you escape all HTML and angled brackets with < and >.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

Place code here

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}