Skip to content

Instantly share code, notes, and snippets.

@akiym
Created March 31, 2011 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akiym/896527 to your computer and use it in GitHub Desktop.
Save akiym/896527 to your computer and use it in GitHub Desktop.
preview Markdown in real-time.
use Mojolicious::Lite;
use Text::Markdown qw/markdown/;
get '/' => sub {
my $self = shift;
$self->render('index');
};
get '/markdown' => sub {
my $self = shift;
my $text = $self->param('q') || '';
my $html = markdown($text);
$self->render(text => $html);
};
app->start;
__DATA__
@@ markdown.js
$(function () {
$('#markdown').focus().keyup(function () {
var text = $(this).val();
$.ajax({
url: '/markdown',
data: {q: text},
success: function (html) {
$('#preview').html(html);
}
});
});
});
@@ markdown.css
textarea {
width: 100%;
height: 250px;
}
#preview {
color: #333;
}
@@ index.html.ep
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>markdown.pl</title>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="markdown.js"></script>
<link rel="stylesheet" type="text/css" href="markdown.css" />
</head>
<body>
<textarea id="markdown"></textarea>
<div id="preview"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment