Welcome! » Log In » Create A New Profile

AutoFormat.AutoParagraph needs to support single new lines

Posted by cyphix333 
AutoFormat.AutoParagraph needs to support single new lines
April 05, 2015 09:24AM

I have just started using HtmlPurifier and think it's awesome, however it comes with one caveat; the lack of single new line support and being able to turn them into line-breaks.

I was initially turning all line-breaks into

<br>

tags but didn't like this as it wasn't semantically correct so I started using "AutoFormat.AutoParagraph", but the fact it doesn't convert single newlines is quite a big downfall for me. :(

I have searched the net about it and found numerous people asking the same thing, so seems like I am not alone in wanting this.

I am going to have to go back to using all

<br>

tags until you add support for this, hopefully it is soon!

Re: AutoFormat.AutoParagraph needs to support single new lines
April 05, 2015 07:37PM

I don't think this would be a difficult injector to write.

Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 02:08AM

I don't think this would be a difficult injector to write.

Well I guess what I was asking is that I was hoping it could be built into HtmlPurifier by default. Obviously as you would understand it's not as simple as replacing all line breaks with

<br>

tags as it depends on where the line breaks appear within the html.

I imagine the %AutoFormat.AutoParagraph functionality already takes in account all of this so it shouldn't be too hard to include converting single line breaks as well?

Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 02:15AM

Right. Also, autoparagraph is a bit complicated because it has to figure out when new paragraph start, but a br injector would just insert a br every time there's a newline.

Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 02:34AM

Right. Also, autoparagraph is a bit complicated because it has to figure out when new paragraph start, but a br injector would just insert a br every time there's a newline.

Well you couldn't really do that because, consider the following code:

<ul>
  <li>cat</li>
  <li>dog</li>
  <li>fish</li>
  <li>horse</li>
</ul>
  • Line breaks BEFORE the starting list tag should be converted
  • Line breaks AFTER the starting list tag shouldn't be converted
  • Line breaks BEFORE the starting list item tag shouldn't be converted
  • Line breaks AFTER the starting list item tag should be converted
  • Line breaks BEFORE the closing list item tag should be converted
  • Line breaks AFTER the closing list item tag shouldn't be converted
  • Line breaks BEFORE the closing list tag shouldn't be converted
  • Line breaks AFTER the closing list tag should be converted
Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 02:45AM

Yeah, the autoparagraph injectors handles this by testing if a p tag is allowed in a context before attempting to insert it. You'll want that code.

Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 03:00AM

Alright thnaks.

So you don't think this is going to be something that's going to be included by default as an injector?

Where can I go to learn about creating injectors with HtmlPurifier?

Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 03:05AM

My suggestion is to just read the source. AutoParagraph is a bit complicated; Linkify would be easier to adapt.

Re: AutoFormat.AutoParagraph needs to support single new lines
April 06, 2015 03:19AM

Alright - cheers!

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: