Last Updated: February 25, 2016
·
1.51K
· blazeeboy

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

1 Response
Add your response

May I humbly suggest Mou

over 1 year ago ·