Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2014-06-21 18:03:42

Michael
Member
Registered: 2014-04-05
Posts: 35

Function "clean_paragraphs"

It seems to me that this function does not work well.
It seems that the formats <p> and <br> is done randomly.
Anyway, generated semantics does not fit the context.

After commenting the following code, the context is ok:

function clean_paragraphs($text)
{
	// Add paragraph tag around post, but make sure there are no empty paragraphs

	$text = '<p>'.$text.'</p>';

	/*
	// Replace any breaks next to paragraphs so our replace below catches them
	$text = preg_replace('%(</?p>)(?:\s*?<br />){1,2}%i', '$1', $text);
	$text = preg_replace('%(?:<br />\s*?){1,2}(</?p>)%i', '$1', $text);

	// Remove any empty paragraph tags (inserted via quotes/lists/code/etc) which should be stripped
	$text = str_replace('<p></p>', '', $text);

	$text = preg_replace('%<br />\s*?<br />%i', '</p><p>', $text);

	$text = str_replace('<p><br />', '<br /><p>', $text);
	$text = str_replace('<br /></p>', '</p><br />', $text);
	$text = str_replace('<p></p>', '<br /><br />', $text);*/

	return $text;
}

(include/parser.php)

What do you think? Does the existence of this function makes sense?

Last edited by Michael (2014-06-21 19:21:05)


PS Sorry for my English, it's not my mother tongue. I try to do my best, but I'm still making mistakes.

Offline

#2 2014-06-22 15:40:21

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,047
Website

Re: Function "clean_paragraphs"

As far as I know, this works.

Can you post some example input and output that show how this is misbehaving?


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#3 2014-06-23 14:42:57

chris98
Member
From: England, United Kingdom
Registered: 2013-05-31
Posts: 906
Website

Re: Function "clean_paragraphs"

Have you added this into your own site pages? This doesn't work for me then, but I need CSS adding to that style sheet.

Offline

#4 2014-06-23 14:45:56

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,047
Website

Re: Function "clean_paragraphs"

Also, there's an opening comment ("/*") in that code that is not in the FluxBB source. Have you modified anything in that function?


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#5 2014-06-23 16:07:40

Michael
Member
Registered: 2014-04-05
Posts: 35

Re: Function "clean_paragraphs"

Yes- as I wrote- I /*edited*/ this function because it spoiled the context of the utterance.
Paragraphs styles have set the padding, what spoils the context IMO. Because instead of <br> sometimes function inserts a new paragraph.

I hope you understood me. My English is bad.


PS Sorry for my English, it's not my mother tongue. I try to do my best, but I'm still making mistakes.

Offline

#6 2014-06-24 08:06:36

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,047
Website

Re: Function "clean_paragraphs"

Please provide some example input, the output of the function and your expected output.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#7 2014-06-24 13:52:24

Michael
Member
Registered: 2014-04-05
Posts: 35

Re: Function "clean_paragraphs"

For example, when I push a few enters, it is converted to a new paragraph.

input:

	Hi there.
Here is a example message.

		best regards

output:

<p>Hi there.<br>
Here is a example message.</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; best regards</p>

PS Sorry for my English, it's not my mother tongue. I try to do my best, but I'm still making mistakes.

Offline

#8 2014-06-24 14:06:51

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,047
Website

Re: Function "clean_paragraphs"

This looks fine to me. Let me explain how the algorithm works:

1. Trim whitespace. All whitespace (new lines, tabs and spaces) are removed from the beginning and end of the post.

Hi there.
Here is a example message.

		best regards

2. Split into paragraphs. Empty lines in the middle of a post means the user wants to start a new paragraph. Thus, this is where we split up the post.

<p>Hi there.
Here is a example message.</p>
<p>		best regards</p>

3. Detect linebreaks. Whenever the user inserts a line break inside a paragraph, we convert that into a BR tag.

<p>Hi there.<br>
Here is a example message.</p>
<p>		best regards</p>

Last but not least, whitespace at the beginning of paragraphs is converted to non-breaking spaces.

I hope this helps.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

Board footer

Powered by FluxBB 1.5.8