Wednesday, August 31, 2005 Custom ColdFusion Functions

Just a collection of ColdFusion functions I've created based on need that I thought I would share.

XHTMLParagraphFormat()

The ColdFusion function ParagraphFormat() is designed to take blocks of text and format them as HTML, converting carriage returns and line breaks into code. This is very useful for taking information in a database and displaying it dynamically in a page. The way the function works, however, creates invalid XHTML, and not clean HTML either. What it does is take every combination of carriage return and line feed and convert it to a single <P> tag.

Good HTML has an opening <P> tag and a closing </P> tag. Valid XHTML requires both, and that they be in lowercase. This function provides that funcationality, and is used in the same manner as the standard ParagraphFormat() function.

XHTMLParagraphFormat
<cffunction name="XHTMLParagraphFormat" returntype="string" output="false">
   <cfargument name="strTextBlock" required="true" type="string" />
   <cfreturn REReplace("<p>" & strTextBlock & "</p>", "\r+\n\r+\n", "</p><p>", "ALL") />
</cffunction>