如何向 WordPress.com 上托管的 WordPress 博客添加语法突出显示?

发布于 2024-08-02 05:56:38 字数 86 浏览 6 评论 0 原文

我想为我的 WordPress 博客提供一个好的语法荧光笔。我有哪些选择?我经常看到它具有颜色鲜艳的语法突出显示和复制到剪贴板的选项。有人知道这是什么工具吗?

I'd like to have a good syntax highlighter for my WordPress blog. What options do I have available? I often see one which has well-colored syntax highlighting and options to copy to the clipboard. Does anyone have an idea what tool this is?

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

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

发布评论

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

评论(9

野心澎湃 2024-08-09 05:56:38

在 wordpress.com 上,您无法安装插件,因此您必须使用 Wordpress 的内置小部件。

这样做:

[code language='python']

[/code]

请注意,这些标签位于可视化编辑器中,而不是 HTML 编辑器中。

您可以在此处找到更多信息。

On wordpress.com, you can't install plugins, so you have to use Wordpress' built-in widget.

Do it like:

[code language='python']

[/code]

Note that those tags go inside your visual editor, not the HTML editor.

You can find more information here.

静赏你的温柔 2024-08-09 05:56:38

语法高亮的最佳方法是使用 prismjs,它完全免费,具有很棒的功能。

  1. 它支持几乎所有编程语言、shell 脚本等等。

  2. 它的重量非常轻,不会像其他语法突出显示插件那样降低您的网站速度。

为了配置 prismjs,您需要在 function.php 文件中进行少量代码调整。关注此博客中的图罗
http://skillslane.com/setup-syntax-highlighter-for-wordpress/

The best way for syntax highlighting is using prismjs, which is completely free with awesome features.

  1. It has support for almost all programming languages, shell scripts and much more.

  2. It is very light weight and it will not bog down your sites speed like other syntax highlighting plugins.

For configuring prismjs you need to do little code tweaks in your function.php file. Follow the turoails in this blog
http://skillslane.com/setup-syntax-highlighter-for-wordpress/

白首有我共你 2024-08-09 05:56:38

SyntaxHighlighter 是一个非常好的工具。它使用 JavaScript 和 CSS 类来标记应突出显示的 HTML 元素。它还允许将代码复制到剪贴板并打印。

SyntaxHighlighter is a pretty good tool. It uses JavaScript with CSS classes to mark HTML elements that should be highlighted. It also allows code to be copied to the clipboard and printed.

肩上的翅膀 2024-08-09 05:56:38

http://wordpress.org/extend/plugins/devformatter/

各种语法的 WP 插件突出显示!

http://wordpress.org/extend/plugins/devformatter/

WP Plugin for various syntax highlighting!

夏见 2024-08-09 05:56:38

如果您不想或无法在博客上安装内容,我建议您使用 pygments 来突出显示您的代码。我描述了这个此处

If you don't want to, or can't install stuff on your blog, I suggest you use pygments to highlight your code. I described this here.

优雅的叶子 2024-08-09 05:56:38

这是一个离线选项(我知道您正在询问在线工具,但以防万一......)

我使用离线工具将带有源代码示例的博客条目处理为 html 格式,然后发布 html。

其实很简单:

  • 将源代码偏移至少 4
    空格并指定语言
    :::html 这样的第一行
  • 通过以下方式运行您的文件:

python script:

import markdown
html = markdown.markdown(text,['codehilite'])

I setup markdown with pygments 也许您可以只使用 pygments 作为源代码。您运行该文件和脚本,然后将 html 复制粘贴到您的博客中。

您可以从 pygments 转储 css 样式以突出显示语法,然后链接到它或将其包含在您的页面中。我不确定 wordpress 是否支持。

以下是如何使用 pygments 设置 Markdown语法突出显示(对于 Blogger - Blogger 的唯一细节是它使用 css 更新 Blogger css 以突出显示代码)。

Here is an offline option (I know you are asking about online tool but just in case ...)

I use offline tools to process the blog entry with source code examples into html format and then just post the html.

It's really just:

  • offset source code by at least 4
    spaces and specify language on the
    first line like :::html
  • run your file through:

python script:

import markdown
html = markdown.markdown(text,['codehilite'])

I setup markdown with pygments probably you could just use pygments for source code. You run the file thought the script and then copy paste the html to your blog.

You can dump css style, to highlight syntax, from pygments and then either link to it or include it in your page. I'm not sure if wordpress supports that.

Here is how to setup markdown with pygments to do syntax highlighting (for Blogger - the only specifics for Blogger is that it updates the Blogger css with the css to highlight code).

情感失落者 2024-08-09 05:56:38

您可以使用 Alex Gorbatchev 的 SyntaxHighlighter。它的 javascript 非常简单且支持良好,易于安装和修改。以下是针对 blogger 的一些说明...但您所要做的就是删除 blogger=true 行。

http://code-slim -jim.blogspot.com/2010/11/adding-syntax-higher-to-your-blog.html

You could use the Alex Gorbatchev's SyntaxHighlighter. Its javascript and really simple and well supported, easy to install and modify. Here are some instructions for blogger... but all you have to do you to do is remove the blogger=true line.

http://code-slim-jim.blogspot.com/2010/11/adding-syntax-higher-to-your-blog.html

可可 2024-08-09 05:56:38

我为 WordPress 开发了一个轻量级语法高亮插件,名为“Mivhak”。该插件有一个后端代码编辑器,可以轻松插入代码,并具有实时错误检查和语法突出显示功能。它也是高度可定制的。

该插件托管在 wordpress.org 上

I have developed a lightweight syntax highlighter plugin for WordPress called "Mivhak". The plugin has a backend code editor to easily insert code, with live error checking and syntax highlighting. It is also highliy customizable.

The plugin is hosted on wordpress.org

贱贱哒 2024-08-09 05:56:38

它现在支持 SyntaxHighlighter Code 块。

虽然有点不方便,但必须在旁边的设置中选择语言。

It now supports SyntaxHighlighter Code blocks.

Although it's a little inconvenient that languages must be chosen in the aside settings.

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