Created
October 12, 2012 11:19
-
-
Save junichiro/3878760 to your computer and use it in GitHub Desktop.
markdown でhtml化してファイル保存し、それをブラウザに表示する
This file contains hidden or 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
use strict; | |
use warnings; | |
use Path::Class; | |
use Text::Markdown 'markdown'; | |
my $file = file(join(' ', @ARGV)); | |
exit if ( $file->stringify !~ m|\.md$| ); | |
my $target_file = file(get_target_file_name($file)); | |
my $text = $file->slurp; | |
my $html = markdown($text); | |
my $fh = $target_file->openw(); | |
my $template = join(q//, <DATA>); | |
print $fh sprintf($template, $html); | |
exec(sprintf("open %s", escape_file_name($target_file))); | |
sub get_target_file_name { | |
my $file_name = shift; | |
$file_name =~ s/\.md$/.html/; | |
return $file_name; | |
} | |
sub escape_file_name { | |
my $file_name = shift; | |
$file_name =~ s/\s/\\ /msgx;; | |
return $file_name; | |
} | |
__DATA__ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf8"> | |
<style type="text/css"> | |
body { | |
background-color: #F7F2E6; | |
} | |
strong { | |
color: #C00010; | |
} | |
</style> | |
</head> | |
<body style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 15px; word-wrap: break-word; margin: 10px auto 0px auto; width: 625px; position: relative; color: #403929;"> | |
%s | |
</body> | |
</html> |
instapaper 風になるようなcss を追記
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
emacs でmarkdown 形式のファイルを書いているときに、lisp 経由で呼び出す