Skip to content

Instantly share code, notes, and snippets.

@ParkinT
Forked from emad-elsaid/markdown.rb
Last active August 29, 2015 13:57
Show Gist options
  • Save ParkinT/9865733 to your computer and use it in GitHub Desktop.
Save ParkinT/9865733 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# gem install sinatra --no-document
# gem install github-markdown --no-document
# usage: ruby markedown.rb then, in Nitrous, simply select 'Preview -> Port 3000' on the menu
require 'sinatra'
require 'github/markdown'
# Set port for compatability with Nitrous.IO
configure :development do
set :bind, '0.0.0.0'
set :port, 3000 # Not really needed, but works well with the "Preview" menu option
end
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment