lib/indexer/importer/markdown.rb in indexer-0.1.0 vs lib/indexer/importer/markdown.rb in indexer-0.2.0
- old
+ new
@@ -23,17 +23,35 @@
#
# Import metadata from HTML file.
#
def load_markdown(file)
require 'nokogiri'
- require 'redcarpet'
+ text = File.read(file)
+
+ begin
+ require 'redcarpet'
+ html = render_with_redcarpet(text)
+ rescue LoadError
+ require 'kramdown'
+ html = render_with_kramdown(text)
+ end
+
+ doc = Nokogiri::HTML(html)
+
+ load_html(doc)
+ end
+
+ #
+ def render_with_redcarpet(text)
renderer = Redcarpet::Render::HTML.new()
markdown = Redcarpet::Markdown.new(renderer, :autolink=>true, :tables=>true, :space_after_headers=>true)
- html = markdown.render(File.read(file))
- doc = Nokogiri::HTML(html)
+ markdown.render(text)
+ end
- load_html(doc)
+ #
+ def render_with_kramdown(text)
+ Kramdown::Document.new(text).to_html
end
end
# Include mixin into Importer class.