1
macgeek
A fixed nl2Br -- no more extra white space
  • 2004/9/13 11:47

  • macgeek

  • Just popping in

  • Posts: 5

  • Since: 2004/9/6 1


Coming from other CMSes I've found the way XOOPS handles text to be extremely annoying. Luckily, there were a significant amount of other things that made me use it for my upcoming site and I am, overall, quite happy. But I had to fix that damned "extra white space" problem when posting.

After hunting for a while I found it was the nl2Br function that was very, very simply-implemented. I made a smart version. This version has some simple rules:

1. If there is an HTML tag at either end, remove all white space so it doesn't get parsed. This fixes the "too much white space above the tables" problem.
2. If there are a bunch of new lines between things, put one P tag in its place.
3. It there is one new line in-between two lines, place a BR.

Enjoy.

function &nl2Br($text)
{
    
/*
    If there are two or more NLs between things, add a 
    If there is one NL then make it a .
    
    If the last non-white-space char before the line break was
    the end of a tag, don't add anything.
    */
    
    //Remove white space between HTML tags and a preceding
    //or following new line. (And the new line itself.)
    
$text preg_replace("/(<.*?>)s*[rn]s*/","$1"$text);
    
$text preg_replace("/s*[rn]s*(<.*?>)/","$1"$text);
    
    
//Single returns become single breaks.
    //This is before the  handler because it would match these as well.
    
$text preg_replace("/([^rn])rn([^rn])/","$1$2"$text);
    
    
//Multiple returns become one paragraph break.
    
$text preg_replace("/[rn]+/",""$text);
    
    
//Remaining chars become breaks.
    
$text preg_replace("/n/",""$text);
    
$text preg_replace("/r/",""$text);
    
    return 
$text;     
}

2
macgeek
Re: A fixed nl2Br -- no more extra white space
  • 2004/9/13 14:16

  • macgeek

  • Just popping in

  • Posts: 5

  • Since: 2004/9/6 1


Upon further investigation, this horks PRE tags. Still working :)

3
macgeek
Re: A fixed nl2Br -- no more extra white space
  • 2004/9/13 14:47

  • macgeek

  • Just popping in

  • Posts: 5

  • Since: 2004/9/6 1


Feh. Can't get around PRE tags, but adding this above the default line works well. It eliminates line breaks around HTML tags.

//Remove white space between HTML tags and a preceding or following new line.
                //(And the new line itself.)
                
$text preg_replace("/(<.*?>)s*[rn]s*/","$1"$text);
                
$text preg_replace("/s*[rn]s*(<.*?>)/","$1"$text);

4
Stewdio
Re: A fixed nl2Br -- no more extra white space
  • 2004/9/13 14:55

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


Thanks for the updates and investigation. Perhaps you could also submit your changes to the source forge. I'm assuming of course that this is in the text sanitiser, just so that others know where to look when and if they decide to add your changes.

5
moss
Re: A fixed nl2Br -- no more extra white space
  • 2019/12/10 14:02

  • moss

  • Just popping in

  • Posts: 38

  • Since: 2009/10/28


Hello,

I have Xoops 2.5.9 and I have this issue with table... I tried to play with module.textsanitizer.php and function nl2Br($text) but it doesn't work.

Can I have some help

Thanks

Login

Who's Online

253 user(s) are online (174 user(s) are browsing Support Forums)


Members: 0


Guests: 253


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits