Burn `require 'markdown'` with the fire of a thousand suns GitHub::Markup now has an actual preference order for Markdown libraries, tries to require them explicitly and use their actual APIs instead of the compatibility 'Markdown' layer. Redcarpet is the default library, and the one listed in the Gemfile. If it's not available, the (opinionated) require order is: - Redcarpet - RDiscount - Maruku - Kramdown - BlueCloth This soothes my soul.
Vicent Marti tanoku@gmail.com
Wed, 07 Dec 2011 13:19:50 +0100
3 files changed,
20 insertions(+),
3 deletions(-)
M
lib/github/markup.rb
→
lib/github/markup.rb
@@ -22,8 +22,9 @@
def markup(file, pattern, &block) require file.to_s add_markup(pattern, &block) + true rescue LoadError - nil + false end def command(command, regexp, &block)
M
lib/github/markup/rdoc.rb
→
lib/github/markup/rdoc.rb
@@ -1,3 +1,4 @@
+require "rdoc" require "rdoc/markup/to_html" module GitHub
M
lib/github/markups.rb
→
lib/github/markups.rb
@@ -1,5 +1,20 @@
-markup(:markdown, /md|mkdn?|mdown|markdown/) do |content| - Markdown.new(content).to_html +MD_FILES = /md|mkdn?|mdown|markdown/ + +if markup(:redcarpet, MD_FILES) do |content| + RedcarpetCompat.new(content).to_html + end +elsif markup(:rdiscount, MD_FILES) do |content| + RDiscount.new(content).to_html + end +elsif markup(:maruku, MD_FILES) do |content| + Maruku.new(content).to_html + end +elsif markup(:kramdown, MD_FILES) do |content| + Kramdown::Document.new(content).to_html + end +elsif markup(:bluecloth, MD_FILES) do |content| + BlueCloth.new(content).to_html + end end markup(:redcloth, /textile/) do |content|