Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active December 8, 2023 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/fe93e4996165a4ee88ab3269bbd32535 to your computer and use it in GitHub Desktop.
Save JamoCA/fe93e4996165a4ee88ab3269bbd32535 to your computer and use it in GitHub Desktop.
QuoteFonts UDF to use regex to add missing single quotes to font names
<!--- 20231207180156
James Moberg / SunStar Media
This is a ColdFusion UDF that uses regex to adds missing single quotes to font names. (CKEditor doesn't consistently quote inline CSS values.)
Fixes HTML generated with this CKEditor4 shortcoming: https://ckeditor.com/old/forums/CKEditor-3.x/Ckeditor-external-fonts-problem
--->
<cfsavecontent variable="test">
style="font-family:'Times New Roman'; Times New Roman"
style="font-family:Times New Roman"
style="font-family:'Times New Roman'; "
style="font-family:Times New Roman; Gill Sans,Gill Sans Extrabold"
</cfsavecontent>
<cfscript>
string function qouteFonts(string html="", string fontNames="") output=false hint="I add missing single quotes to font names" {
local.fontNames = listtoarray(listappend("Times New Roman", arguments.fontNames));
arraysort(local.fontnames, "textnocase", "desc");
local.html = javacast("string", arguments.html);
for (local.fontName in local.fontNames){
local.html = local.html.replaceAll("([^'])(#trim(local.fontName)#)([^'])", "$1\'$2\'$3");
}
return local.html;
}
</cfscript>
<cfoutput>
<pre>#test#</pre>
<hr>
<pre>#qouteFonts(test, "Gill Sans,Gill Sans Extrabold")#</pre>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment