BloggerAds

搜尋此網誌

2011年9月20日 星期二

程式筆記 - 在Blogger中使用SyntaxHighlighter


SyntaxHighlighter可以解析程式碼,加上行數以及對關鍵字加上顏色處理, 增加程式碼美觀及可讀性.

網址:
http://alexgorbatchev.com/SyntaxHighlighter/




有在部落格貼程式碼的人可以考慮使用, 可以讓程式碼更整齊美觀一點, 下面是有使用跟沒使用的差別...


使用SyntaxHighlighter
class Test : public Parents
{
public:
    Test();
    ~Test();
public:
    int mId;
};
int main()
{
    Test aa;
    return 0;
}


無使用SyntaxHighlighter
class Test : public Parents
{
public:
Test();
~Test();
public:
int mId;
};
int main()
{
Test aa;
return 0;
}

安裝方法:

官方提供了兩種安裝方法, 沒要特別做修改傳到自己空間的可以使用hosted version

1.開啟Blogger設定頁,點選設計->修改HTML

2.找到</head>, 在前面貼上

<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"></link>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript">
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushColdFusion.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.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/shBrushDelphi.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushErlang.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.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/shBrushJavaFX.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>

3.找到</body>, 在前面貼上,並存檔跳出設定頁

<script type='text/javascript'>
SyntaxHighlighter.all()
</script>

4.測試,在Blogger文章貼上html

<pre class="brush:cpp">
int main()
{
return 0;
}
</pre>


5.網頁顯示最終結果
int main()
{
return 0;
}


原帖:
http://arkkk.blogspot.com/2011/09/test.html

1 則留言: