Simple Machines Community Forum

SMF Development => Feature Requests => Applied or Declined Requests => Topic started by: Red G. Brown on October 23, 2009, 04:21:58 PM

Title: Use <p></p> instead of <br /><br />
Post by: Red G. Brown 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/
Title: Re: Use <p></p> instead of <br /><br />
Post by: SleePy on November 06, 2009, 07:50:57 PM
I believe this was done due to how some browsers handle the paragraph tag.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown 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?
Title: Re: Use <p></p> instead of <br /><br />
Post by: JBlaze 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?
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 06, 2009, 08:55:04 PM
Because it makes CSS styling of paragraphs impossible.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 07, 2009, 12:53:16 PM
I'm not talking about code, I'm talking about paragraphs. Paragraphs MUST have paragraph tags.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 07, 2009, 01:52:06 PM
BBcode is not hard to parse, that's why it's there.
Title: Re: Use <p></p> instead of <br /><br />
Post by: SleePy 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Adish - (F.L.A.M.E.R) 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Antechinus on November 08, 2009, 01:29:40 AM
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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: 青山 素子 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: 青山 素子 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.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 08, 2009, 02:06:28 AM
OK, thank you. Is there a way I can follow progress on my feature requests? Is it tracked in this thread, or somewhere else?
Title: Re: Use <p></p> instead of <br /><br />
Post by: 青山 素子 on November 08, 2009, 02:17:29 AM
We don't have a formal feature tracking solution in place at this time. Sorry.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Vveb.ws on November 10, 2009, 12:29:32 AM
Quote from: qwasty on October 23, 2009, 04:21:58 PM
... 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>';
Nobody can estimate your VERY GOOD IDEA !

with this code we can mark paragrafs with indent
CSS: div.po p { text-indent:40px; }
<div class=po> be writen in BB-codes: <div class=po> <p>...</p> </div>

Can't you answer me, where is this code you write ? please

I want to replace <br /> to </p><p>&nbsp;, but where - I do not know  :-[
I think my replace <br /> to </p><p>&nbsp; more simply and useful.

In my topic I have'nt receive answer - In what file should replace transfer line in message from <br /> to </ p><p> ? (http://www.simplemachines.org/community/index.php?topic=346797.msg2346822#msg2346822)
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 10, 2009, 01:01:11 AM
I did it with $news['body'] in my own version of the ssi_boardNews() function for use on the http://www.livebusinesschat.com/ website. I didn't modify my forum because it wasn't necessary for me.

I'm sure somewhere in Display.php there is something like $news['body'] that you could alter with my code, if you're not worried about the bad things that might happen.

You could find this code in Display.php (SMF version 1.1.10):

// Run BBC interpreter on the message.
$message['body'] = parse_bbc($message['body'], $message['smileysEnabled'], $message['ID_MSG']);

And replace it with

// Run BBC interpreter on the message.
$message['body'] = parse_bbc($message['body'], $message['smileysEnabled'], $message['ID_MSG']);

// Get rid of <br /><br /> and replace with paragraph tags
$message['body'] = '<p>' . str_replace("<br />","<br />
   ", str_replace("<br /><br />", "</p>
   <p>", $message['body'])) . '</p>';

I don't know if that will work, but even if it does, I'm sure it will cause some problems. Use it at your own risk, and SAVE A BACKUP of Display.php so you can undo it if there are unacceptable problems.

If anyone else knows a better solution, please post it.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Vveb.ws on November 10, 2009, 04:24:41 AM
Thank you very much !

Sources/Display.php - lines 890-891
After (where you say):
// Run BBC interpreter on the message.
$message['body'] = parse_bbc($message['body'], $message['smileysEnabled'], $message['ID_MSG']);

I have little rewrite your code and insert this:
// Get rid of <br /><br /> and replace with paragraph tags
$message['body'] = '<p>&nbsp;' . str_replace("<br />", "</p><p>&nbsp;",  $message['body']) . '</p>';

Result - very good :) :
<div class="post" id="msg_10"><p>&nbsp;PARAGRAF-1 </p><p>&nbsp;PARAGRAF-2 </p></div>
sample - _http://ozdorovlenie.vveb.ws/index.php/topic,7.0.html

in the begininng of each paragraf there is &nbsp; - it's not concern me :)
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 10, 2009, 12:42:50 PM
My code handles single <br />, and double <br /><br />. You only want to change double <br /><br /> to paragraph tags. Your code changes them all. For example, with your code, this:

Hi
There is a single <br /> after "Hi"

Would be incorrectly changed to this:

Hi

There is a single <br /> after "Hi"
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor on November 10, 2009, 12:44:26 PM
What happens if you have triple <br />?

Supposing I have two paragraphs with two lines of space, to visually separate the paragraphs?
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 10, 2009, 02:25:37 PM
I use a few other functions to take care of that. I remove all extra whitespace.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor on November 10, 2009, 02:32:30 PM
The approach works for you, but it's another instance of headaches for me personally; it's also one of the things that perpetually drives me mad with MediaWiki to the point where if I want to layout content how I want it laid out I have to do it manually in raw HTML.

My personal view is that while <p> </p> is generally good, I can also see issues with users who put two blank lines in their post and expect to get the same two blank lines in their displayed post; there is a certain expectation there.

As a general rule that while the semantic value and technical value of <p> </p> is better, the average forum admin actually doesn't care. Most admins/webmasters haven't commented that much on the new theme and semanticisation in RC2, in fact neither have most modders that I can see, because it just works for them. I think there is a certain case for that here too.

Bottom line: it would be great to do. But there will come a point where doing it would actually prove more problematic than not doing it for the general use case. Tweaking for individual forums is fine - in your case you mention you strip whitespace. But that's not something that can be done for all cases, and is actually likely to lead to bug reports because the software is trying to guess how I want it handled.

It does to a point come back to Do What I Mean versus Do What I Say and someone's going to end up being wrong :(
Title: Re: Use <p></p> instead of <br /><br />
Post by: Red G. Brown on November 10, 2009, 02:44:36 PM
I'd have to check my code again, but I might be wrong. I think maybe I only convert the first instance of of <br /><br />, and leave the rest. In any case, that would be easy enough to do. You get paragraphs, and if there's extra line breaks, you keep them. There's nothing wrong with that.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor on November 10, 2009, 02:49:42 PM
Depends on the browser, actually.

From what I remember, some browsers would not process the <br /> if it opens the paragraph and would simply collapse it.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Vveb.ws on November 11, 2009, 05:47:43 AM
Guys!
What you are arguing at all?
In our country, so arguing only on politics and elections.

On those issues, which do not? What these replacement once can cause some problems? Why guess beforehand? Forum works and  well! As we say: "While the roasted cock did not bite, Cossack did not cross himself."

1) After all the standard bb-codes (table, quote, code) I put <p> - to the next line was a paragraph, not a simple line

2) shows the complete code of their replacements, with all corrections:

// Get rid of <br /><br /> and replace with paragraph tags
$message['body'] = '<p>' . str_replace("<br /><br />", "</p><p>&nbsp;</p><p>", str_replace("<br />", "</p><p>",  $message['body'])) . '</p>';
$message['body'] = str_replace("<p><table", "<table", str_replace("<p><p", "<p", str_replace("<p><table", "<table", str_replace("<p><p", "<p", str_replace("<p></td>", "</td>", str_replace("</p></p>", "</p>", str_replace("<p><pre>", "<pre>", str_replace("</pre></p>", "</pre>", str_replace("<p><div", "<div", str_replace("<p><h1>",  "<h1>", str_replace("<p><h2>", "<h2>", str_replace("<p></p>", "<p>&nbsp;</p>", $message['body'])))))))))))) ;


You can see for themselves that I have very clean code and NO PROBLEMS on my forum _http://ozdorovlenie.vveb.ws  after such substitutions (forum in russian language :) )

if this important for you...
Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor on November 11, 2009, 06:50:27 AM
I don't see that we're arguing exactly, more that we are both coming at this from different points of view; whenever I get into technical discussions I have to look at it from the wider context, from both my own and from the viewpoint of others and all the different uses this can be put to.

I would like to point out that your second instruction can be simplified and made faster like so:

$message['body'] = str_replace(array("<p></p>", "<p><h2>", "<p><h1>", "<p><div", "</pre></p>", "<p><pre>", "</p></p>", "<p></td>", "<p><p", "<p><table", "<p><p", "<p><table"), array("<p>&nbsp;</p>", "<h1>", "<h2>", "<div",  "</pre>", "<pre>", "</p>", "</td>", "<p", "<table", "<p", "<table"), $message['body']);

The operations will be done in the same order.
Title: Re: Use <p></p> instead of <br /><br />
Post by: Vveb.ws on November 11, 2009, 01:00:38 PM
You have mistakes the number for "<h2>", "<h1>" (need "<h1>", "<h2>") ;)
It's works too ! THANKS !

Title: Re: Use <p></p> instead of <br /><br />
Post by: Arantor on November 11, 2009, 03:00:49 PM
Meh, I copy pasted it slightly wrong.

$message['body'] = str_replace(array("<p></p>", "<p><h2>", "<p><h1>", "<p><div", "</pre></p>", "<p><pre>", "</p></p>", "<p></td>", "<p><p", "<p><table", "<p><p", "<p><table"), array("<p>&nbsp;</p>", "<h2>", "<h1>", "<div",  "</pre>", "<pre>", "</p>", "</td>", "<p", "<table", "<p", "<table"), $message['body']);
Title: Re: Use <p></p> instead of <br /><br />
Post by: ascaland on November 14, 2009, 01:22:38 AM
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.

Ironic you mention that considering your the one being ignorant and rude while your "idea" isnt so great at all. If anything, your the discouraging one for refusing to listen.

http://webdesign.about.com/od/htmltags/a/aabg092299a.htm