top | item 39608991

(no title)

yuchi | 2 years ago

In the era of DOM documents (see notion, gitbook) I very often resort to attributed strings to do magic stuff with text parsing and manipulation. It’s such an elegant structure and I don’t understand why is so unknown.

Incredible article btw

discuss

order

LikeAnElephant|2 years ago

Do you have an example? I’d love to learn more!

yuchi|2 years ago

Let’s say you have a rich text where you want to highlight all occurrences of some token or syntax. When you have tree data structures you cannot use regexps or a simple parsers, since the full text may be split in different nodes.

With attributes strings it’s trivial, you just need to move attributes accordingly and to normalize stuff at the end.

Ezhik|2 years ago

I wonder if there are any web rich text editor components that use attributed strings? Tired of the DOM.