jBBCode icon indicating copy to clipboard operation
jBBCode copied to clipboard

Parse returns

Open Studio384 opened this issue 10 years ago • 2 comments

Hello,

I'm trying to put jBBCode into a project of mine. For that, the code I've written fetches data from a database and puts that code through jBBCode, however, jBBCode seems to ignore returns completely. So text written in separate paragraphs make just a single paragraph. Is there any way to put every block of text between the p-tag in HTML without users having to put additional BBCode in their comments?

Thanks in advance.

Studio384 avatar Nov 08 '15 20:11 Studio384

Auto-paragraphs are difficult to achieve. You can try to split the output by double linebreaks and insert tags there. But the error rate would probably be high. IMHO it would be much easier to implement a NodeVisitor that is applying nl2br() on all TextNodes.

DaSourcerer avatar Sep 19 '16 10:09 DaSourcerer

I have implemented this feature in a parser for a project: https://github.com/youthweb/bbcode-parser But it isn't simple.

I implemented it this (theoretical easy) way: After $parser->getAsHtml() replace a single line break with <br /> and two line breaks with </p>\n<p>. Then prepand a <p> and append a </p> to the text. See https://github.com/youthweb/bbcode-parser/blob/master/src/Manager.php#L132

The problem is that not every HTML tag should be inside the p-Tag (like <list>, <code> or <h1>). So I prepand and append a marker where not to add a <p>. See https://github.com/youthweb/bbcode-parser/blob/master/src/DefinitionSet/HeadlineSet.php#L35

You can also look at the testsuite to see, how the parser will work: https://github.com/youthweb/bbcode-parser/blob/master/tests/integration/ParsingTest.php#L142

I hope this will help you.

Art4 avatar Sep 19 '16 11:09 Art4