CFLib.org – Common Function Library Project

FlashHtmlFormat(text)

Last updated September 15, 2003

author

William Steiner

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Flash doesn't support all html tags, and is very strict on the format of the tags it does support. This function to attempts to convert the string into "Flash Safe" HTML code. Including simulation of <ol> and <li> tags.

Return Values:
Returns a string.

Example:

<cfsavecontent variable="text">
This some <b>html</b> text. It's <i>very</i> interesting.
<p>
<ol>
<li>List items...
<li>More list items.
</ol>
<p>
<table>
<tr>
<td>foo</td>
</tr>
</table>
</cfsavecontent>

<cfoutput>
&DisplayText=#FlashHtmlFormat(text)#&
</cfoutput>

Parameters:

Name Description Required
text Text to be converted. Yes

Full UDF Source:

/**
 * Converts a string into &quot;Flash&quot; safe HTML.
 * 
 * @param text 	 Text to be converted. (Required)
 * @return Returns a string. 
 * @author William Steiner (williams@hkusa.com) 
 * @version 1, September 15, 2003 
 */
function FlashHTMLFormat(someText) {
	var returnText = someText;
	var listCount = 0;
	returnText = ReplaceNoCase(returnText, "#Chr(10)#", "", "ALL");
	returnText = ReplaceNoCase(returnText, "<OL></OL>", "", "ALL");
	returnText = StripCR(returnText);

	while (FindNoCase('<OL>', returnText) neq 0) {
		while ((FindNoCase('</OL>', returnText) gt FindNoCase('<li>', returnText)) AND (FindNoCase('<li>', returnText) neq 0)) {
			startSearchAt = FindNoCase('<OL>', returnText);
			listCount = listCount + 1;
			// replaces the next <li> with the correct number.
			if (listCount gt 9)
				returnText = ReplaceNoCase(returnText, "<li>", "<BR>  #listCount#.  ");
			else
				returnText = ReplaceNoCase(returnText, "<li>", "<BR>    #listCount#.  ");
		}
		// we are done with that list, get rid of the <ol> tag so we can find the next 
		listCount = 0;
		returnText = ReplaceNoCase(returnText, "<OL>", "<br>", "one"); 
		returnText = ReplaceNoCase(returnText, "</OL>", "<br><br>", "one"); 
	}
	
	returnText = ReplaceNoCase(returnText, "<LI>", "<br>", "ALL"); 
	// Step xx, get rid of ALL </li>, </ol>, and </ul> tags
	returnText = ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(returnText, "</li>", "", "ALL"), "</ol>", "<br><br>", "ALL"), "</ul>", "<br><br>", "ALL");
	// Step xx, REReplace statement changes the color attribute of the font tag to have
	// quotes around it...ActiveEdit strips them out :(
	returnText = REReplaceNoCase(returnText, "<FONT color=(#Chr(35)#[A-Za-z0-9]*)></FONT>", "", "ALL");
	returnText = REReplaceNoCase(returnText, "target=([A-Za-z0-9_]*)", "target=#Chr(34)#\1#Chr(34)#", "ALL");
	returnText = REReplaceNoCase(returnText, "face=([A-Za-z0-9_ ]*)", "face=#Chr(34)#\1#Chr(34)#", "ALL");
	returnText = REReplaceNoCase(returnText, "color=(#Chr(35)#[A-Za-z0-9]*)", "color=#Chr(34)#\1#Chr(34)#", "ALL");
	returnText = REReplaceNoCase(returnText, "size=([A-Za-z0-9]*)", "size=#Chr(34)#\1#Chr(34)#", "ALL");
	returnText = ReplaceNoCase(returnText, "&nbsp;", " ", "ALL");
	returnText = ReplaceNoCase(returnText, "&##39;", "'", "ALL");
	returnText = ReplaceNoCase(returnText, "'", "'", "ALL");
	returnText = ReplaceNoCase(returnText, "'", "'", "ALL");
	returnText = ReplaceNoCase(returnText, """", "#Chr(34)#", "ALL");
	returnText = ReplaceNoCase(returnText, """", "#Chr(34)#", "ALL");
	returnText = ReplaceNoCase(returnText, "<EM>", "<I>", "ALL");
	returnText = ReplaceNoCase(returnText, "</EM>", "</I>", "ALL");
	returnText = ReplaceNoCase(returnText, "<STRONG>", "<B>", "ALL");
	returnText = ReplaceNoCase(returnText, "</STRONG>", "</B>", "ALL");
	return returnText;
}
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