4 Replies Latest reply: Apr 9, 2012 11:16 AM by azeem878 RSS

    whiteSpaceCollapse not working on textFlow created from HTML

    Robert Reinhardt Community Member

      Is there a trick to getting whiteSpaceCollapse to work with imported HTML? Here's my current code, where value is HTML text (e.g. "<p>Blah</p>.."):

       

      textFlow = TextConverter.importToFlow( value, TextConverter.TEXT_FIELD_HTML_FORMAT);

       

       

       

       

       

      textFlow.whiteSpaceCollapse = WhiteSpaceCollapse.COLLAPSE;

       

      I've also set whiteSpaceCollapse on the RichEditableText to "collapse" but I'm still noticing vertical space differences if my external HTML has linebreaks between <p></p> nodes. Many thanks in advance for any suggestions.

       

      -Robert

        • 1. Re: whiteSpaceCollapse not working on textFlow created from HTML
          rdermer Adobe Employee

          WhiteSpaceCollapse is applied as part of the import.  After that changing it or modifying it has no effect.

           

          Richard

          • 2. Re: whiteSpaceCollapse not working on textFlow created from HTML
            aliman

            And so ? How do we set the TextConverter to avoid collapsing white spaces on import now ?

             

            I ve tried many ways but still no way to avoid a WEIRD behavior.
            If I set spaces and I want to collapse them, then I can do it with a simple search/replace, there are plenty

            of regex out there to do this.

            I don't need the framework to behave strangely right ? So why did the flex engineers spend time

            on putting together stuff that is totally weird ?
            Plus the TextConverter has a lot of tlf_internal methods, just to avoid us to overload its functionnalities...

            • 3. Re: whiteSpaceCollapse not working on textFlow created from HTML
              mjzhang

              Hi aliman,

              Did you set format string to TextConvertr.PLAIN_TEXT_FORMAT ? That will preserve your spaces I think. 

              var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.PLAIN_TEXT_FORMAT); 

               

              And for tlf_internal, i just find one tlf_internal function in TextConverter. Others are public.

              static tlf_internal function setFormatsToDefault():void

              • 4. Re: whiteSpaceCollapse not working on textFlow created from HTML
                azeem878 Community Member

                this is the way to solve this bug and no need for changing any xml settings , simple and it works

                 

                exporting the textflow:

                 

                var richTextXML:xml = new XML("<"+"richTextXML"+"/>");

                 

                richTextXML.appendChild(getCdataXMl());

                 

                private function getCdataXMl():xml{

                 

                  var textFlowStr:String = TextConverter.export(textFlow,TextConverter.TEXT_FIELD_HTML_FORMAT

                 

                , ConversionType.STRING_TYPE).toString();

                 

                var textFlowXMl:xml = new XMl("<![CDATA["+textFlowStr+"]]>");

                 

                return textFlowXMl;

                 

                }

                 

                importing TextFlow from XMl :

                 

                var htmlTextInStr:String = richTextXMl.text();

                 

                var importtedTextFlow:TextFlow = TextConverter.importToFlow(htmlTextInStr,TextConverter.TEXT_FIELD_HTML_FORMAT);

                 

                textArea.textFlow = importtedTextFlow;