Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.8k stars 876 forks source link

Consider adding BBCode support? #763

Closed mark8044 closed 2 years ago

mark8044 commented 3 years ago

BBCode is used on a large number of bulletin board systems as an alternative form of markup language.

BBCode follows a tag structure that is often translated to HTML for rendering on a browser.

This could be an interesting addition to add even more versatility to this package

tneotia commented 3 years ago

This is an interesting suggestion. In practice this may seem easy to implement because it's pretty much the same syntax and structure as basic HTML. However we use an external library to help us parse the HTML into a readable tree, and it doesn't support BBCode at the moment. There is this library: https://pub.dev/packages/bbob_dart but we cannot use it because it does not have nullsafety support (and probably won't since it hasn't been updated in quite some time).

Maybe something very basic could be possible? I don't want to implement a buggy feature though... Parsing these tree structures is very, very error prone.

Side note: If your BBCode is very simple why don't you load the string and replace the [ and ] with < and >? Again, that would only really work for the simple stuff like bold, italic, underline, etc. We could also try and use that approach to feed it into our HTML parser and then detect BBCode specific elements like link or image, and convert those to actual HTML elements.

erickok commented 2 years ago

There's also https://pub.dev/packages/flutter_bbcode which support bbcode and its specific tags already. I'd prefer not to include this feature.

Sub6Resources commented 2 years ago

Yeah, this is definitely outside the scope of this project, sorry.

As a workaround you could convert the BBCode string into HTML as @tneotia mentioned, which shouldn't be terribly difficult.