News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Use <p></p> instead of <br /><br />

Started by Red G. Brown, October 23, 2009, 04:21:58 PM

Previous topic - Next topic

Red G. Brown

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/

SleePy

I believe this was done due to how some browsers handle the paragraph tag.
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

Red G. Brown

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?

JBlaze

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?
Jason Clemons
Former Team Member 2009 - 2012

Red G. Brown

Because it makes CSS styling of paragraphs impossible.

Arantor

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.

Red G. Brown

I'm not talking about code, I'm talking about paragraphs. Paragraphs MUST have paragraph tags.

Arantor

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.

Red G. Brown

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.

Arantor

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.

Red G. Brown

BBcode is not hard to parse, that's why it's there.

SleePy

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 ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

Red G. Brown

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.

Arantor

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.

Red G. Brown

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.

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

@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.

Antechinus

Quote from: qwasty 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.

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.

青山 素子

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

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


Red G. Brown

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.

青山 素子

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

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


Advertisement: