add encoding option
This commit is contained in:
@@ -2,3 +2,4 @@ source "http://rubygems.org"
|
|||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
gem "rake", "~> 0.9.2"
|
gem "rake", "~> 0.9.2"
|
||||||
|
gem "grit", :git => "git://github.com/mojombo/grit.git"
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# no_follow - Boolean that determines if rel="nofollow" is added to all
|
# no_follow - Boolean that determines if rel="nofollow" is added to all
|
||||||
# <a> tags.
|
# <a> tags.
|
||||||
|
# encoding - Encoding Constant or String.
|
||||||
#
|
#
|
||||||
# Returns the formatted String content.
|
# Returns the formatted String content.
|
||||||
def render(no_follow = false)
|
def render(no_follow = false, encoding = nil)
|
||||||
sanitize = no_follow ?
|
sanitize = no_follow ?
|
||||||
@wiki.history_sanitizer :
|
@wiki.history_sanitizer :
|
||||||
@wiki.sanitizer
|
@wiki.sanitizer
|
||||||
@@ -47,7 +48,7 @@ module Gollum
|
|||||||
data = %{<p class="gollum-error">#{e.message}</p>}
|
data = %{<p class="gollum-error">#{e.message}</p>}
|
||||||
end
|
end
|
||||||
data = process_tags(data)
|
data = process_tags(data)
|
||||||
data = process_code(data)
|
data = process_code(data, encoding)
|
||||||
if sanitize || block_given?
|
if sanitize || block_given?
|
||||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||||
doc = sanitize.clean_node!(doc) if sanitize
|
doc = sanitize.clean_node!(doc) if sanitize
|
||||||
@@ -381,9 +382,10 @@ module Gollum
|
|||||||
# final HTML.
|
# final HTML.
|
||||||
#
|
#
|
||||||
# data - The String data (with placeholders).
|
# data - The String data (with placeholders).
|
||||||
|
# encoding - Encoding Constant or String.
|
||||||
#
|
#
|
||||||
# Returns the marked up String data.
|
# Returns the marked up String data.
|
||||||
def process_code(data)
|
def process_code(data, encoding = nil)
|
||||||
return data if data.nil? || data.size.zero? || @codemap.size.zero?
|
return data if data.nil? || data.size.zero? || @codemap.size.zero?
|
||||||
|
|
||||||
blocks = []
|
blocks = []
|
||||||
@@ -399,7 +401,8 @@ module Gollum
|
|||||||
end
|
end
|
||||||
|
|
||||||
highlighted = begin
|
highlighted = begin
|
||||||
blocks.map { |lang, code| Pygments.highlight(code, :lexer => lang) }
|
encoding ||= Encoding::UTF_8
|
||||||
|
blocks.map { |lang, code| Pygments.highlight(code, :lexer => lang, :options => {:encoding => encoding.to_s}) }
|
||||||
rescue ::RubyPython::PythonError
|
rescue ::RubyPython::PythonError
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
@@ -443,7 +446,7 @@ module Gollum
|
|||||||
require 'redcarpet'
|
require 'redcarpet'
|
||||||
|
|
||||||
class MarkupGFM < Markup
|
class MarkupGFM < Markup
|
||||||
def render(no_follow = false)
|
def render(no_follow = false, encoding = nil)
|
||||||
sanitize = no_follow ?
|
sanitize = no_follow ?
|
||||||
@wiki.history_sanitizer :
|
@wiki.history_sanitizer :
|
||||||
@wiki.sanitizer
|
@wiki.sanitizer
|
||||||
@@ -462,7 +465,7 @@ module Gollum
|
|||||||
]
|
]
|
||||||
data = Redcarpet.new(data, *flags).to_html
|
data = Redcarpet.new(data, *flags).to_html
|
||||||
data = process_tags(data)
|
data = process_tags(data)
|
||||||
data = process_code(data)
|
data = process_code(data, encoding)
|
||||||
|
|
||||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -166,9 +166,11 @@ module Gollum
|
|||||||
|
|
||||||
# Public: The formatted contents of the page.
|
# Public: The formatted contents of the page.
|
||||||
#
|
#
|
||||||
|
# encoding - Encoding Constant or String.
|
||||||
|
#
|
||||||
# Returns the String data.
|
# Returns the String data.
|
||||||
def formatted_data(&block)
|
def formatted_data(encoding = nil, &block)
|
||||||
@blob && markup_class.render(historical?, &block)
|
@blob && markup_class.render(historical?, encoding, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: The format of the page.
|
# Public: The format of the page.
|
||||||
|
|||||||
@@ -422,6 +422,20 @@ context "Markup" do
|
|||||||
compare(content, output)
|
compare(content, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "code blocks with multibyte caracters indent" do
|
||||||
|
content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb"
|
||||||
|
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
|
||||||
|
"s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'" +
|
||||||
|
"</span>\n</pre>\n</div>\n\n\n<p>b</p>"
|
||||||
|
index = @wiki.repo.index
|
||||||
|
index.add("Bilbo-Baggins.md", content)
|
||||||
|
index.commit("Add alpha.jpg")
|
||||||
|
|
||||||
|
page = @wiki.page("Bilbo Baggins")
|
||||||
|
rendered = Gollum::Markup.new(page).render(false, Encoding::UTF_8)
|
||||||
|
assert_equal output, rendered
|
||||||
|
end
|
||||||
|
|
||||||
test "code with wiki links" do
|
test "code with wiki links" do
|
||||||
content = <<-END
|
content = <<-END
|
||||||
booya
|
booya
|
||||||
|
|||||||
Reference in New Issue
Block a user