Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ddaffd3

Browse files
committed
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.
1 parent 92fb3cd commit ddaffd3

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/github/markup.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def render(filename, content = nil)
2222
def markup(file, pattern, &block)
2323
require file.to_s
2424
add_markup(pattern, &block)
25+
true
2526
rescue LoadError
26-
nil
27+
false
2728
end
2829

2930
def command(command, regexp, &block)

lib/github/markup/rdoc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "rdoc"
12
require "rdoc/markup/to_html"
23

34
module GitHub

lib/github/markups.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
markup(:markdown, /md|mkdn?|mdown|markdown/) do |content|
2-
Markdown.new(content).to_html
1+
MD_FILES = /md|mkdn?|mdown|markdown/
2+
3+
if markup(:redcarpet, MD_FILES) do |content|
4+
RedcarpetCompat.new(content).to_html
5+
end
6+
elsif markup(:rdiscount, MD_FILES) do |content|
7+
RDiscount.new(content).to_html
8+
end
9+
elsif markup(:maruku, MD_FILES) do |content|
10+
Maruku.new(content).to_html
11+
end
12+
elsif markup(:kramdown, MD_FILES) do |content|
13+
Kramdown::Document.new(content).to_html
14+
end
15+
elsif markup(:bluecloth, MD_FILES) do |content|
16+
BlueCloth.new(content).to_html
17+
end
318
end
419

520
markup(:redcloth, /textile/) do |content|

0 commit comments

Comments
 (0)