Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created March 30, 2010 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestrrat/348721 to your computer and use it in GitHub Desktop.
Save lestrrat/348721 to your computer and use it in GitHub Desktop.
use strict;
use File::Spec;
use Text::MultiMarkdown 'markdown';
sub wrap_markdown {
my ($markdown) = @_;
my $output = <<EOM;
<html>
<head>
<style type="text/css">
<!--
body {
font-family: Halvetica, sans-serif;
padding-left: 2em;
}
pre { padding-left: 2em }
-->
</style>
</head>
<body>
EOM
$output .= $markdown;
$output .= <<EOM;
</body>
</html>
EOM
}
sub {
my $env = shift;
my $file = File::Spec->catfile(
File::Spec->curdir, $env->{PATH_INFO});
open my $fh, '<', $file or die "Failed to open $file: $!";
my $content = do { local $/; <$fh> };
[
200,
[ "Content-Type" => 'text/html; charset=utf-8' ],
[ wrap_markdown( markdown( $content ) ) ]
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment