Skip to content

Instantly share code, notes, and snippets.

@junichiro
Created October 12, 2012 11:19
Show Gist options
  • Save junichiro/3878760 to your computer and use it in GitHub Desktop.
Save junichiro/3878760 to your computer and use it in GitHub Desktop.
markdown でhtml化してファイル保存し、それをブラウザに表示する
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>
@junichiro
Copy link
Author

emacs でmarkdown 形式のファイルを書いているときに、lisp 経由で呼び出す

@junichiro
Copy link
Author

instapaper 風になるようなcss を追記

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment