britzl / defold-richtext

Defold-RichText is a system to create styled text based on an HTML inspired markup language
MIT License
75 stars 12 forks source link

Add support for overlapping/out of order tags. #42

Closed rgrams closed 5 years ago

rgrams commented 5 years ago

Allow RichText to handle text like this:

<color=red><b>some text</color></b>

...where the tags are not closed in the same order that they are opened.

Or they could actually overlap, like this: "<i>this is italic <b>bold italic : </i>bold regular</b> back to normal."

this is italic bold italic : bold regular back to normal.

I guess the parser would have to store the current styling state with the order of opened tags, so it could handle any tag that came next, rather than only searching for consecutive open-close pairs.


Feel free to close as "won't add".

rgrams commented 5 years ago

OK, I've reworked the parser in a local copy to make it work with tags in any order (this also removes the caveat about nested tags of the same name). I'll try to clean it up and probably make a PR in the next couple of days.

Screenshot 2019-09-03 02 25 09

It is a little bit more involved, having to save a history of the old values that each current tag modified. I'll try to do some performance tests to see how it is. I do think it would be a good improvement for Defold-RichText though. It's much more flexible and forgiving, and in some circumstances it could really cut down the total number of tags.

britzl commented 5 years ago

Also in PR #45

britzl commented 5 years ago

Fixed via PR #45