google-code-prettifyでソースコードのシンタックスハイライト

| | Comments (0) | TrackBacks (1)
google-code-prettifyでソースコードをシンタックスハイライトする方法を示す。
本ブログではgoogle-code-prettifyを導入済みなので、HTMLソースを適宜参照されたい。


手順は大まかに次の通りである。


  1. google-code-prettifyをダウンロード
  2. google-code-prettifyをウェブサーバにアップロード
  3. google-code-prettify本体(jsおよびcss)をインクルード
  4. google-code-prettifyのprettyPrint()をbodyタグのonloadイベントでcall
  5. シンタックスハイライトしたい部分をpreタグでくくりprettyprintクラスを適用


1. google-code-prettifyはgoogleのサイトからダウンロードする。
2. アップロードはffftpwinscpなど、任意の方法でアップロードする。
3. headタグは次のようにする。


<head>
<title>this is a title.</title>
<link href="/js/google_code_prettify/prettify.css" rel="stylesheet" type="text/css"/>
<script src="/js/google_code_prettify/prettify.js" type="text/javascript"></script>
</head>


ただし、pretty.cssおよびpretty.jsの場所はアップロード先によって変更の必要がある。


4. bodyタグは次のようにする。


<body onload="prettyPrint()">


5. preタグの適用は次のようにする。


<pre class="prettyprint">ソースコード</pre>


Enjoy!! ともにソースコードを晒しましょう。

1 TrackBacks

Listed below are links to blogs that reference this entry: google-code-prettifyでソースコードのシンタックスハイライト.

TrackBack URL for this entry: http://mahata.net/movabletype/mt-tb.cgi/2978

前々からシンタックスハイライトをしたいと思っていたのですが、検索したところ google-code-prettifyでソースコードのシンタックスハイライト... Read More

Leave a comment

About this Entry

This page contains a single entry by mahata published on October 3, 2007 8:41 PM.

MovableTypeで変数の値で条件分岐 was the previous entry in this blog.

last.fmから最新の再生履歴を配列として取得するphpスクリプト is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.