code
最簡單的最好 – 用 pre 的 CSS style
CSS 是這樣的
pre {
background: #F0F0F0 url(images/blogger-code.gif) repeat-y scroll left top;
border: 1px solid #CCCCCC;
color: #333333;
display: block;
font-family: Courier New;
font-size: 8pt;
line-height: 120%;
margin: 5px 0 0 20px;
max-height: 200px;
overflow: auto;
padding: 10px 10px 10px 21px;
width: 90%;
}
完全不用 javascript , 直接寫到 wordpress 的 style.css 裡 , 要用時就直接用 html pre tag 就好, 比上次找的
SyntaxHighlighter Plus 還方便, 雖然沒有 syntax highlight , 不過就是簡單, 再說 blog 上面也不適合放一大串的程式碼不是嗎?
// sample code :
for ( $i=0; $i<10; $i++ ) {
// do something
}
裝了 SyntaxHighlighter Plus , 程式碼可以看清楚了
It supports the following languages (the alias for use in the post is listed next to the name):
* Bash — bash, sh
* C++ — cpp, c, c++
* C# — c#, c-sharp, csharp
* CSS — css
* Delphi — delphi, pascal
* Java — java
* JavaScript — js, jscript, javascript
* PHP — php
* Python — py, python
* Ruby — rb, ruby, rails, ror
* SQL — sql
* VB — vb, vb.net
* XML/HTML — xml, html, xhtml, xslt
修改 … /wp-content/plugins/syntaxhighlighter-plus/shlfiles/SyntaxHighlighter.css
把 .dp-highlighter 的 width 改成想要的寬度
[code language=C]
#include
main() {
printf(“Hello World!”);
}
[/code]
