■textileを使おう!
いえmarkdownの方が好みなのですが会社でRedmineを使っているので、ドキュメントはtextileで書いておけばそれをコピペするだけでチケットに綺麗に書けるわけです。この書きためたtextileをローカル閲覧する際にHTMLで見れる環境を構築しました。
vim-quickrun+openbrowser.vimで開くとかApache使わないでinvisible.js使ったり色々模索してますがこれはそのうちの1つです。ちなみにこのBloggerはmarkdownで書いてます。
■Apacheを導入
とりあえずWindows向けのApacheをインストールします。
■PHPをインストール
PHPを使うのでインストールしておきます。
■httpd.confの編集
textileのTypeとActionを追加しておきます。(要mod_action)
AddType text/textile textile
Action text/textile /lib/tt.php
conf読み直しのためにApacheを再起動。
■Parserをlibにつっこみます
- http://textile.thresholdstate.com/からDLした純正パーサーをlibに突っ込みます。
- Actionに指定したtt.phpをlibに突っ込みます This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
<?php require_once 'classTextile.php'; if ( isset($_SERVER['PATH_TRANSLATED']) ) { $file = realpath($_SERVER['PATH_TRANSLATED']); $ext = substr($file, strrpos($file, '.') + 1); } if ( $file and is_readable($file) and $ext === 'textile') { $textile = new Textile(); $body = $textile->TextileThis(file_get_contents($file)); } else { $body = '<p>cannot read file</p>'; } header('Content-Type: text/html;'); echo '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> ' . $body . ' </body> </html> '; - 完成!
これで拡張子が.textileのtextile記法のファイルをtextileディレクトリにでも突っ込んでブラウザでlocalhost/textile/hoge.textileとかアクセスすればHTMLで表示されるよ!
cssなしの生htmlもなんなので、会社ではtt.phpで生成しているhtmlにcssをリンクさせて表示させてます。 丸々参考にさせてもらったFenrir川端さんのGitHub のように、Markdown ファイルを HTML として表示したいに感謝。