Prettify - syntax highlight
mikesamuel 做的 syntax highlight 也是使用 Javascript & CSS 完成的 - google-code-prettify
支援的語言包含 C系列, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, 還有Makefiles. 而 Ruby, PHP, Awk, Perl 表現也還可以, 但是因為註解符號的關係無法使用在 Smalltalk, Lisp-like, CAML-like上.
1. include .js & .css
// 這裡
// 或是這裡
<pre class="prettyprint"/> (有框框):
#!/bin/bash
# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
local a=1
local b=1
while true ; do
echo $a
local tmp=$a
a=$(( $a + $b ))
b=$tmp
done
}
# output the 10th element of the series and halt
fib | head -10 | tail -1
<code class="prettyprint"/> (沒有框框):
/**
* nth element in the fibonacci series.
* @param n >= 0
* @return the nth element, >= 0.
*/
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.write(fib(10));
