2010年10月29日 星期五

怎麼在blogger貼程式碼

首先 ,到 SyntaxHighLighter下載檔案
http://alexgorbatchev.com/SyntaxHighlighter/
並找一個空間host裡面的js,css檔案

假設我們存放在xxx.xxx.xxx裡面

登入blogger,並至設定,修改html裡面


<!-- 設定載入 shCore.css 與 shThemeDefault.css --> 
<link href='http://xxx.xxx.xxx/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://xxx.xxx.xxx/shThemeDefault.css' rel='stylesheet' type='text/css'/> 
<!-- 設定需要載入的核心檔案 shCore.js --> 
<script src='http://xxx.xxx.xxx/shCore.js' type='text/javascript'/> 
<!-- 設定需要載入的程式語言檔案 --> 
<script src='http://xxx.xxx.xxx/shBrushJScript.js' type='text/javascript'/> 
<script src='http://xxx.xxx.xxx/shBrushSql.js' type='text/javascript'/> 
<script src='http://xxx.xxx.xxx/shBrushVb.js' type='text/javascript'/> 
<script src='http://xxx.xxx.xxx/shBrushXml.js' type='text/javascript'/> 
<!-- 設定啟用 highlighter --> 
<script type='text/javascript'> 
     SyntaxHighlighter.config.bloggerMode = true; 
     SyntaxHighlighter.all()
</script> 


將前述程式碼貼在 <body> 後面
儲存,就算是設定完成了



平時貼程式碼的方法,假設我要貼下列程式碼

function helloSyntaxHighlighter()
{
 return "hi!";
}

就在發表文章中的修改html以下列方式撰寫

<pre class="brush: js;">
function helloSyntaxHighlighter()
{
return "hi!";
}
</pre>

如果你的文字有特殊字元,不要忘記先encode,
http://www.opinionatedgeek.com/dotnet/tools/htmlencode/encode.aspx

1 則留言: