Color Coding in BlogCFC with ColdFish

February 27, 2008 8:07 PM
Related Categories: Web Dev

Jason Delmore created ColdFish to color code any file content or string.  Its wickidly easy to implement.

To add it to your blog you simply need to modify a couple files.

1) Application.cfm - this is optional, but a good idea I think.  Just after the cfset for application.blog add:

<cfset application.coldfish = createObject("component","org.delmore.coldfish").init()/>

2) in Blog.cfc (typically org/camden/blog/blog.cfc) line 2085 ish:

<cfset result = "<div class=""#style#"">" & application.coldfish.formatString(codeportion) &  "</div>"/>

For item 2 I had to add a bit more as I use FCK editor and as such the html was changed a bit when saved to the DB.  I also dont't use <code></code> but rather directly applied a class to my html with <div class="code"></div> instead.  So I needed to reformat my content a bit for coldFish to format.

So I added:

<!--- line 2072 ish to replace the divs with code tags  --->
<cfset arguments.string =  replacenocase(arguments.string, '<div class="code">','<code>', 'ALL')>   
<cfset arguments.string =  replacenocase(arguments.string, '</div>','</code>', 'ALL')>   
<!--- line 2085ish just above my item 2 above to set the html as coldFish wants it and remove formating breaks --->
<cfset codeportion= replace(codeportion, '<br />', '', 'all')>
<cfset codeportion= replace(codeportion, '<p>', '', 'all')>
<cfset codeportion= replace(codeportion, '</p>', '', 'all')>
<cfset codeportion= replace(codeportion, '<', '<', 'all')>
<cfset codeportion= replace(codeportion, '>', '>', 'all')>

<cfset codeportion= replace(codeportion, '&', '&', 'all')>
<cfset codeportion= replace(codeportion, '"', '"', 'all')>


Like this entry? Subscribe to my blog.

Comments (moderation on)

Note: Coldfish requires CF 8 ....
# Posted By jax | 3/6/08 5:32 AM

Sponsors


Savvy Content Manager