patorjk / Extendible-BBCode-Parser

Allows you to parse BBCode and to extend the markup to add your own tags. All major tags are supported and parser reports back any errors it finds.
http://patorjk.com/bbcode-previewer/
MIT License
133 stars 54 forks source link

is it possible to parse bbcode with html tags in the string? #27

Closed patrikpatrik closed 3 years ago

patrikpatrik commented 3 years ago

For some reason when html tags are included in the string it doesn't seem to work properly.

For example if you had a string like "

The log is [color=brown][b] dirty[/b][/color]

"

it doesnt seem to parse the tags right but the bbcode will go through, or the tags will parse correctly with html() but the bbcode is changed to something weird..

patorjk commented 3 years ago

It's setup not to interpret HTML tags, so it'll change the <>'s into HTML entities.

patrikpatrik commented 3 years ago

@patorjk , Thank you for the quick response. Is there a way to interpret it with an option or anything?

patorjk commented 3 years ago

No, it's not setup to allow both HTML and BBCode. You could try commenting out these two lines:

https://github.com/patorjk/Extendible-BBCode-Parser/blob/master/xbbcode.js#L740

But I'm not sure what the exact effects would be, plus you'd be allowing any HTML into the result, which isn't a good idea.

patrikpatrik commented 3 years ago

That's right. So what would be the proper way of doing this? Sanitizing the string of all html tags except for the bbcodes, then parsing accordingly, then add the tags afterwards using vanilla js or jQuery no?

patorjk commented 3 years ago

That could work. Maybe replace <> with {}, run the bbcode parser, then swap back in the <>'s.

patrikpatrik commented 3 years ago

I might do that. Okay thank you.