add encoding option
This commit is contained in:
@@ -2,3 +2,4 @@ source "http://rubygems.org"
|
||||
|
||||
gemspec
|
||||
gem "rake", "~> 0.9.2"
|
||||
gem "grit", :git => "git://github.com/mojombo/grit.git"
|
||||
|
||||
+10
-7
@@ -28,9 +28,10 @@ module Gollum
|
||||
#
|
||||
# no_follow - Boolean that determines if rel="nofollow" is added to all
|
||||
# <a> tags.
|
||||
# encoding - Encoding Constant or String.
|
||||
#
|
||||
# Returns the formatted String content.
|
||||
def render(no_follow = false)
|
||||
def render(no_follow = false, encoding = nil)
|
||||
sanitize = no_follow ?
|
||||
@wiki.history_sanitizer :
|
||||
@wiki.sanitizer
|
||||
@@ -47,7 +48,7 @@ module Gollum
|
||||
data = %{<p class="gollum-error">#{e.message}</p>}
|
||||
end
|
||||
data = process_tags(data)
|
||||
data = process_code(data)
|
||||
data = process_code(data, encoding)
|
||||
if sanitize || block_given?
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
doc = sanitize.clean_node!(doc) if sanitize
|
||||
@@ -380,10 +381,11 @@ module Gollum
|
||||
# Process all code from the codemap and replace the placeholders with the
|
||||
# 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.
|
||||
def process_code(data)
|
||||
def process_code(data, encoding = nil)
|
||||
return data if data.nil? || data.size.zero? || @codemap.size.zero?
|
||||
|
||||
blocks = []
|
||||
@@ -399,7 +401,8 @@ module Gollum
|
||||
end
|
||||
|
||||
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
|
||||
[]
|
||||
end
|
||||
@@ -443,7 +446,7 @@ module Gollum
|
||||
require 'redcarpet'
|
||||
|
||||
class MarkupGFM < Markup
|
||||
def render(no_follow = false)
|
||||
def render(no_follow = false, encoding = nil)
|
||||
sanitize = no_follow ?
|
||||
@wiki.history_sanitizer :
|
||||
@wiki.sanitizer
|
||||
@@ -462,7 +465,7 @@ module Gollum
|
||||
]
|
||||
data = Redcarpet.new(data, *flags).to_html
|
||||
data = process_tags(data)
|
||||
data = process_code(data)
|
||||
data = process_code(data, encoding)
|
||||
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
|
||||
|
||||
+4
-2
@@ -166,9 +166,11 @@ module Gollum
|
||||
|
||||
# Public: The formatted contents of the page.
|
||||
#
|
||||
# encoding - Encoding Constant or String.
|
||||
#
|
||||
# Returns the String data.
|
||||
def formatted_data(&block)
|
||||
@blob && markup_class.render(historical?, &block)
|
||||
def formatted_data(encoding = nil, &block)
|
||||
@blob && markup_class.render(historical?, encoding, &block)
|
||||
end
|
||||
|
||||
# Public: The format of the page.
|
||||
|
||||
+15
-1
@@ -421,7 +421,21 @@ context "Markup" do
|
||||
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
|
||||
compare(content, output)
|
||||
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
|
||||
content = <<-END
|
||||
booya
|
||||
|
||||
Reference in New Issue
Block a user