2010年3月14日 星期日

在Blogger中加入程式碼區塊(使用SyntaxHighlighter )

資訊主頁版面配置修改HTML
</body>標籤之前加入下方程式碼,然後儲存範本


<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushAS3.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushBash.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCpp.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushColdFusion.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCss.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushDelphi.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushDiff.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushErlang.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushGroovy.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJava.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJavaFX.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushJScript.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPerl.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPhp.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPlain.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPowerShell.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushPython.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushScala.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushVb.js"></script>

<script type="text/javascript"
src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js"></script>

<link type="text/css" rel="stylesheet"
href="http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css"/>

<link type="text/css" rel="stylesheet"
href="http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css"/>

<script type="text/javascript"> SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf';

SyntaxHighlighter.config.bloggerMode = true;

SyntaxHighlighter.all();

</script>





之後在建立新文章便可以使用程式碼區塊了,使用方式如下:
新文章➝切換到修改html,加入程式碼 。(ps.發布文章後才會正確顯示)




<pre class="brush: language;">
// 欲顯示的程式碼
</pre>



language的部分就是想要顯示的語言,可用下表對應名稱替換


語言名稱對應名稱
ActionScript3 as3, actionscript3
Bash/shell bash, shell
ColdFusion cf, coldfusion
C# c-sharp, csharp
C++ cpp, c
CSS css
Delphi delphi, pas, pascal
Diff diff, patch
Erlang erl, erlang
Groovy groovy
JavaScript js, jscript, javascript
Java java
JavaFX jfx, javafx
Perl perl, pl
PHP php
Plain Text> plain, text
PowerShell ps, powershell
Python py, python
Ruby rails, ror, ruby
Scala scala
SQL sql
Visual Basic vb, vbnet
XML xml, xhtml, xslt, html, xhtml



如下:以C#作為顯示語言



<pre class="brush: c-sharp;">

class CTest

{

class CTest() { }

}

</pre>


沒有留言:

張貼留言