Hacker News new | ask | show | jobs
by yuchi 837 days 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

3 comments

Do you have an example? I’d love to learn more!
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.

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