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

Parsing table newlines issue #69

Open
pedjas opened this issue Sep 5, 2016 · 3 comments
Open

Parsing table newlines issue #69

pedjas opened this issue Sep 5, 2016 · 3 comments

Comments

@pedjas
Copy link

pedjas commented Sep 5, 2016

I have set definitions to parse BBC for table as:

    //table
    $builder = new \JBBCode\CodeDefinitionBuilder('table', '<table><tbody>{param}</tbody></table>');
    array_push($this->definitions, $builder->build());

    //thead
    $builder = new \JBBCode\CodeDefinitionBuilder('th', '<th>{param}</th>');
    array_push($this->definitions, $builder->build());

    //tr
    $builder = new \JBBCode\CodeDefinitionBuilder('tr', '<tr>{param}</tr>');
    array_push($this->definitions, $builder->build());

    //td
    $builder = new \JBBCode\CodeDefinitionBuilder('td', '<td>{param}</td>');
    array_push($this->definitions, $builder->build());

It forks fine except it requires all BBC in a table to be in single line. If any part of table is split to new line, empty line will be inserted on top of rendered TABLE.

When dealing with tables it is necessary to split table to several lines and even make indentation for elements to make it readable.

Is there a way to clean all new lines and spaces outside of TR and TD tags within a TABLE?

@DaSourcerer
Copy link
Contributor

Well, I guess you could implement a NodeVisitor that is removing all leading and trailing whitespaces via trim() in the TextNodes of your table. In general it is not a good idea to implement tables in BBCode, though.

@pedjas
Copy link
Author

pedjas commented Sep 21, 2016

Well it is necessity. The same issue is with lists or other HTML tags that have inner structure.

Thing is trim should not be executed always. IT should be optional. I guess good solution would be to provide events so we can add our own code to handle such situations for BBC that needs it.

@Art4
Copy link
Contributor

Art4 commented Sep 21, 2016

For complex tags like [list] or [table] I would recommend to create a own CodeDefinition instead of using CodeDefinitionBuilder.

Here you can see my implementation for [list]: https://github.com/youthweb/bbcode-parser/blob/master/src/Definition/ListDefinition.php

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