試用過幾個語法標記顯示的外掛,最後選擇了google syntax highlighter,其實每個標記外掛都有它的優缺點,沒有最好的,只好選容易修改成合我意的,修正處如下所述:

1. 中文標示
編輯shCore.js,搜尋下列字串並取代:
| expand source | 擴展原始碼 |
| view plain | 純文字 |
| copy to clipboard | 複製 |
| 列印 | |
| The code is in your clipboard now | 代碼已複製到剪貼簿 |
| Printing | 列印中 |
2. 斷行
會自動斷行,但這是我不喜歡的功能,有需要我自己會斷;編輯SyntaxHighlighter.css,在.dp-highlighter這個類別加入white-space:nowrap;
.dp-highlighter {
font-family: "Consolas", "Courier New", Courier, mono;
font-size: 12px;
background-color: #E7E5DC;
width: 99%;
overflow: auto;
margin: 18px 0px 18px 0px;
padding-top: 1px; /* adds a little border on top when controls are hidden */
white-space:nowrap;
}
3. 可控制高度
它的設計是你代碼有多長,就會跑多長出來,所以我把它改成可用id控制高度;編輯shCore.js,在最下方找到highlighter.Highlight(element[propertyName]);後面加入if (element.id!='') highlighter.div.id = element.id;
highlighter.Highlight(element[propertyName]); if (element.id!='') highlighter.div.id = element.id;
範例:
//設定id
<pre name="code" class="javascript" id="test1">
//填寫代碼
</pre>
<script>
//設定高度
document.getElementById("test1").style.height = "150px";
</script>
2. SyntaxHighlighter.css更新到1.5.1版後,連結有位移情況,所以改用回1.5版
3. google syntax highlighter 2.0版要錢,所以沒有在用
在Google及Yahoo找資料,已成為許多人每天必行的公事。「網路」的無遠弗屆,造就了一個世界級的知識寶庫,著實讓我受益良多。
設立此部落格除用做網路行銷、學習記事與知識管理外,希望也能做些回饋和經驗分享,如果有人能從這裡的文章得到一點幫助就好了...
網站生日:2008/09/16 年紀:24個多月
寫下留言