Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse returns #63

Open
Studio384 opened this issue Nov 8, 2015 · 2 comments
Open

Parse returns #63

Studio384 opened this issue Nov 8, 2015 · 2 comments

Comments

@Studio384
Copy link

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.

@DaSourcerer
Copy link
Contributor

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.

@Art4
Copy link
Contributor

Art4 commented Sep 19, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants