ruby-bbcode icon indicating copy to clipboard operation
ruby-bbcode copied to clipboard

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

Open veger opened this issue 10 years ago • 4 comments

It is nicer (HTML) to use paragraphs (<p>...</p>) instead of <br /> for newlines/paragraphs.

Furthermore, the <p> HTML elements can be styled (e.g. using CSS) making the output more flexible

veger avatar Feb 03 '15 11:02 veger

+1

TheNotary avatar Feb 03 '15 19:02 TheNotary

Simple adding paragraphs using something like:

node[:text].gsub("\r\n", "\n").map {|s| "<p>#{s}</p>"}.join("")

results in (lots of) paragraphs around each text section, for example

"This is [b]bold[/b] and this [i]italic[/i]."

becomes

 "<p>This is</p><b><p>bold</p></b><p> and this </p><i><p>italic</p></i><p>.</p>"

Lots of paragraphs, even without a single newline!

Using

node[:text].gsub("\r\n", "\n").gsub("\n", "</p>\n<p>")

and putting the opening and ending tag before and after the test, solves this But it easily results in invalid HTML. The following is valid bbcode:

"This is [b] line 1
and this[/b] line 2."

but would become

"<p>This is <b> line 1</p>
<p>and this </b> line 2.</p>"

So solving this issue is not as trivial as I initially assumed and some more thoughts on the subject are required...

veger avatar Feb 11 '15 22:02 veger

Additionally, using the <p>-tags, limits the allowed contents (no tables, frames, blocks, etc.). So it might be better to use <div>-tags, as these support any/most content.

veger avatar Feb 11 '15 22:02 veger

Just a reminder. According to the official reference, newlines should not be treated as paragraph borders (see tag [*]). Double newlines however can be.

almaron avatar May 24 '19 20:05 almaron