Skip to main content
Participant
January 19, 2011
Question

TextConverter.importToFLow() and span style class

  • January 19, 2011
  • 1 reply
  • 1365 views

I'm trying to create a TextFlow object from generic HTML Text. There seems to be a problem with converting the span style class when having some tags inside the span:

Here's a code snippet to narrow the issue down:

            var htmlText:String = '<SPAN CLASS="myclass"><b>foo</b>bar</SPAN>';

            var textFlow:TextFlow = TextConverter.importToFlow(htmlText, TextConverter.TEXT_FIELD_HTML_FORMAT);
           
            trace(TextConverter.export(textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.XML_TYPE));

The output is:
<p>
     <span fontWeight="bold">foo</span>
     <span styleName="myclass">bar</span>
</p>


As you can see, the foo span doesn't have a myclass style after conversion to text layout format.
I think this problem is related to the fact, that the TEXT_FIELD_HTML_FORMAT doesn't allow nested tags, and the <b>foo</b> being converted to a span too...

Any idea how to solve this?

This topic has been closed for replies.

1 reply

Adobe Employee
January 19, 2011

This is a limitation of TLF 1.0. There is a fix for this, though, if you are willing to upgrade  In TLF 2.0, spans still don't nest, but there's a new <g> element that is used to group spans together.

When I import your html string into TLF 2.0, I get this result:

<TextFlow whiteSpaceCollapse="preserve" version="3.0.0" xmlns="http://ns.adobe.com/textLayout/2008">

  <p>

    <g styleName="myclass" typeName="span">

      <span fontWeight="bold">foo</span>

      <span>bar</span>

    </g>

  </p>

</TextFlow>

If I then take this flow and export it back to HTML, I get this:

<HTML><BODY><P ALIGN="left"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="1"><span class="myclass"><B>foo</B>bar</span></FONT></P></BODY></HTML>

TLF 2.0 is available on it own, and as part of Flex Hero. Both of these are still pre-release.
- robin