在博客中发布源代码 - 使用 C# 容器失败

发布于 2024-08-30 17:48:57 字数 1519 浏览 8 评论 0 原文

我尝试了这个相关的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>();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

<逆流佳人身旁 2024-09-06 17:48:58

我用 < 替换了所有 < 并得到了 这个。 (实际上,我在 SO 上使用了同样的技巧。)

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

懒的傷心 2024-09-06 17:48:58

您所要做的就是对您的程序进行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文