Markdown Preview using ruby and sinatra simple script
every time i write markdown in my readme file i have to write something wrong, so i wrote this script to solve my problem
#!/usr/bin/env ruby
# gem install sinatra --no-document
# gem install github-markdown --no-document
require 'sinatra'
require 'github/markdown'
set :port, 3000
get '/' do
<<-EOT
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Markdown tester</title>
</head>
<body>
<textarea id="markdown" style="width:100%;height:300px;"></textarea>
<div id="preview" ></div>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$('#markdown').keyup(function(){
$.post('/preview', {md:$('#markdown').val()}, function(response){
$('#preview').html(response);
});
});
</script>
</body>
</html>
EOT
end
post '/preview' do
GitHub::Markdown.render_gfm params['md']
end
Written by Emad Elsaid
Related protips
1 Response
May I humbly suggest Mou
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#