Extending the mx.core.RichTextEditor to give it and xhtmlText property using regular expressions. That sentence is pretty self explanatory.

Application Source

I’ve written on the the mx.controls.RichTextEditor before in flex… and there are some issues with the HTML that it outputs. That post states that the htmlText the the RichTextEditor pretty much blows as far as including it on a real html page…

There are many other solutions to this issue, there are some friends that have even written on it…

I had a few suggestions with the google code solution, simply because it wasn’t XHTML compliant, and it wasn’t really packaged as a component you could reuse. It was packages as pretty much an example mxml file with a function inside of it that did your regex to change the code… Which gave me a great start, I’m actually going to try to get on that google code site, and try to get on as a project contributor to give them the new component, or at least see what they think. Most solutions you read online including my post about the font being to large state that you can simply write a regular expression to change your text… I didn’t like how in my post the only thing i listed was how to call it by clicking a button and not doing it on a change event of some sort. So that was definitely one of the goals with this post. Another thing that annoyed me with the rich text editor was when i tried to manipulate the htmlText property of the RichTextEditor it simply wouldn’t take my values, or it would re-commit it’s values after mine had ran, even looking that source of the RichTextEditor, and overriding it, and overriding commitProperties, it still didn’t quite work out… so simply out of frustration, i decided… well.. what the heck… why would you want to override the htmlText… what if by chance… (this someone could be crazy) someone is actually using it… then you wouldnt want to take it away from them, right? Of course not… so on that post from thanksmister.com there are SOOOO many comments, and some of them have reverse engineered the regular expressions to change the htmlText back to what it was, and so I started thinking, why not just have a separate variable? The whole point of what we’re doing is to make the htmlText from the TextEditor actually XHTML compliant or either make it actually show something somewhat close to what it visually shows the user in flash, in the browser… meaning when you use htmlText output from flex, and you put it in an html page in a browser, it looks like shit if you adjust the font, color, size position or anything else, because of the way it formats it’s htmlText.

My solution was to create a variable called xhtmlText, so now you can use myRichTextEditor.htmlText or myRichTextEditor.xhtmlText… granted I think your supposed to get rid of whitespace in true valid xhtml text (i didn’t look up any specs… I read some coding standards on it, a while back (like 2 years ago) and I integrated all the things I could remember, all tags must have an ending tag, and they must be LOWERCASE (something absolutely annoys me when i see people mixing there tag case, say from HOMESITE!), and in a href tags, target=”_blank” is deprecated, and your now supposed to use rel=”external”. so thats the just of what I did in the regular expressions…

Application Source

Please feel free to check out the application, and view the source.