Skip to content

Instantly share code, notes, and snippets.

@jberger
Created February 25, 2020 20:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/0009fafb7b3b81798d122fdd2bcfdd44 to your computer and use it in GitHub Desktop.
Save jberger/0009fafb7b3b81798d122fdd2bcfdd44 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite -signatures;
use CommonMark;
# server markdown from markdown/ within app's home
my $root = app->home->child('markdown');
get '/*file' => sub ($c) {
#TODO handle traversal attacks
my $path = $root->child($c->stash('file'));
return $c->reply->not_found
unless -f $path;
$c->render(
text => CommonMark->markdown_to_html($path->slurp),
format => 'html',
);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment