3 Replies Latest reply on Oct 21, 2008 11:24 AM by dragonmagik

    htmlText removing all line breaks

    dragonmagik
      In my program, a user can input any type of text using a RichTextEditor. The entered text has all its illegal xml characters replaced ( < with &lt;) etc. Then that string is put into an xml document. A custom component then recieves the xml document, converts the html back into its original form and applies it as the htmlText property of a text control. This used to work fine. I need string converstions because there are certain 'metaStrings' that get replaced based on certain criteria ... i.e. the string {$DATE} would get replaced by the actual date upon loading at a later time. As I said, this used to work, and I had no problem displaying text exactly as the user created it. Now, for some reason, when I set the htmlText property, ALL line breaks are removed, of any type. </br> <p> </p> <li> </li> for bullets. Formating remians, increased font size, colors, etc, but there are no line breaks.

      I have my loading snipped of code and its subsequent output:

      public static function loadHtmlText(textControl:Text, textData:XML, replaceMeta:Boolean = false):void
      {
      trace('loading html text into a text component, loading',textData);
      var html:String = textData.Html.toString();
      trace('after parsing to a string',html);
      if(replaceMeta)
      {
      trace('replacing');
      html = html.replace(/\{\$DATE\}/,textData.Date);
      //add any additional meta sequences here for replacement
      }
      trace('after replacing',html);
      textControl.htmlText = html;


      textControl.validateNow(); //force a validation
      trace('value that was set',textControl.htmlText);
      }

      and the subsequent output:

      loading html text into a text component, loading
      <Data>
      <Html>&lt;TEXTFORMAT LEADING="2"&gt;&lt;P ALIGN="LEFT"&gt;&lt;FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0"&gt;Line 1&lt;/FONT&gt;&lt;/P&gt;&lt;/TEXTFORMAT&gt;&lt;TEXTFORMAT LEADING="2"&gt;&lt;P ALIGN="LEFT"&gt;&lt;FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0"&gt;Line 2&lt;/FONT&gt;&lt;/P&gt;&lt;/TEXTFORMAT&gt;&lt;TEXTFORMAT LEADING="2"&gt;&lt;P ALIGN="LEFT"&gt;&lt;FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0"&gt;Line 3&lt;/FONT&gt;&lt;/P&gt;&lt;/TEXTFORMAT&gt;</Html>
      <Date>NotSet</Date>
      </Data>

      after parsing to a string
      <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 1</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 2</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 3</FONT></P></TEXTFORMAT>

      after replacing
      <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 1</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 2</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 3</FONT></P></TEXTFORMAT>
      value that was set <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line 1Line 2Line 3</FONT></P></TEXTFORMAT>



      um, oops, all the strings wordwrapped, makes it impossible to read. there were three <P> </P> blocks passed in
      each one said Line 1 Line 2 and Line 3 respectively, and each one should be on its own line.

      After forcing validation of the text control after setting this string, there is only one <P></P> tag with all the text in it ... Line 1Line 2Line 3.


      Any ideas?

      this was working before, all I did was move the text setting into its own function, insead of a function called by the set method of my custom component's data provider.

      Thanks for the help.
        • 1. Re: htmlText removing all line breaks
          fedecarra
          I'm having the same problem. I work with open source sdk (use mxmlc compiler instead of flex builder ide). I've noticed that the problem only occurs when I use a non-system font (for example a ttf font declared with font-face in css). if I use system fonts, all line breaks are rendered correctly.
          hope someone will solve this bug.
          • 2. Re: htmlText removing all line breaks
            Level 7

            "dragonmagik" <webforumsuser@macromedia.com> wrote in message
            news:g5qv24$ekr$1@forums.macromedia.com...
            > In my program, a user can input any type of text using a RichTextEditor.
            > The
            > entered text has all its illegal xml characters replaced ( < with <) etc.
            > Then
            > that string is put into an xml document. A custom component then recieves
            > the
            > xml document, converts the html back into its original form and applies it
            > as
            > the htmlText property of a text control. This used to work fine. I need
            > string converstions because there are certain 'metaStrings' that get
            > replaced
            > based on certain criteria ... i.e. the string {$DATE} would get replaced
            > by the
            > actual date upon loading at a later time. As I said, this used to work,
            > and I
            > had no problem displaying text exactly as the user created it. Now, for
            > some
            > reason, when I set the htmlText property, ALL line breaks are removed, of
            > any
            > type. </br> <p> </p>
            • </li> for bullets. Formating remians,
              > increased
              > font size, colors, etc, but there are no line breaks.
              >
              > I have my loading snipped of code and its subsequent output:
              >
              > public static function loadHtmlText(textControl:Text, textData:XML,
              > replaceMeta:Boolean = false):void
              > {
              > trace('loading html text into a text component, loading',textData);
              > var html:String = textData.Html.toString();
              > trace('after parsing to a string',html);
              > if(replaceMeta)
              > {
              > trace('replacing');
              > html = html.replace(/\{\$DATE\}/,textData.Date);
              > //add any additional meta sequences here for replacement
              > }
              > trace('after replacing',html);
              > textControl.htmlText = html;
              >
              >
              > textControl.validateNow(); //force a
              > validation
              > trace('value that was set',textControl.htmlText);
              > }
              >
              > and the subsequent output:
              >
              > loading html text into a text component, loading
              > <Data>
              > <Html><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont"
              > SIZE="10" COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line
              > 1</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 2</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 3</FONT></P></TEXTFORMAT></Html>
              > <Date>NotSet</Date>
              > </Data>
              >
              > after parsing to a string
              > <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10"
              > COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line
              > 1</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 2</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 3</FONT></P></TEXTFORMAT>
              >
              > after replacing
              > <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="listFont" SIZE="10"
              > COLOR="#0B333C" LETTERSPACING="0" KERNING="0">Line
              > 1</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 2</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 3</FONT></P></TEXTFORMAT>
              > value that was set <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT
              > FACE="listFont" SIZE="10" COLOR="#0B333C" LETTERSPACING="0"
              > KERNING="0">Line
              > 1Line 2Line 3</FONT></P></TEXTFORMAT>
              >
              >
              >
              > um, oops, all the strings wordwrapped, makes it impossible to read. there
              > were three <P> </P> blocks passed in
              > each one said Line 1 Line 2 and Line 3 respectively, and each one should
              > be on
              > its own line.
              >
              > After forcing validation of the text control after setting this string,
              > there
              > is only one <P></P> tag with all the text in it ... Line 1Line 2Line 3.
              >
              >
              > Any ideas?
              >
              > this was working before, all I did was move the text setting into its own
              > function, insead of a function called by the set method of my custom
              > component's data provider.

              Did you change the prettyPrinting property of the XML class?


            • 3. Re: htmlText removing all line breaks
              dragonmagik Level 1
              Wow, almost three months later, when my work schedule actually lets me reapproach this problem, and I get the solution :-). It turns out, I am not sure why, or if even Adobe knows about the bug, but if you are applying fonts using stylesheets to all your application controls, i.e. I have an Application style declaration where I set the font, then redering html text in the Text control is buggy, usually jsut removing all the line breaks. Why, I have no idea, it just does. However, the same bug does not occur in the TextArea component. Again, I don't know why, seems ridiculous to me, but as the solution to this problem, simply create a TextArea component, set styles backgroundAlpha to 0, its borderStyle to 'none', set the editable property to false, and boom, you have a scrolling Text component, that doesn't render html text incorrectly.