Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleaning up HTML formatted content for display within Flash?

I want to display HTML formatted content from various sources inside a Flash Flex application. Flash supports HTML formatting in its text fields, however it is very limited compared to a web browser. Are there any scripts out there that will convert common HTML formatted text into a format that Flash can handle? My particular use cases are:

  • Displaying HTML formatted emails inside Flash
  • Displaying RTF files inside Flash (after running an RTF2HTML conversion on the server)
  • Displaying random HTML content copied and pasted from other sources into Flash

I'm open to code that runs either on the client or the server, but server is probably preferable.

like image 596
davr Avatar asked Feb 20 '12 23:02

davr


3 Answers

The subset of html tags supported is quite poor and has not changed in forever:

<a>, <b>, <br>, <font>, <img>, <i>, <li>, <p>, <textformat>, <u>

This means is that regardless of conversion quality, html cannot be rendered as fully intended; you could also be giving up a significant portion of css styling if you replace unsupported tags with more basic ones.

That being said, http://simplehtmldom.sourceforge.net/ (PHP) would work with some tweaks and it's competent enough to cope with invalid markup as well (seeing how you're after processing content from various sources, I'd say this feature alone would save a lot of pain in the long run) - than replace

<h1>,...,<h6> => <b>
<strong>      => <b>
<em>          => <i>

and plaintext the rest of it into paragraphs you'd be surprised at how readable it would still be. You could be a bit fancy too like so:

<h1> => <b class="header1">

and add some css as appropriate (although flash css support is pretty limited too)

I've been saving this one for desert - you'll either love it or hate it but it would do the trick. Assuming your app is deployed in-browser (if not and I misread you, save me the embarrassment and stop reading right here) you could use an iframe to display your html, seriously.

JS<->AS communication is fairly straightforward and you could have it positioned over a predetermined area of your app, giving the illusion that it's part of it; just remember to set windowmode on the flash object/embed correctly so it does not render on top of other page elements, then increase the iframe z-index.

I would not be surprised if this is seen as an "ugly" approach, but it's beautiful on the inside - you'll end up with verbatim html and real css support. As for user interactions, you could even intercept link clicks etc. in the iframe and request an action from the movieclip.

like image 162
Oleg Avatar answered Oct 19 '22 22:10

Oleg


You can use HTMLPurifier and specify a whitelist of tags that you want to support.

like image 45
Dragos Avatar answered Oct 19 '22 23:10

Dragos


AS3 HTML Parser Library is not quite what I'm looking for, since it does not convert the HTML but instead renders it within Flash, meaning that it wont be editable. But it may be useful in some cases that I only want to display and not edit text.

Another option is to look at several sample HTML that I'd like to be able to display, and then write regex to convert them to the format Flash/TLF expects. But I feel like that may be a huge endeavor, due to the wide range of HTML out there.

like image 35
davr Avatar answered Oct 19 '22 23:10

davr