Adding font tags to htmlText

I am after some example code (in any language) or help from someone that has attempted the following:

I am trying to write a class in AS3 that displays text in a TextField and then allows users to edit the text in an almost idential fashion to the way text can be edited in these forums, by most word processors etc. That is to say by highlighting a section and clicking the corresponding button text can be underlined, bolded, colour changed etc.

In actuality I keep a separate string that gets edited allowing me to avoid much of flash’s idiosyncrasies and save it to XML when finished.

If anyone has done this in AS3 I’d love to get a look at the code or even just a general idea of how they went about it.

Whilst I have the basic structure working well, trying to cope with users adding tags that span tags in complex text is causing me to have to write a massive amount of checks and balances.

Thanks for your consideration,

S