Skip to content

Instantly share code, notes, and snippets.

@rrotter
Created June 19, 2015 22:27
Show Gist options
  • Save rrotter/69d885eb45ffe2f0f4ff to your computer and use it in GitHub Desktop.
Save rrotter/69d885eb45ffe2f0f4ff to your computer and use it in GitHub Desktop.
Add github-markdown support to Tilt (and thus Sinatra and others).
# usage:
# set :gfm => true to enable GitHub Flavored Markdown mode
require 'tilt/template'
require 'github/markdown'
module Tilt
class GitHubTemplate < Template
self.default_mime_type = 'text/html'
def prepare
@engine = nil
if options[:gfm]
@output = GitHub::Markdown.render_gfm(data)
else
@output = GitHub::Markdown.render(data)
end
end
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
def allows_script?
false
end
end
end
require 'github/markdown'
require './github-markdown'
module Tilt
register_lazy :GitHubTemplate, './github-markdown', 'markdown', 'mkd', 'md'
end
#...
get '/readme' do
markdown :README
end
get '/readme/gfm' do
markdown :README, :gfm => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment