Wrap text output in paragraph tags

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
GravityDK
Registered User
Posts: 36
Joined: Sat Aug 28, 2010 10:19 am

Wrap text output in paragraph tags

Post by GravityDK »

Outcome: Instead of using linebreaks, wrap paragraphs in <p> tags.
Rationale: This is semantically correct HTML5. It also allows for typographic control of spacing between paragraphs.

How to implement was outlined in this thread.

Change functions_content.php from

Code: Select all

function bbcode_nl2br($text)
{
   // custom BBCodes might contain carriage returns so they
   // are not converted into <br /> so now revert that
   $text = str_replace(array("\n", "\r"), array('<br />', "\n"), $text);
   return $text;
}
to:

Code: Select all

function bbcode_nl2br($text)
{
   //  It looks like this works.  Can't put in multiple lines of whitespace, though.
   // first, lets trim starting/trailing whitespace

   $text = trim($text);
   
   // temporarily replace two or more consecutive newlines
   // into SOH characters (not used in normal text)
   
   $text = preg_replace('~(\r\n|\n){2,}|$~', "\001", $text);
   
   // convert remaining (i.e. single) newlines into html br's
   
   $text = nl2br($text);
   
   // finally, replace SOH chars with paragraphs
   
   $text = preg_replace('/(.*?)\001/s', '<p>$1</p>' . "\n", $text); 
   return $text; 
}
Unwanted consequence: "The only problem I saw was that using this code nobody could put in multiple lines of whitespace. You know how someone will say something at the top of a post, put in a bunch of blank lines forcing you to scroll down then reveal the answer below? That wouldn't be possible with this code as all the newlines are removed. But otherwise, it looks pretty good. "

Also required is to change content.css font-sizes from the below, to desired sizes; perhaps 1.0 em.

Code: Select all

.panel p {
   font-size: 1.2em;
   margin-bottom: 1em;
   line-height: 1.4em;
}

.content p {
   font-family: "Lucida Grande", "Trebuchet MS", Verdana, Helvetica, Arial, sans-serif;
   font-size: 1.2em;
   margin-bottom: 1em;
   line-height: 1.4em;
}

Nelsaidi
Registered User
Posts: 122
Joined: Tue Nov 11, 2008 5:44 pm

Re: Wrap text output in paragraph tags

Post by Nelsaidi »

Or rather than editting the function which mods depend on and adding tags forcefully could break it you simply add it in the template?

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 138
Joined: Sun Dec 18, 2005 5:44 pm
Location: Texas
Contact:

Re: Wrap text output in paragraph tags

Post by Noxwizard »

You can't just put paragraph tags around everything because several of the BBCodes will break the validity.

GravityDK
Registered User
Posts: 36
Joined: Sat Aug 28, 2010 10:19 am

Re: Wrap text output in paragraph tags

Post by GravityDK »

I don't know if that's the ideal place to make the change, but the intent is clear: improve the HTML produced by phpBB by using <p> tags. Is there a better place it could be put?

Post Reply