Welcome! » Log In » Create A New Profile

Disallow BR input but convert single newlines to BR

Posted by joel.wietelmann 
Disallow BR input but convert single newlines to BR
February 01, 2011 12:35PM

I modified AutoParagraph to convert each single newline in a given paragraph to . It works fantastically.

The problem is that to do it I had to allow 'br', which means my users can now fill the screen with line breaks.

How should I deal with this? I want HTMLPurifier to remove all the 'br' tags from user input, but I also want it to output 'br' tags when I tell it to. I thought about ripping them out with preg_replace before I run it through the purifier, but if a user wants to post pre-formatted code, that's going to be a problem.

Any ideas?

Re: Disallow BR input but convert single newlines to BR
February 01, 2011 12:39PM

Mm, you might be able to do something involving armor although I'm not sure if there are enough hooks to make that happen. Maybe something easier is to unconditionally strip brs in the MakeWellFormed stage, but keep br in the allowed elements array.

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: