views:

153

answers:

3

I tried the solutions that are posted in this related SO question and for the most part the code snippets are working, but there are some cases that are still getting garbled by Blogger when it publishes the blog.

In particular, declaring generic containers seems to be most troublesome. Please see the code examples on my blog: http://mlai-lirik.blogspot.com/, specifically the section where I declare the dictionary.

I want to display this:

static Dictionary<int, List<Delegate>> _delegate = new Dictionary<int,List<Delegate>>();

But blogger publishes this:

static Dictionary<int, list=""><delegate>> _delegate = new Dictionary<int, list=""><delegate>>();

And it caps the end of my code section with this:

</delegate></delegate></int,></delegate></int,>

Apparently blogger thinks that the <int and <delegate> portion of the dictionary are some sort of HTML tags and it automatically attempts to close them at the end of the code snippet. Does anybody know how to get around this problem?

Update:
I used CraftyFella's solution http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html and it causes the above-mentioned issues to occur (i.e. his solution does not work for the code snippets I posted).

I also tried wrapping my code snippets with the <code></code> tags, but that didn't work either. The results were similarly disappointing: Dictionary<int, List<string>> test = new Dictionary<int, List<string>>(); turns into Dictionary> test = new Dictionary>();

+2  A: 

I replaced all of the < with &lt; and got this. (Same trick I use on SO, actually.)

banzaimonkey
Yup, blogger kind of sucks...it's amazing they don't replace `<` and `>` automatically. I always use the HTML editor because I got tired of their normal frontend screwing everything up.
Travis Gockel
+1 that solved it!
Lirik
+1  A: 

What you have to do is HTML encode your program. First replace all & with &amp;, then replace all < with &lt; and > with &gt;. Although the very last one isn't strictly required to get it to work, I think it's better for correctness.

Gabe
+1  A: 

This will be helpful for the beginners to show how to format source code for blog posts http://codeshode.blogspot.com/2010/06/format-my-source-code-for-blogging.html

tjaank