SyntaxHighlighter 可以將你在blog貼上的程式碼漂亮的排版,
SyntaxHighlighter官方website:
http://alexgorbatchev.com/SyntaxHighlighter/download/
這邊的教學,主要是讓你不必下載任何檔案,
就可以嵌入SyntaxHighlighter的css和js檔,
首先將以下的程式碼複製: 將這一段程式碼加入<head></head>標籤之間,
<!--SYNTAX HIGHLIGHTER BEGINS-->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
<!--SYNTAX HIGHLIGHTER ENDS-->
編輯文章時,在程式碼的前後加上<pre class="brush:java"></pre>
(這裡使用java語言作為範例)
<pre class="brush:java">
public class HelloWorld
{
public static void main(String [] args)
{
System.out.println("HelloWorld");
}
}
</pre>
之後就會看到程式碼有顏色標示了。
public class HelloWorld
{
public static void main(String [] args)
{
System.out.println("HelloWorld");
}
}