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

OK, thank you. Is there a way I can follow progress on my feature requests? Is it tracked in this thread, or somewhere else?

青山 素子

We don't have a formal feature tracking solution in place at this time. Sorry.
Motoko-chan
Director, Simple Machines

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


Vveb.ws

#22
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> ?

Red G. Brown

#23
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.

Vveb.ws

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 :)

Red G. Brown

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"

Arantor

What happens if you have triple <br />?

Supposing I have two paragraphs with two lines of space, to visually separate the paragraphs?
Holder of controversial views, all of which my own.


Red G. Brown

I use a few other functions to take care of that. I remove all extra whitespace.

Arantor

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 :(
Holder of controversial views, all of which my own.


Red G. Brown

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.

Arantor

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.
Holder of controversial views, all of which my own.


Vveb.ws

#31
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...

Arantor

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.
Holder of controversial views, all of which my own.


Vveb.ws

You have mistakes the number for "<h2>", "<h1>" (need "<h1>", "<h2>") ;)
It's works too ! THANKS !


Arantor

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']);
Holder of controversial views, all of which my own.


ascaland

#35
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

Advertisement: