寫Blogger的人,若是程式設計人員,想必有要貼Code的需求。可是直接貼上的話,又會遇到美觀的問題,經由Google的協助我找到一個不算糟的解決方案,那就是使用SyntaxHighlighter這個外掛,官網是http://alexgorbatchev.com/wiki/SyntaxHighlighter,安裝方式可以參考這兩篇文章:
我的使用方式如下,在HTML中的head區塊最後貼上這些程式碼:
<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/shBrushJScript.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/shBrushPhp.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/shBrushCSharp.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/shBrushXml.js' type='text/javascript'/> <script type='text/javascript'> SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.all(); </script>
當需要使用的時候,將你的程式碼放在<pre class="brush:html">和</pre>之間即可,針對不同的程式更改類別屬性,前述是針對HTML進行程式碼美化。這項SyntaxHighlighter支援的程式碼請參考這裡。
要注意的是,如果程式碼之中有特殊的HTML符號,則需要使用相對應的編碼,如小於的<和大於的>編碼等等。
沒有留言:
張貼留言