Advertisement:

Author Topic: Use <p></p> instead of <br /><br />  (Read 19210 times)

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Use <p></p> instead of <br /><br />
« on: October 23, 2009, 04:21:58 PM »
This should be easy to fix since I did it myself with no experience with PHP. Basically, everywhere there's a line break in a the text of a posting, a <br /> tag is inserted. If there's a double line break - indicating a paragraph where a paragraph tags should be used - a then <br /><br /> is inserted. If there's more line breaks, then more <br />'s are inserted. It could also use a little source code clean up.

To fix this, I did the following for each posting:

echo '<p>',str_replace("<br />","<br />
   ", str_replace("<br /><br />", "</p>
   <p>", $array['body'])),'</p>';

That bit of code will put breaks in the HTML source code to match single line breaks, and it'll put <p></p> tags around paragraphs separated by double line breaks.

If there's an even number of more than two line breaks, it will give empty <p></p> tags. For odd numbers of more than two line breaks, it will give empty <p></p> tags followed by a <br />. That's a new bug introduced by this code that should be fixed somehow by recognizing sequences of more than two <br /> tags and then just leaving them alone without trying to make paragraphs out of them.

This fix will make the code more semantically correct and search engine friendly, as well as making it easier to style with custom styles in all cases, so please fix this! The simple solution I found isn't perfect, but it's still a dramatic improvement over the current method.

I'm using SMF 1.1.10 at http://www.livebusinesschat.com/
« Last Edit: November 06, 2009, 07:51:12 PM by SleePy »

Offline SleePy

  • Site Team Lead
  • SMF Master
  • *
  • Posts: 29,934
  • Gender: Male
  • Thats his happy face.
    • jdarwood007 on GitHub
    • @jdarwood on Twitter
    • SleePy Code - My personal site
Re: Use <p></p> instead of <br /><br />
« Reply #1 on: November 06, 2009, 07:50:57 PM »
I believe this was done due to how some browsers handle the paragraph tag.
Jeremy D — Site Team / SMF Developer
Support the SMF Support team!
Profiles:
GitHub

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #2 on: November 06, 2009, 08:04:12 PM »
Maybe it's time to stop doing that. I can't think of any browsers that don't handle the paragraph tag correctly, especially when its properties are defined with CSS. Do you have any other info about why this is still being done?

Offline JBlaze

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,152
    • @fragicide on Twitter
Re: Use <p></p> instead of <br /><br />
« Reply #3 on: November 06, 2009, 08:49:25 PM »
I see no problem in it at all. Why make a fuss?

I can see the problem in using <b> and <i> tags as they are deprecated, but seeing that <br /> isn't, why bother?

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #4 on: November 06, 2009, 08:55:04 PM »
Because it makes CSS styling of paragraphs impossible.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,049
    • Arantor on GitHub
Re: Use <p></p> instead of <br /><br />
« Reply #5 on: November 07, 2009, 07:43:16 AM »
Except that it would actually cause MANY other problems.

Don't forget, <br /> is used, AFAIR, in the code tag. You CANNOT wrap chunks of code inside <p> </p> because that would make any instance of a blank line in code be broken into separate paragraphs and would force it to be styled, likely, incorrectly.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #6 on: November 07, 2009, 12:53:16 PM »
I'm not talking about code, I'm talking about paragraphs. Paragraphs MUST have paragraph tags.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,049
    • Arantor on GitHub
Re: Use <p></p> instead of <br /><br />
« Reply #7 on: November 07, 2009, 01:02:58 PM »
You're missing my point.

\n => <br /> is done globally, prior to any BBC handling, IIRC. To do it how you're suggesting, it would have to step through every instance of \n\n and figure out if it's inside code or php (or any one of a number of custom tags) and figure out if it's supposed to replace it or not.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #8 on: November 07, 2009, 01:11:13 PM »
I'm not suggesting how it should be done, I'm just pointing out that it's not hard. Even if it were hard, it should still be done because the current <br /> tag method is wrong, for both technical reasons, and practical reasons. I'm sure it was expedient though, and that's fine. Working software is always better than no software, but it should be on the list of things to do for the future.

As I mentioned before, I have solved the problem myself already, and I don't have to deal with code tags because BBcode is disabled on my system.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,049
    • Arantor on GitHub
Re: Use <p></p> instead of <br /><br />
« Reply #9 on: November 07, 2009, 01:15:15 PM »
You're missing my point, again. It *IS* that hard for the general use-case where bbcode is enabled. It's fine for you, though.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #10 on: November 07, 2009, 01:52:06 PM »
BBcode is not hard to parse, that's why it's there.

Offline SleePy

  • Site Team Lead
  • SMF Master
  • *
  • Posts: 29,934
  • Gender: Male
  • Thats his happy face.
    • jdarwood007 on GitHub
    • @jdarwood on Twitter
    • SleePy Code - My personal site
Re: Use <p></p> instead of <br /><br />
« Reply #11 on: November 07, 2009, 08:02:42 PM »
qwasty,
I can't remember the exact browser or case (Its hard enough to remember all I do).  But it was mostly with padding and margins I believe that browsers impose by default.

None the less, this is to late for SMF 2.0.  So I will move this to our feature requests board.
Jeremy D — Site Team / SMF Developer
Support the SMF Support team!
Profiles:
GitHub

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #12 on: November 07, 2009, 08:20:23 PM »
I've been using paragraph tags for years. I've never run into a problem as long as I specify the styling I want. I hope you'll revisit this when it comes time to update SMF again after the release of 2.0.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,049
    • Arantor on GitHub
Re: Use <p></p> instead of <br /><br />
« Reply #13 on: November 07, 2009, 08:23:16 PM »
You have again missed my point.

Right now every single instance of \n becomes <br />.

If you want to have \n\n become <p>, you will have to go through and evaluate every single \n to determine if it's inside a code tag or not. So instead of a bulk replace, you CAN'T do that and have to step through it again and again and again which is much, much slower.

You don't use code tags on your forum, the impact would not be as drastic to you, but the contents of code tags MUST be retained, whitespace inclued, otherwise you may as well remove any hope of using SMF for tech support where the contents must be preserved.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #14 on: November 07, 2009, 08:43:45 PM »
I haven't missed your point Arantor. You've told me several times before that what I wanted to do was too hard. Each time I've ignored you, and I promptly found an easy way to do it. Your time is better spent responding to issues you know how to solve, rather than discouraging people from achieving their goals with SMF.

Offline Adish - (F.L.A.M.E.R)

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,614
  • Gender: Male
  • I am a ninja!
    • adishpatel on Facebook
    • https://www.linkedin.com/in/adishpatel on LinkedIn
Re: Use <p></p> instead of <br /><br />
« Reply #15 on: November 07, 2009, 09:00:00 PM »
@qwasty
That is harsh buddy. The SMF team knows what is going on. People just don't get into the team without knowing the codes around in SMF. It is the dedication and the skills they have. Arantor has been one of the best Team member around solving issues that you might have never dreamed of. Making such harsh comments on a Ex-Team member (currently) would be very inappropriate.

Your suggestions are always welcomed, but don't do personal attacks please.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,136
  • Master of BBC Abuse
Re: Use <p></p> instead of <br /><br />
« Reply #16 on: November 08, 2009, 01:29:40 AM »
I haven't missed your point Arantor. You've told me several times before that what I wanted to do was too hard. Each time I've ignored you, and I promptly found an easy way to do it. Your time is better spent responding to issues you know how to solve, rather than discouraging people from achieving their goals with SMF.

You have not found "an easy way to do it". You have found an easy way to do it when BBC is disabled. If you can find an equally easy way to do it with full BBC enabled, and it is robust in all browsers, and it does not cause any other problems, then you will have a point.

Note that I'm not saying you can't do this, just that it hasn't been done yet as far as I can tell.

Offline 青山 素子

  • Server Team
  • SMF Super Hero
  • *
  • Posts: 17,021
  • 戦場ヶ原、蕩れ!
    • srvrguy on GitHub
    • @motokochan on Twitter
    • Nekomusume Moe
Re: Use <p></p> instead of <br /><br />
« Reply #17 on: November 08, 2009, 01:47:27 AM »
qwasty, we are quite willing to listen to suggestions and are even interested in methods to accomplish something.

The problem here is that your method has huge side-effects with built-in BB Code items such as [code], [php] and similar blocks where line breaks must be preserved as entered. Your solution destroys that.

If you can come up with a way to accurately detect these situations and still get the result you wish, please do post about it. Until then, arguing with team members and former team members over a valid point they have is a bad way to win support.
Motoko-chan
Director, Simple Machines

Just because it's pouring down doesn't mean we're gonna drown. There's a time when all you can say is let it rain - Mat Kearney (Let It Rain)

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


Offline Red G. Brown

  • Jr. Member
  • **
  • Posts: 225
Re: Use <p></p> instead of <br /><br />
« Reply #18 on: November 08, 2009, 01:56:57 AM »
My solution solves my problem. Your problem is more complex, but similar. Either way, it can and should be done. There's no reason not to use <br /> tags to format BBcode cleanly. Code isn't paragraphs anyway. That's all I've got to say about this. The rest is up to you.

Offline 青山 素子

  • Server Team
  • SMF Super Hero
  • *
  • Posts: 17,021
  • 戦場ヶ原、蕩れ!
    • srvrguy on GitHub
    • @motokochan on Twitter
    • Nekomusume Moe
Re: Use <p></p> instead of <br /><br />
« Reply #19 on: November 08, 2009, 02:03:38 AM »
Nobody is saying it shouldn't be done. Rather, simply, that your solution is not a good general purpose solution, which you seemed to be advertising.

We are too late in the 2.0 development cycle to cover this request, but it will be noted and possibly looked at when we open development back up.
Motoko-chan
Director, Simple Machines

Just because it's pouring down doesn't mean we're gonna drown. There's a time when all you can say is let it rain - Mat Kearney (Let It Rain)

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.