Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.
Today I came across a small but annoying difference between the way Adobe CF and Railo implement the HTMLCodeFormat() function that I want to share.
A few days ago I turned on whitespace management on my Railo server and noticed that the code blocks in my blog entries were losing all their indenting. I checked the database and all the carraige returns and tabs were still in their so I am fairly confident that the whitespace management was to blame. Now I could have simply turned it back off but I didnt really want to so I decided to try code around the problem.
Solution On Railo
So after a little research I came up with the simple code block to convert carraige returns and tabs to html. I tested and deployed it all on Railo and life was good.
Adobe CF Is Different
So today I come along and decide to do some cross platform testing on my site. I load up my local copy in railo and everything looks fine, but when I load it in Adobe CF all my code blocks are missing their indenting and carraige returns.
Needless to say this had me scratching my head for a while until I noticed a small difference between the Adobe livedocs and the Railo wiki for the HTMLCodeFormat() function. Note the following highlighted difference in the function documentation.
Replaces special characters in a string with their HTML-escaped equivalents and inserts <pre> and </pre> tags at the beginning and end of the string.
HTML-escaped string string, enclosed in <pre> and </pre> tags. Return characters are removed; line feed characters are preserved. Characters with special meanings in HTML are converted to HTML character entities such as >.
Now I really didn't need to do anything to fix this as it is unlikely I will every run my blog on Adobe CF, but just on the off chance I decided I might as well fix it while I know what the issue is.
As you can see my solution was to replace all the carriage returns with a place holder string which I knew would be unique before escaping my code. Then once I had escaped my code I could safely convert the place holder to actual html <br/> tags.
Now there might be a more elegant solution than this (I'd love to hear about it), but for now this code works consistently on Railo and Adobe CF and gives me my desired output.