开发者

Posting source code in blogger- fails with C# containers

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 cod开发者_如何学Ce 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>();


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜