Created
April 11, 2014 14:00
-
-
Save plukevdh/10471333 to your computer and use it in GitHub Desktop.
simple markdown switcher for jruby vs mri
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
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