Welcome! » Log In » Create A New Profile

Stop stripping tags that are outside of the body..

Posted by Chris Altman 
Chris Altman
Stop stripping tags that are outside of the body..
June 16, 2010 01:00PM

We are trying to figure out how to make sure html, head, meta, style, title, aren't stripped.

In an effort to stop them from being removed by HTMLPurifier we used the addElement method. We seem to be able to get them all to work EXCEPT HEAD.

                        $oDef = $oConfig->getHTMLDefinition(true);

                        $oDef->addElement(
                                'style', // name
                                false, // content set
                                'Optional: #PCDATA', // allowed children
                                'Common', // attribute collection
                                array( // attributes
                                        'type' => 'CDATA',
                                ));

                        $oDef->addElement(
                                'title', // name
                                false, // content set
                                'Optional: #PCDATA', // allowed children
                                'I18N', // attribute collection
                                array( // attributes
                                ));

                        $oDef->addElement(
                                'meta', // name
                                false, // content set
                                'Empty', // allowed children
                                'I18N', // attribute collection
                                array( // attributes
                                        'http-equiv' => 'CDATA',
                                        'name' => 'CDATA',
                                        'content' => 'CDATA',
                                        'scheme' => 'CDATA',
                                ));

                        $oDef->addElement(
                                'head', // name
                                false, // content set
                                'Optional: Flow | #PCDATA | title | style | meta', // allowed children
                                'Common', // attribute collection
                                array( // attributes
                                ));

                        $oDef->addElement(
                                'body', // name
                                false, // content set
                                'Optional: Flow | #PCDATA | Inline', // allowed children
                                'Common', // attribute collection
                                array( // attributes
                                ));

                        $html = $oDef->addElement(
                                'html',  // name
                                false, // content set
                                'Optional: Flow | #PCDATA | head | body | title | style | meta', // allowed children
                                'Common', // attribute collection
                                array( // attributes
#                                       'action*' => 'URI',
#                                       'method' => 'Enum#get|post',
#                                       'name' => 'ID'
                                ));
                        $html->excludes = array('html'=>true);

You may ask why we have title, style, meta inside the html. It's because the HEAD isn't working yet. So in the meantime we put them there since they seem to render even though they are children of HEAD.

Re: Stop stripping tags that are outside of the body..
June 18, 2010 08:52AM

Can you please post the configuration you're using? Have you been updating the definition revision (or suspended caching) while developing your plugins?

Author:
Your Email:

Subject:

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:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: