[Web]SyntaxHighlighter

我的博客中使用了WordPress的插件 SyntaxHighlighter 这是一个代码高亮、模式化的工具,能让你的代码在网页上以类似IDE编辑器里的样子高亮关键字。功能挺强的,支持的语言很多,我列在下面了。在文章的最后,我将SyntaxHighlighter自带帮助文档列了出来,并稍微翻译了一下。
具体用法:

  1. 在代码前根据代码语言的不同加上不同的[%Lang]在代码后加上[/%Lang],%Lang = 你用的语言对应的Brush aliases(具体对应罗列于下)。例如[@cpp]#include [/cpp](@去掉)。
  2. 或者只用一次%Lang,[@code lang=%Lang]你的代码[/code]或者[@source lang=%Lang]你的代码[@source lang=%Lang],其中lang都可以换成language。





























































































































Brush nameBrush aliasesFile name
ActionScript3as3, actionscript3shBrushAS3.js
Bash/shellbash, shellshBrushBash.js
ColdFusioncf, coldfusionshBrushColdFusion.js
C#c-sharp, csharpshBrushCSharp.js
C++cpp, cshBrushCpp.js
CSScssshBrushCss.js
Delphidelphi, pas, pascalshBrushDelphi.js
Diffdiff, patchshBrushDiff.js
Erlangerl, erlangshBrushErlang.js
GroovygroovyshBrushGroovy.js
JavaScriptjs, jscript, javascriptshBrushJScript.js
JavajavashBrushJava.js
JavaFXjfx, javafxshBrushJavaFX.js
Perlperl, plshBrushPerl.js
PHPphpshBrushPhp.js
Plain Textplain, textshBrushPlain.js
PowerShellps, powershellshBrushPowerShell.js
Pythonpy, pythonshBrushPython.js
Rubyrails, ror, rubyshBrushRuby.js
ScalascalashBrushScala.js
SQLsqlshBrushSql.js
Visual Basicvb, vbnetshBrushVb.js
XMLxml, xhtml, xslt, html, xhtmlshBrushXml.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.(在HTML中插入PHP经常使用这种方法)
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.(自动换行)
一些简码示例

[php]这里写你的代码[/php]
[css autolinks=”false” classname=”myclass” collapse=”false” firstline=”1” gutter=”true” highlight=”1-3,6,9” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4” toolbar=”true” title=”example-filename.php”]这里写你的代码[/css]