PukiWikiでgoogle-code-prettifyを利用してソースコードをハイライト表示するプラグインです。 google-code-prettify自体はjavascriptで動作します。
-
pukiwiki.codeprettifyをダウンロードする
-
ファイルを解凍し、codeprettify.inc.phpをpluginフォルダの下に配置する
-
google-code-prettifyをダウンロードする
http://code.google.com/p/google-code-prettify/ から、下記のいずれかをダウンロード:
prettify-{日付}.zip prettify-small-{日付}.zip
smallがついてるのはコメントや改行などを縮小化したバージョンで機能的にはどちらも同じ、コードに興味がある人は前者、 とりあえず使えればいいやという人は後者でよい。
-
google-code-prettifyのzipファイルを解凍し、下記ファイルをskinフォルダの下に置く
prettify.css prettify.js
-
skin/pukiwiki.skin.phpファイルを編集し、google-code-prettifyのcssファイルとjsファイルを追加する
<link rel="stylesheet" type="text/css" media="print" href="skin/pukiwiki.css.php?charset=<?php echo $css_charset ?>&media=print" charset="<?php echo $css_charset ?>" />
の下あたりに下記を追加
<link href="skin/prettify.css" rel="stylesheet" type="text/css" charset="utf-8"/> <script src="skin/prettify.js" type="text/javascript" charset="utf-8"></script>
さらにbodyタグを以下のように変更する
<body onload="prettyPrint();">
-
複数行の引数を有効にする
pukiwiki.ini.phpを編集し、PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACKのdefineを探して、値を0にする
define('PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK', 0); // 1 = Disabled
ブロック型とインラインの両方に対応しています
#codeprettify{{
<?php
echo 'test';
?>
}}
&codeprettify{<?php echo 'test'; ?>};
google-code-prettifyでは言語の指定や、行数の表示がcssクラスの指定で行えます。 codeprettifyプラグインでは関数の第一引数で追加するcssクラス指定できます。
#codeprettify(lang-html linenums:4){{
<body>
<h1>codeprettify</h1>
</body>
</html>
}}
http://www.gnu.org/licenses/gpl.html GPLv2
Copyright 2008-2010 Makoto Kawasaki