Instantly share code, notes, and snippets.

Embed
What would you like to do?
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