在 Wordpress.com 中显示 C# 代码

发布于 2024-08-23 08:44:06 字数 481 浏览 5 评论 0原文

我已经研究了几个小时,但我有点沮丧。也许我只是错过了一些东西,因为我是博客新手。

托管我自己的博客,我只是使用 WordPress.com。 我想包含 C# 代码片段,并让它们看起来像在 Visual Studio 中一样,或者至少让它们看起来不错,当然还有行号和颜色。 我见过的解决方案似乎都假设您正在托管自己的博客。 我不知道如何安装插件。

是否有一个小部件可以使代码片段看起来不错,或者我可以轻松使用其他一些解决方案?

谢谢

编辑:Sarfraz概述了解决我的问题的一种方法(谢谢!),我已经尝试过,但有一个问题,即它不会对我的大部分代码进行着色(较新的关键字,例如 varfromwhereselect 等)。有解决这个问题还是有其他解决方案?

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 技术交流群。

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

发布评论

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

评论(4

把回忆走一遍 2024-08-30 08:44:07

只需在 html 模式下编辑您的文章,并将您的代码包含在这些标签中即可。

[sourcecode language="css"]
[/sourcecode]

示例:

[sourcecode language="javascript"]
 // javascript hello world program
 alert('Hello, World !!');
[/sourcecode]

注意:您需要为语言属性指定正确的语言标识符,如上所示。

更多信息在这里:)

Just edit your aricles in html mode and enclose your code within these tags.

[sourcecode language="css"]
[/sourcecode]

Example:

[sourcecode language="javascript"]
 // javascript hello world program
 alert('Hello, World !!');
[/sourcecode]

Note: You need to specify correct language identifier for the language attribute as shown above.

More Information Here :)

看透却不说透 2024-08-30 08:44:07

[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

风情万种。 2024-08-30 08:44:07
    [code language="csharp"]
       //Your code here
    [/code]
    [code language="csharp"]
       //Your code here
    [/code]
不必你懂 2024-08-30 08:44:07

看起来这已经更新了,现在您可以使用

[code language="[the lang you are posting]"]
your code here
[/code]

注意:您可以将语言简写为 lang

[code lang="[the lang you are posting]"]
your code here
[/code]

这是支持的语言列表

looks like this has been updated, now you can use

[code language="[the lang you are posting]"]
your code here
[/code]

note: you can shorthand language as lang

[code lang="[the lang you are posting]"]
your code here
[/code]

here is the list of supported languages

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