SBBCodeParser icon indicating copy to clipboard operation
SBBCodeParser copied to clipboard

Doesn't convert bbcode within url tags

Open cyphix333 opened this issue 10 years ago • 4 comments

Been looking for a good bbcode to html parser and so far SBBCodeParser has passed all the tests except it doesn't seem to parse bbcode inside [url] tags.... ie;

[url=http://moo.com][color=#9966ff]a colored text link[/color][/url]

is converted to:

<a href="http://moo.com">[color=#9966ff]a colored text link[/color]</a>

and..

[url=http://moo.com][b]a bold text link[/b][/url]

is converted to:

<a href="http://moo.com">[b]a bold text link[/b]</a>

cyphix333 avatar Feb 25 '15 16:02 cyphix333

I found the solution go to "classes/Node/Container/Document.php" and change the url Tag (starting from the line 564) to the following code :

new BBCode('url', function($content, $attribs, $node)
            {
                if(empty($attribs['default']))
                    $attribs['default'] = $content;

                // add http:// to www starting urls
                if(strpos($attribs['default'], 'www') === 0)
                    $attribs['default'] = 'http://' . $attribs['default'];
                // add the base url to any urls not starting with http or ftp as they must be relative
                else if(substr($attribs['default'], 0, 4) !== 'http'
                    && substr($attribs['default'], 0, 3) !== 'ftp')
                    $attribs['default'] = $node->root()->get_base_uri() . $attribs['default'];

                return '<a href="'.$attribs['default'].'">' . $content . '</a>';
            })

Khalilbz avatar Aug 15 '16 17:08 Khalilbz

Thanks for your post, but I ended up using NBBC instead :) One of the reasons being that this repo is no longer maintained - no commits in over 3 years now.

cyphix333 avatar Aug 16 '16 11:08 cyphix333

Good , but is there some problems in the NBBC parser ?

Khalilbz avatar Aug 17 '16 21:08 Khalilbz

No major issues that I can recall - it's a pretty solid parser, but not sure if it's maintained anymore either, but is built well and is very flexible.

cyphix333 avatar Aug 18 '16 10:08 cyphix333