-
-
Save ParkinT/9865733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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