vstojkovic / bugle

Butt-Ugly Game Launcher for Exiles
Apache License 2.0
6 stars 1 forks source link

BBScope badness #1

Closed randomouscrap98 closed 1 year ago

randomouscrap98 commented 1 year ago

Hey, I hope you don't mind me bothering you with this. I noticed that you had to jump through a lot of hoops to get the BBScope bbcode parser to work for you; namely that you had to insert "img" into the only list to get images to work inside links (oof I'm sorry you had to do that) at https://github.com/vstojkovic/bugle/blob/3e9966d992616756c3ff991ad089178c375b0d33/src/gui/mod_manager.rs#L670-L687 and then needing to replace newlines with \<br> at https://github.com/vstojkovic/bugle/blob/3e9966d992616756c3ff991ad089178c375b0d33/src/gui/mod_manager.rs#L642

I'm sorry you had so many issues; I didn't expect anyone to use this. I made an update which should make all this much easier, and fix a couple issues. First, since you're using the extended tagset, tags that render to <pre> (like [code]) will break if you replace all newlines with <br>. Second, if the bbcode you're parsing accidentally doesn't provide a url when embedding an image, such as [url][img=whatever][/url], it will generate incorrect HTML (or so it seems). Both of these are my fault of course.

I believe both of these are fixed in 0.2.0, so if you're willing, you could update bbscope to 0.2.0 in Cargo.toml then change your BBCode initialization to just:

//Images are allowed inside url scope by default now and handle the situation when no url is provided (it's not pretty but it's 
//not invalid html at least). Furthermore, the default is to emit <br> where appropriate (so not within pre, img, etc)
static ref BBCODE: BBCode = BBCode::from_config(BBCodeTagConfig::extended(), None).unwrap();

So you don't have to loop over stuff or merge separate matchers, etc. There's some other configuration stuff inside the BBCodeTagConfig if you need, and I can add more as needed.

Then, you can remove the newline replacement mentioned above, as newlines are now conditionally replaced with <br> when in the correct scope.

Anyway, I hope that wasn't bothersome, feel free to ignore :^). Just figured I'd mention since it sucks having to make hacks for libraries (and I don't want you to be surprised by incorrect html generation).

vstojkovic commented 1 year ago

Whoa, that's awesome! Thank you so much, I'll grab the new version and simplify my code. 🙂

vstojkovic commented 1 year ago

Done! Thanks again.

randomouscrap98 commented 1 year ago

Awesome! If you have any issues, just let me know (or open an issue). Have fun with your project, it seems really cool!