diff --git a/Gemfile b/Gemfile index fe867854..430c4222 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,4 @@ source "http://rubygems.org" gemspec gem "rake", "~> 0.9.2" +gem "grit", :git => "git://github.com/mojombo/grit.git" diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 59f51a22..16cc2399 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -28,9 +28,10 @@ module Gollum # # no_follow - Boolean that determines if rel="nofollow" is added to all # 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 = %{

#{e.message}

} 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) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index a794ff1d..ac3e0294 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -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. diff --git a/test/test_markup.rb b/test/test_markup.rb index 559929e4..f788682e 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -421,7 +421,21 @@ context "Markup" do " 2\n\n\n\n\n

b

" compare(content, output) end - + + test "code blocks with multibyte caracters indent" do + content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb" + output = "

a

\n\n
" +
+             "s = 'やくしまるえつこ'" +
+             "\n
\n
\n\n\n

b

" + 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