CFLib.org – Common Function Library Project

XHTMLParagraphFormat(string[, attributeString])

Last updated July 2, 2008

author

Jeff Howden

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns a string that starts with an opening paragraph tag, ends with a closing paragraph tag, has all CR/LF replaced with closing and then opening paragraph tags, and also accepts an optional argument that can be used to assign attributes to all opening paragraph tags inserted into the string.

Return Values:
Returns a string.

Example:

<cfsavecontent variable="myVar">The nice thing about this function is that it will allow you to pass a string representing additional attributes to apply each opening paragraph tag applied to the string.
Additionally, unlike the built-in ParagraphFormat() function, the string returned by the function begins with an opening paragraph tag (&lt;p&gt;) and ends with a closing paragraph tag (&lt;/p&gt;).  It also inserts a closing paragraph tag (&lt;/p&gt;) before starting the next paragraph.
Finally, for those of you who like to have your applications generate nicely formatted HTML, this tag breaks each paragraph on to a separate line.</cfsavecontent>

<cfoutput>#XHTMLParagraphFormat(myVar, "style=""font-family: tahoma; font-size: 12px; color: ##000099""")#</cfoutput>

Parameters:

Name Description Required
string String you want XHTML formatted. Yes
attributeString Optional attributes to assign to all opening paragraph tags (i.e. style=""font-family: tahoma""). No

Full UDF Source:

/**
 * Returns a XHTML compliant string wrapped with properly formatted paragraph tags.
 * 
 * @param string 	 String you want XHTML formatted. (Required)
 * @param attributeString 	 Optional attributes to assign to all opening paragraph tags (i.e. style=""font-family: tahoma""). (Optional)
 * @return Returns a string. 
 * @author Jeff Howden (cflib@jeffhowden.com) 
 * @version 1, July 2, 2008 
 */
function XHTMLParagraphFormat(string)
{
  var attributeString = '';
  var returnValue = '';
  if(ArrayLen(arguments) GTE 2) attributeString = ' ' & arguments[2];
  if(Len(Trim(string)))
    returnValue = '<p' & attributeString & '>' & Replace(string, Chr(13) & Chr(10), '</p>' & Chr(13) & Chr(10) & '<p' & attributeString & '>', 'ALL') & '</p>';
  return returnValue;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson