SyntaxHighlighter使用介绍

WordPress的插件 SyntaxHighlighter 是一个代码高亮、模式化的工具,能让你的代码在网页上以类似IDE编辑器里的样子高亮关键字。功能挺强的,支持的语言很多。

具体用法:
  1. 在代码前根据代码语言的不同加上不同的[%Lang]在代码后加上[/%Lang],%Lang = 你用的语言对应的Brush aliases(具体对应罗列于下)。例如[@cpp]#include <stdio.h>[/cpp](@去掉)。
  2. 或者只用一次%Lang,[@code lang=%Lang]你的代码[/code]或者[@source lang=%Lang]你的代码[@source lang=%Lang],其中lang都可以换成language。
  3. 例如:<pre class=”brush: plain; first-line: 1″> …你的代码…</pre>

点击Brush name 有官方网站的详细介绍和Demo,有兴趣的童鞋可以去看看。对于技术类的博客来说,这种语法高亮插件是必不可少的欧~

Brush name Brush aliases File name
ActionScript3 as3, actionscript3 shBrushAS3.js
Bash/shell bash, shell shBrushBash.js
ColdFusion cf, coldfusion shBrushColdFusion.js
C# c-sharp, csharp shBrushCSharp.js
C++ cpp, c shBrushCpp.js
CSS css shBrushCss.js
Delphi delphi, pas, pascal shBrushDelphi.js
Diff diff, patch shBrushDiff.js
Erlang erl, erlang shBrushErlang.js
Groovy groovy shBrushGroovy.js
JavaScript js, jscript, javascript shBrushJScript.js
Java java shBrushJava.js
JavaFX jfx, javafx shBrushJavaFX.js
Perl perl, pl shBrushPerl.js
PHP php shBrushPhp.js
Plain Text plain, text shBrushPlain.js
PowerShell ps, powershell shBrushPowerShell.js
Python py, python shBrushPython.js
Ruby rails, ror, ruby shBrushRuby.js
Scala scala shBrushScala.js
SQL sql shBrushSql.js
Visual Basic vb, vbnet shBrushVb.js
XML xml, xhtml, xslt, html, xhtml shBrushXml.js

简码参数

这些参数你能够设置在简码中。对于布尔值(即 on/off),使用 true/1 或者 false/0。

lang or language — The language syntax to highlight with. You can alternately just use that as the tag, such as [@php]code[/php]. (代码语言)
autolinks — Toggle automatic URL linking.(将URL自动转换成链接)
classname — Add an additional CSS class to the code box.(加载额外CSS控制)
collapse — Toggle collapsing the code box by default, requiring a click to expand it. Good for large code posts.(收缩代码框,对于大量代码很有用)
firstline — An interger specifying what number the first line should be (for the line numbering).(首行号)
gutter — Toggle the left-side line numbering.(是否显示左侧行号)
highlight — A comma-sperated list of line numbers to highlight. You can also specify a range. Example: 2,5-10,12(高亮行号)
htmlscript — Toggle highlighting any extra HTML/XML. Good for when you're mixing HTML/XML with another language, such as having PHP inside an HTML web page. The above preview has it enabled for example. This only works with certain languages.(不清楚)
light — Toggle light mode which disables the gutter and toolbar all at once.(不显示行号和工具条)
padlinenumbers — Controls line number padding. Valid values are false (no padding), true (automatic padding), or an integer (forced padding).(控制行号行间距)
title (v3 only) — Sets some text to show up before the code. Very useful when combined with the collapse parameter.
toolbar — Toggle the toolbar (buttons in v2, the about question mark in v3)(标题,显示在代码前)
wraplines (v2 only) — Toggle line wrapping.(自动换行)

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>