分享

SyntaxHighlighter使用介绍 | 代码至上

 zhuoyue图书馆 2012-05-10

SyntaxHighlighter使用介绍

2011年4月19日  964 views 发表评论 阅读评论
我的博客中使用了WordPress的插件 SyntaxHighlighter 这是一个代码高亮、模式化的工具,能让你的代码在网页上以类似IDE编辑器里的样子高亮关键字。功能挺强的,支持的语言很多,我列在下面了。在文章的最后,我将SyntaxHighlighter自带帮助文档列了出来,并稍微翻译了一下。
具体用法:
  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。

点击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.(自动换行)
一些简码示例

[@php]这里写你的代码[/php]

1
这里写你的代码

[@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]

example-filename.php
1
这里写你的代码

[@code lang="js"]这里写你的代码[/code]

1
这里写你的代码

[@sourcecode language="plain"]这里写你的代码[/sourcecode]

1
这里写你的代码
?

声明:未作说明,则本文为代码至上原创。转载务必注明出处
注意:转载须保留全文,如需修改请 联系作者
本文永久地址:http:///archives/128

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多