Open veger opened 9 years ago
+1
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...
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.
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