Remove dependency on Redcarpet
Now Gollum does all its Markdown processing through GitHub::Markup; if you require a custom Markdown renderer using Redcarpet or another library, you can hot-load it from your own code base: Gollum::Wiki.markup_classes[:markdown] = YourRedcarpetRenderer
This commit is contained in:
@@ -433,51 +433,4 @@ module Gollum
|
|||||||
def update_cache(type, id, data)
|
def update_cache(type, id, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
|
||||||
require 'redcarpet'
|
|
||||||
|
|
||||||
class MarkupGFM < Markup
|
|
||||||
def render(no_follow = false)
|
|
||||||
sanitize = no_follow ?
|
|
||||||
@wiki.history_sanitizer :
|
|
||||||
@wiki.sanitizer
|
|
||||||
|
|
||||||
data = extract_tex(@data.dup)
|
|
||||||
data = extract_code(data)
|
|
||||||
data = extract_tags(data)
|
|
||||||
|
|
||||||
flags = [
|
|
||||||
:autolink,
|
|
||||||
:fenced_code,
|
|
||||||
:tables,
|
|
||||||
:strikethrough,
|
|
||||||
:lax_htmlblock,
|
|
||||||
:no_intraemphasis
|
|
||||||
]
|
|
||||||
data = Redcarpet.new(data, *flags).to_html
|
|
||||||
data = process_tags(data)
|
|
||||||
data = process_code(data)
|
|
||||||
|
|
||||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
|
||||||
|
|
||||||
doc.search('pre').each do |node|
|
|
||||||
next unless lang = node['lang']
|
|
||||||
next unless lexer = Pygments::Lexer[lang]
|
|
||||||
text = node.inner_text
|
|
||||||
html = lexer.highlight(text)
|
|
||||||
node.replace(html)
|
|
||||||
end
|
|
||||||
|
|
||||||
doc = sanitize.clean_node!(doc) if sanitize
|
|
||||||
yield doc if block_given?
|
|
||||||
|
|
||||||
data = doc_to_html(doc)
|
|
||||||
data = process_tex(data)
|
|
||||||
data
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue LoadError
|
|
||||||
MarkupGFM = Markup
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
+7
-9
@@ -54,32 +54,30 @@ module Gollum
|
|||||||
# Gets the markup class used by all instances of this Wiki.
|
# Gets the markup class used by all instances of this Wiki.
|
||||||
# Default: Gollum::Markup
|
# Default: Gollum::Markup
|
||||||
def markup_classes
|
def markup_classes
|
||||||
@markup_classes ||
|
@markup_classes ||=
|
||||||
if superclass.respond_to?(:markup_classes)
|
if superclass.respond_to?(:markup_classes)
|
||||||
superclass.markup_classes
|
superclass.markup_classes
|
||||||
else
|
else
|
||||||
classes = Hash.new(::Gollum::Markup)
|
Hash.new(::Gollum::Markup)
|
||||||
|
|
||||||
# Add custom markup classes for different languages
|
|
||||||
classes[:markdown] = ::Gollum::MarkupGFM
|
|
||||||
classes
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Gets the default markup class used by all instances of this Wiki.
|
# Gets the default markup class used by all instances of this Wiki.
|
||||||
# Kept for backwards compatibility until Gollum v2.x
|
# Kept for backwards compatibility until Gollum v2.x
|
||||||
def markup_class
|
def markup_class(language=:default)
|
||||||
markup_classes[:default]
|
markup_classes[language]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the default markup class used by all instances of this Wiki.
|
# Sets the default markup class used by all instances of this Wiki.
|
||||||
# Kept for backwards compatibility until Gollum v2.x
|
# Kept for backwards compatibility until Gollum v2.x
|
||||||
def markup_class=(default)
|
def markup_class=(default)
|
||||||
new_classes = Hash.new default
|
|
||||||
@markup_classes = Hash.new(default).update(markup_classes)
|
@markup_classes = Hash.new(default).update(markup_classes)
|
||||||
default
|
default
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :default_markup_class, :markup_class
|
||||||
|
alias_method :default_markup_class=, :markup_class=
|
||||||
|
|
||||||
# Gets the default sanitization options for current pages used by
|
# Gets the default sanitization options for current pages used by
|
||||||
# instances of this Wiki.
|
# instances of this Wiki.
|
||||||
def sanitization
|
def sanitization
|
||||||
|
|||||||
+8
-4
@@ -11,13 +11,17 @@ context "Wiki" do
|
|||||||
assert_equal Gollum::Markup, Gollum::Wiki.markup_class
|
assert_equal Gollum::Markup, Gollum::Wiki.markup_class
|
||||||
end
|
end
|
||||||
|
|
||||||
test "#markup_class= doesn't clobber alternate markups" do
|
test "#default_markup_class= doesn't clobber alternate markups" do
|
||||||
custom = Class.new(Gollum::Markup)
|
custom = Class.new(Gollum::Markup)
|
||||||
Gollum::Wiki.markup_class = custom
|
custom_md = Class.new(Gollum::Markup)
|
||||||
|
|
||||||
assert_equal custom, Gollum::Wiki.markup_class
|
Gollum::Wiki.markup_classes = Hash.new Gollum::Markup
|
||||||
|
Gollum::Wiki.markup_classes[:markdown] = custom_md
|
||||||
|
Gollum::Wiki.default_markup_class = custom
|
||||||
|
|
||||||
|
assert_equal custom, Gollum::Wiki.default_markup_class
|
||||||
assert_equal custom, Gollum::Wiki.markup_classes[:orgmode]
|
assert_equal custom, Gollum::Wiki.markup_classes[:orgmode]
|
||||||
assert_equal Gollum::MarkupGFM, Gollum::Wiki.markup_classes[:markdown]
|
assert_equal custom_md, Gollum::Wiki.markup_classes[:markdown]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "repo path" do
|
test "repo path" do
|
||||||
|
|||||||
Reference in New Issue
Block a user