En
aqui dan una solución usando expresiones regulares, la función vendría a ser:
Código :
private function cleanHTML(str:String):String
{
var pattern:RegExp = /<TEXTFORMAT.*?>/g;
var str:String = str.replace(pattern, "");
pattern = /<FONT.*?>/g;
str = str.replace(pattern, "");
pattern = /<\/FONT.*?>/g;
str = str.replace(pattern, "");
pattern = /<A HREF/g;
str = str.replace(pattern, "<a href");
pattern = /<\/A>/g;
str = str.replace(pattern, "</a>");
pattern= /TARGET="_blank"/g;
str = str.replace(pattern, "rel=\"external\" ");
pattern = /<I>/g;
str = str.replace(pattern, "<em>");
pattern = /<\/I>/g;
str = str.replace(pattern, "</em>");
pattern = /<B>/g;
str = str.replace(pattern, "<strong>");
pattern = /<\/B>/g;
str = str.replace(pattern, "</strong>");
pattern = /<U>/g;
str = str.replace(pattern, "<u>");
pattern = /<\/U>/g;
str = str.replace(pattern, "</u>");
pattern= /<\/LI><LI>/g;
str = str.replace(pattern, "</li><li>");
pattern= /<\/LI>/g;
str = str.replace(pattern, "</li></ul>");
pattern= /<LI>/g;
str = str.replace(pattern, "<ul><li>");
pattern = /<P ALIGN="LEFT">/g;
str = str.replace(pattern, "<p style=\"text-align:left\" >");
pattern = /<P ALIGN="RIGHT">/g;
str = str.replace(pattern, "<p style=\"text-align:right\" >");
pattern = /<P ALIGN="JUSTIFY">/g;
str = str.replace(pattern, "<p style=\"text-align:justify\" >");
pattern = /<\/P>/g;
str = str.replace(pattern, "</p>");
pattern = /<\/TEXTFORMAT.*?>/g;
str = str.replace(pattern, "");
pattern= /<\/ul><ul>/g;
str = str.replace(pattern, "");
return str;
}
Esta función te genera un html limpio a partir del html del RichTextEditor.