My Pre tags disappeared from DotNetNuke (DNN)

* Update, I have moved my blog to Orchard running on Azure after several years on Blogger.com*

Since this is a “Technical” blog I expect to be showing a lot of code. One of the best ways I have seen is done by Scott Hanselman. He uses Pre tags and the Code Syntax Highlighter java library to add CSS styles to the words. He then uses CSS sheets to add color. It even adds the line numbering on the side. I stole the code (As far as I can see it’s free) and put it on my DotNetNuke (DNN) site I am using for the blog. It looked fantastic… wait, what looks wrong… It’s missing the indentions… and the extra line spaces.

I had to dig a little deeper. I edited the post and sure enough in the source view of the FCK editor there were no indentions or spaces. I put them back in and posted it and they disappeared again. I edited the post again and toggled between source and standard view on the FCK editor and the spaces and indentions disappeared each time.

Since it’s better to search for someone else’s solution than to debug on your own I searched and found this bug report for the FCK editor. They had a newer version so I put it in my site (after making a copy of the existing code). Voila, now when I toggle between source and standard views the formatting stays. So cool. Now I post it back and … what the???

They’re gone. I double checked and the FCK editor is working. I pulled up fiddler and sure enough the page was sending the data with the spaces to the server but they weren’t coming back down. Just to see if it was a blog module thing or a wider concern I tried it in the Text/HTML module and the results were the same. I even checked the database and sure enough the spaces were there so somewhere on the way to the client they were getting stripped.

Most likely DNN has some code to validate input and it is editing it out. This was probably a security concern going a bit too far. I could get the source code for DNN and walk through and find out what HTML editing they are doing on inputs. I thought I would post this blog first then maybe the DNN guys could use this for the investigation.

I had more trouble with the Pre tag while writing the blog. Whenever I post pre tag with the <> around it the returning code looks fine on the screen but when I edit the post things get moved around. I took a look at fiddler again and it looks like the text being sent down to the FCK editor is UTF8 encoded but anywhere I put in text that had to be encoded is not escaped. It looks like FCK editor is having to interpret the encoded data without enough information to determine what was originally encode and what was not.

Boy what a mess. I tried several things. I finally settled on a work around where I put the HTML markup in for the indentions and the extra lines into the pre tags and it seems to survive all the manipulations and even goes through multiple edits. It’s a pain to do it by hand. Now I have to make a decision about automating the work around or digging deeper to fix the root cause. The right thing for the community would be to fix the root cause. What would you do next?