jBBCode icon indicating copy to clipboard operation
jBBCode copied to clipboard

Parsing table newlines issue

Open pedjas opened this issue 9 years ago • 3 comments

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?

pedjas avatar Sep 05 '16 16:09 pedjas

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.

DaSourcerer avatar Sep 19 '16 10:09 DaSourcerer

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.

pedjas avatar Sep 21 '16 07:09 pedjas

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.

Art4 avatar Sep 21 '16 08:09 Art4