我尝试了这个相关的SO问题中发布的解决方案以及大部分代码片段都可以正常工作,但在某些情况下,Blogger 在发布博客时仍然出现乱码。
尤其是声明通用容器似乎是最麻烦的。请参阅我博客上的代码示例:http://mlai-lirik.blogspot.com/ ,特别是我声明字典的部分。
我想显示这个:
static Dictionary<int, List<Delegate>> _delegate = new Dictionary<int,List<Delegate>>();
但是博客发布了这个:
static Dictionary<int, list=""><delegate>> _delegate = new Dictionary<int, list=""><delegate>>();
并且它用这个来结束我的代码部分:
</delegate></delegate></int,></delegate></int,>
显然博客认为 和
字典的一部分是某种 HTML 标签,它会自动尝试在代码片段的末尾关闭它们。有人知道如何解决这个问题吗?
更新:
我使用了CraftyFella的解决方案http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html 并导致上述情况-提到要发生的问题(即他的解决方案不适用于我发布的代码片段)。
我还尝试使用
标签包装我的代码片段,但这也不起作用。结果同样令人失望:Dictionary> test = new Dictionary>();
变成 Dictionary>;测试 = 新字典>();
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)
我用
<
替换了所有<
并得到了 这个。 (实际上,我在 SO 上使用了同样的技巧。)I replaced all of the
<
with<
and got this. (Same trick I use on SO, actually.)您所要做的就是对您的程序进行 HTML 编码。首先将所有
&
替换为&
,然后将所有<
替换为<
并>
与>
。尽管最后一个并不是严格要求使其工作的,但我认为它对于正确性更好。What you have to do is HTML encode your program. First replace all
&
with&
, then replace all<
with<
and>
with>
. Although the very last one isn't strictly required to get it to work, I think it's better for correctness.