provide access to the parsed Nokogiri document fragment when rendering marked up content.
This commit is contained in:
@@ -44,7 +44,12 @@ module Gollum
|
||||
end
|
||||
data = process_tags(data)
|
||||
data = process_code(data)
|
||||
data = sanitize.clean!(data) if sanitize
|
||||
if sanitize || block_given?
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
doc = sanitize.clean_node!(doc) if sanitize
|
||||
yield doc if block_given?
|
||||
data = doc_to_html(doc)
|
||||
end
|
||||
data = process_tex(data)
|
||||
data.gsub!(/<p><\/p>/, '')
|
||||
data
|
||||
|
||||
+2
-2
@@ -132,8 +132,8 @@ module Gollum
|
||||
# Public: The formatted contents of the page.
|
||||
#
|
||||
# Returns the String data.
|
||||
def formatted_data
|
||||
@blob && @wiki.markup_class.new(self).render(historical?)
|
||||
def formatted_data(&block)
|
||||
@blob && @wiki.markup_class.new(self).render(historical?, &block)
|
||||
end
|
||||
|
||||
# Public: The format of the page.
|
||||
|
||||
@@ -25,6 +25,31 @@ context "Markup" do
|
||||
end
|
||||
end
|
||||
|
||||
test "Gollum::Markup#render yields a DocumentFragment" do
|
||||
yielded = false
|
||||
@wiki.write_page("Yielded", :markdown, "abc", commit_details)
|
||||
|
||||
page = @wiki.page("Yielded")
|
||||
markup = Gollum::Markup.new(page)
|
||||
markup.render do |doc|
|
||||
assert_kind_of Nokogiri::HTML::DocumentFragment, doc
|
||||
yielded = true
|
||||
end
|
||||
assert yielded
|
||||
end
|
||||
|
||||
test "Gollum::Page#formatted_data yields a DocumentFragment" do
|
||||
yielded = false
|
||||
@wiki.write_page("Yielded", :markdown, "abc", commit_details)
|
||||
|
||||
page = @wiki.page("Yielded")
|
||||
page.formatted_data do |doc|
|
||||
assert_kind_of Nokogiri::HTML::DocumentFragment, doc
|
||||
yielded = true
|
||||
end
|
||||
assert yielded
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Links
|
||||
|
||||
Reference in New Issue
Block a user