Created
October 6, 2011 07:30
-
-
Save syohex/1266755 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
#!perl | |
use strict; | |
use warnings; | |
use File::Find; | |
use File::Basename; | |
use Text::Markdown qw(markdown); | |
find(\&md2html, '.'); | |
sub md2html { | |
my $path = basename($File::Find::name); | |
return unless defined $path && $path =~ m{\.md$}; | |
my $md_text = do { | |
local $/; | |
open my $fh, '<', $path or die "Can't open $path: $!"; | |
<$fh>; | |
}; | |
my $html = markdown($md_text); | |
(my $output = $path) =~ s{\.md$}{.html}; | |
open my $fh, '>', $output or die "Can't open $output: $!"; | |
print {$fh} $html; | |
close $fh; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment