在 Wordpress.com 中显示 C# 代码
我已经研究了几个小时,但我有点沮丧。也许我只是错过了一些东西,因为我是博客新手。
我不托管我自己的博客,我只是使用 WordPress.com。 我想包含 C# 代码片段,并让它们看起来像在 Visual Studio 中一样,或者至少让它们看起来不错,当然还有行号和颜色。 我见过的解决方案似乎都假设您正在托管自己的博客。 我不知道如何安装插件。
是否有一个小部件可以使代码片段看起来不错,或者我可以轻松使用其他一些解决方案?
谢谢
编辑:Sarfraz概述了解决我的问题的一种方法(谢谢!),我已经尝试过,但有一个问题,即它不会对我的大部分代码进行着色(较新的关键字,例如 var、from、where、select 等)。有解决这个问题还是有其他解决方案?
I have researched this for a few hours and I am kind of frustrated. Maybe I am just missing something as I am new to blogging.
I am not hosting my own blog, I am just using WordPress.com.
I want to include snippets of c# code and have them look like they do in Visual Studio, or at least make them look nice, certainly with line numbers and color.
The solutions I have seen for this all seem to assume you are hosting your own blog.
I cannot figure out how to install plugins.
Is there a widget that will make code snippets look nice, or some other solution I can easily use?
Thank you
EDIT: Sarfraz has outlined one way to solve my problem (thank you!), and I have tried it but there is an issue I have, namely that it does not colorize most of my code (newer keywords like var, from, where, select, etc). Is there a fix to this or is there some other solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需在 html 模式下编辑您的文章,并将您的代码包含在这些标签中即可。
示例:
注意:您需要为
语言
属性指定正确的语言标识符,如上所示。更多信息在这里:)
Just edit your aricles in html mode and enclose your code within these tags.
Example:
Note: You need to specify correct language identifier for the
language
attribute as shown above.More Information Here :)
[sourcecode] 标签通常适用于 C#,但对我来说,当我发布 XAML 代码时,它经常会中断。
相反,我使用此页面来格式化我的代码。结果看起来不错(您可以在我的博客上看到它),但它需要“自定义CSS”选项(15 美元/年)。
编辑:实际上 [sourcecode] 标签工作正常,我现在在所有帖子中使用它
The [sourcecode] tag usually works fine for C#, but for me it often breaks when I post XAML code.
Instead I use this page to format my code. The result looks nice (you can see it on my blog), but it requires the "Custom CSS" option ($15/year).
EDIT: actually the [sourcecode] tag works fine, and I'm now using it in all my posts
看起来这已经更新了,现在您可以使用
注意:您可以将语言简写为 lang
这是支持的语言列表
looks like this has been updated, now you can use
note: you can shorthand language as lang
here is the list of supported languages