How to get HTML text from inputed and edited text into Adobe Flex Builder RichTextEditor control? I mean with valid HTML coming from the Flex RichTextEditor component
Not Badly formated HTML, with no spaces, with tags not closed!
So we have 开发者_如何学JAVAsome text edited with RTE a-la alt text http://livedocs.adobe.com/flex/3/html/images/RTE1.png
We want to get its content as HTML. how to do such thing?
There's a really nice class called RteHtmlParser which can translate RTE generated "html" to html and back. I've been using it on a project and it works nice. You can see a live example and get source code here: http://blog.flashweb.org/archives/7
What version of the framework are you using? When I try to create a duplicate of your linked example using 3.2, I get well-formed HTML.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HBox width="100%" height="100%">
<mx:RichTextEditor id="rte" />
<mx:TextArea height="{rte.height}" width="{rte.width}" text="{rte.htmlText}" />
</mx:HBox>
</mx:Application>
My Flex 3.2 output looks like this, ugly but well-formed:
<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Verdana" SIZE="12" COLOR="#009900" LETTERSPACING="0" KERNING="1"><B>This is the way the world ends</B></FONT></P></TEXTFORMAT>
The same text in your example site gives the badly formed:
<P text-align:CENTER;><span style="font-family:Verdana; font-size:12px; color:#009900; "><strong>This is the way the world ends</strong></span>
(You might post the source for your example; you have "View source" enabled but it's not actually available.)
EDIT:
The external code you're using does the following, among other modifications:
pattern = /<\/P>/g;
str = str.replace(pattern, “”);
So that explains the missing </p>
tags.
I'm not sure what their use case was, but it appears different from what you want. If you want to clean up the default htmlText
returned by the RichTextEditor, you might consider revamping the blog code to suit your needs.
精彩评论