Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Created April 11, 2014 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plukevdh/10471333 to your computer and use it in GitHub Desktop.
Save plukevdh/10471333 to your computer and use it in GitHub Desktop.
simple markdown switcher for jruby vs mri
if RUBY_PLATFORM == 'java'
require 'kramdown'
TYPE = Kramdown
else
require 'redcarpet'
TYPE = Redcarpet
end
class MarkdownRenderer
def initialize(type=TYPE)
@parser = Object.const_get("MarkdownRenderer::#{type}").new
end
def render_file(path)
@parser.render File.read(path)
end
def render(markdown)
@parser.render(markdown)
end
class Kramdown
def render(markdown)
::Kramdown::Document.new(markdown).to_html
end
end
class Redcarpet
def initialize
@renderer = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML, autolink: true, space_after_headers: true)
end
def render(markdown)
@renderer.render(markdown)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment