Making the Close Paragraph act
like a Close Paragraph in Flash

Recently, i’ve become infuriated with Flash and the way it treats HTML text, especially while working on projects that have needed to be put in to a Tridian system ( Anyone who does this, will understand my hatred for it. ). One of the things that got me annoyed for a whole day was the fact that when any XML was uploaded to Tridian it decided to completely collapse all of the white space within the file. So I did some digging around and thought how it’s acting the same way that ‘condenseWhite’ does in flash. Basically what was happens is that the

tag within any Node gets treated as:

<p>This is a paragraph</p>
<p>This is a new paragraph</p>

Where as it should be treated, or at least it is in HTML as:

<p>This is a paragraph</p>

<p>This is a new paragraph</p>

Obviously everyone will notice the space between the first and second, this is how HTML treats the

tags, it adds the extra carriage return in for you, I’m not sure why Flash doesn’t do this. If anyone knows, I would love to hear.

Anyway, this got my knickers in a twist and forced me to talk to one of the guys in the office who talks in regex (Regular Expressions ), honestly I think he orders coffee’s in regex as well.. it’s kind of scary, and I’m pretty sure he never gets what he asks for.

So this led me to get this:

private static function convertToHTML( value : String ) : String
{
	var regExp : RegExp = /<\/p>(?=.*<p)/gsi
	return value.replace( regExp , "<br /></p>" );
}

What this basically does is do a look forward for

<p

if it finds it it replaces the last

</p>

with

<br /></p>

so it puts in the extra space. Just a reminder for anyone looking to use this, I would recommend turning on ‘condenseWhite’, I’ve started to use it in all of my projects, the reason for this is that I find it give’s me more manageable XML files, even for people to look at if they need to make changes.

I hope for anyone looking, this helps!!

Share and Enjoy:
  • Print
  • Twitter
  • del.icio.us
  • Facebook
  • LinkedIn
  • Digg
  • Sphinn
  • Mixx
  • Google Bookmarks
  • RSS