Webサイトとは「つい、うっかりの存在論」である。

角谷HTML化計画

「むずかしく考えることはない」と、偉そうに葉巻を振りまわしながら、トレヴィラヌスはいった。「ガリラヤの太守がじつにみごとなサファイアを持っていることは、みんなが知っている。何者かがそれを盗むつもりで、間違ってここへ入ったんだ。ヤルモリンスキーが起きていたので、泥棒は殺さざるをえなかった。どうだね、これで?」
 「そのとおりかもしれません。しかし、おもしろくはないですね」と、レンロットは答えた。
J.L.ボルヘス『死とコンパス』(『伝奇集』収録)

2007-03-05(Mon) [長年日記]

■1 tDiaryでRuby(やYAML、XML)のコードに色をつける

思い出すのに時間がかかっちゃいました。基本的には、かずひこさんの日記を読んで、 syntaxを導入。rubyとyamlとxmlに色を付けられます。私の環境ではhikidoc.rbに要パッチ。CSSを適用させるために簡単なプラグインも書きました。

手順としては以下のような流れだった模様:

  1. syntaxをインストール
  2. syntaxライブラリをtDiaryに配置
  3. (hikidoc.rbにパッチを適用)
  4. 色付け用のcssファイルを用意してサーバに配置
  5. syntax_stylesheets.rbプラグインを用意
  6. 色を付けたいコードをsuper preっぽく書く

以下、順番に説明します。

1. syntaxをインストール

どうやら私はgemでローカルにインストールしたらしい。たぶん、後述の色付け用のcssを使いたかったから。

gem install syntax

(rubyforgeに置いてある、zipやtar.gzとかのアーカイブには色付け用のcssが入ってないっぽい?)

2. syntaxライブラリをtDiaryに配置

$GEM_HOME/gems/syntax-1.0.0/lib にあるファイルとディレクトリを、tDiaryのルートディレクトリ(という呼び方で良いのかな? index.rbがあるのと同じディレクトリ)に配置。具体的には、syntax.rbとsyntaxディレクトリ。

(3. hikidoc.rbにパッチを適用)

これは任意かな。私のmod_ruby環境ではSecurityErrorが発生したので、hikidocにパッチを当てた。また、このパッチにはsyntaxに付属しているサンプル用のCSSのクラスを使うようにもしてある(この後の手順で利用)。いちおうこのパッチはhikidocのMLに投げてあるけど無反応なので、なにか間違ってるかも。ご参考まで。

4. 色付け用のcssファイルを用意してサーバに配置

色付け用のcssを頑張って書く。私は面倒だったので、$GEM_HOME/gems/syntax-1.0.0/data にある ruby.css, yaml.css, xml.cssを使った。このファイル群をtDiaryの動いているhttpdから見えるところに置く。私の場合は、http://kakutani.com/stylesheets/syntax/

5. syntax_stylesheets.rbプラグインを書く

syntaxの色付け用スタイルシートをtDiaryに認識させる。私は、脊髄反射で簡単なプラグインを用意して<head>に追加した。もっとカッコいいやり方があるんじゃないかと。

syntax_stylesheets.rb
add_header_proc do
   <<-EOS
        <link rel="stylesheet" href="/stylesheets/syntax/ruby.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="/stylesheets/syntax/yaml.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="/stylesheets/syntax/xml.css"  type="text/css" media="screen" />
   EOS
end

6. 色を付けたいコードをsuper preっぽく書く

<<<ruby
...
>>>

と書くと、コードに色がつくようになる。yamlとxmlの場合も同様。グダグダな手順ですが、ともかく色づけはできる、ということで。参考になるといいな。

本日のツッコミ(全3件) [ツッコミを入れる]
kdmsnr (2007-03-05(Mon) 15:22)

ありがとうございます。syntaxのcssファイルを使うには、角谷さんのパッチが必要ですね(デフォルトではpreタグにclassがつかなくて悩みました)。

かずひこ (2007-03-05(Mon) 18:01)

Syntaxライブラリは、対応言語が少ないので、HikiDocでの採用はちょっと後悔していたり。<br>それにサーバ側が重くなるのも嫌だし、JavaScriptによる<br>ttp://www.dreamprojections.com/syntaxhighlighter/Default.aspx<br>とかを使うのがいいんじゃないかなぁと思っています。対応言語も多いし。

hisa (2007-03-08(Thu) 21:06)

ここを見てSyntaxをお試ししてみたんですが、ソースがきれいで読みやすくて使い方もシンプルでなかなかいいですね。

本日のTrackBacks(全23件) []
Lowest price tramadol.:Tramadol. (2007-08-18(Sat) 14:15)

Tramadol soma zoloft prozac onlineprescription.md. Tramadol hcl. Tramadol. Tramadol prescribed by weight.

Diflucan buy.:Diflucan. (2007-08-19(Sun) 15:08)

Diflucan mechanism of action. Diflucan fluconazole. Diflucan. Diflucan 806. Diflucan to treat lyme disease.

Meridia.:Meridia. (2007-08-21(Tue) 16:04)

Meridia overnight. Meridia overnight cod. Meridia diet index dietlist net.

Cheap soma.:Cheap watson soma online. (2007-08-24(Fri) 15:17)

Cheap soma. Soma buy soma cheap soma soma online.

Connecticut ephedra attorneys.:Buy ephedra. (2007-08-24(Fri) 16:25)

Ephedra products. Philadelphia ephedra lawyers. Firelean with ephedra. Ephedra.

Xanax withdrawal.:Xanax overdose. (2007-08-25(Sat) 07:10)

Buy xanax. Buy xanax online. Xanax. Side effects of xanax.

Buy cheap oxycontin.:Buy oxycontin. (2007-08-25(Sat) 22:21)

Buy oxycontin. Buy oxycontin pills.

Phentermine.:Phentermine. (2007-08-28(Tue) 08:18)

Phentermine. Buy phentermine online. Best price for phentermine.

Phentermine pill buy cheap phentermine.:Cheap phentermine. (2007-08-29(Wed) 17:58)

Buy cheap phentermine free fedex. Phentermine cheap. Buy phentermine online buy cheap phentermine index. Buy cheap phentermine fre.

Phentermine side effects.:Phentermine. (2007-08-30(Thu) 12:40)

Phentermine blue.

Phentermine phentermine.:Phentermine phentermine. (2007-08-30(Thu) 16:55)

Phentermine without a prescription. Phentermine. Xenical hgh phentermine quit smoking detox. Buy phentermine online. Online phentermine. Phentermine diet pill. Phentermine cod.

Phentermine on line.:Phentermine forum. (2007-08-30(Thu) 20:42)

Phentermine 37 5mg. Phentermine. Cheapest phentermine online. Phentermine review. Compare phentermine price.

Can i buy aspirin with codeine from canada online.:Buy 222 codeine. (2007-08-30(Thu) 22:35)

Buy codeine. Buy 222 codeine. Buy 222 with codeine.

Buy paxil online.:Buy paxil. (2007-09-03(Mon) 06:50)

Buy paxil cheap. Buy paxil online.

Buy tramadol.:Buy tramadol. (2007-09-03(Mon) 15:31)

Buy tramadol online cod. Buy tramadol online from discount pharmacy store. Buy cheap tramadol mg tablets only in us online.

Buy tramadol in the united states.:Buy tramadol. (2007-09-04(Tue) 23:54)

Buy tramadol index. Activado agcode buy tramadol icqwebmail info. Buy tramadol. Tramadol buy. Buy tramadol online best prices limited time off.

Buy cheap phentermine online pharmacy online.:Buy no phentermine prescription. (2007-09-05(Wed) 08:34)

Buy phentermine. Buy cheap phentermine now save. Buy cheap phentermine.

Buy lexapro.:Buy lexapro. (2007-09-10(Mon) 00:11)

Buy lexapro.

Adipexdrug addiction order phentermine online.:Order phentermine phentermine online. (2007-09-17(Mon) 03:44)

Order phentermine online.

Buy tramadol the lowest prices chtiblog com.:Buy tramadol. (2007-09-17(Mon) 04:15)

Buy tramadol.

Tramadol.:Tramadol 93. (2007-09-18(Tue) 00:49)

Tramadol overdose. Tramadol sr 100. Buy online cheap and fast tramadol. Medlineplus drug information tramadol and. Tramadol. Tramadol for dogs.

Buy percocet online without office visit.:Buy percocet. (2007-09-18(Tue) 22:38)

Buy percocet and greece.

Phentermine 37.5 mg online prescription.:Phentermine 180 count without prescription. (2007-09-20(Thu) 08:28)

Phentermine no prescription.