Welcome! » Log In » Create A New Profile

Filter all elements except b, convert filtered elements to space

Posted by mrfr0g 
Filter all elements except b, convert filtered elements to space
December 13, 2011 01:26PM

I'm having a small issue where I have minified HTML, that I now need to strip out all tags except for the 'b' tag when it has the class 'red'. I am able to pretty easily do this with this config

'HTML.Allowed', 'b[class]'

'Attr.AllowedClasses', 'red'

Since my HTML text is minified, the output looks something like this

::input:: <p><ul><li>item</li><li><b class="red">item2</li></ul></p> ::output:: item<b class="red">item2</b> When when rendered, looks like, "itemitem2"

Since them items are block level elements, is there a way to add a space between them? So the output would look like,

::output:: item <b class="red">item2</b>

Re: Filter all elements except b, convert filtered elements to space
December 13, 2011 03:16PM

Yeah, this is a kind of known lacking feature One possible thing to do is to preprocess the HTML to add the extra spaces necessary before tossing it at HTML Purifier.

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

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: