Skip to content

Instantly share code, notes, and snippets.

@syohex
Created October 6, 2011 07:30
Show Gist options
  • Save syohex/1266755 to your computer and use it in GitHub Desktop.
Save syohex/1266755 to your computer and use it in GitHub Desktop.
カレントディレクトリ以下の Markdown形式のファイルを HTMLに変換する
#!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