From 776df4e6eefbde0640ee4d8ba62c6ab693fafeda Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sat, 27 Oct 2012 18:22:43 -0600 Subject: [PATCH] Fix nokogiri rendering https://github.com/sparklemotion/nokogiri/issues/782 --- lib/gollum.rb | 1 + lib/gollum/blob_entry.rb | 1 + lib/gollum/committer.rb | 1 + lib/gollum/file.rb | 1 + lib/gollum/file_view.rb | 1 + lib/gollum/frontend/app.rb | 1 + lib/gollum/frontend/helpers.rb | 1 + lib/gollum/git_access.rb | 1 + lib/gollum/gitcode.rb | 1 + lib/gollum/markup.rb | 13 ++++++------ lib/gollum/page.rb | 1 + lib/gollum/pagination.rb | 3 ++- lib/gollum/sanitization.rb | 1 + lib/gollum/web_sequence_diagram.rb | 1 + lib/gollum/wiki.rb | 1 + test/test_gitcode.rb | 2 +- test/test_markup.rb | 32 ++++++++++++++++-------------- 17 files changed, 39 insertions(+), 24 deletions(-) diff --git a/lib/gollum.rb b/lib/gollum.rb index bee1a4e2..4ebddd53 100644 --- a/lib/gollum.rb +++ b/lib/gollum.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ # stdlib require 'digest/md5' require 'ostruct' diff --git a/lib/gollum/blob_entry.rb b/lib/gollum/blob_entry.rb index 102a095e..6ce8ac6a 100644 --- a/lib/gollum/blob_entry.rb +++ b/lib/gollum/blob_entry.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum class BlobEntry # Gets the String SHA for this blob. diff --git a/lib/gollum/committer.rb b/lib/gollum/committer.rb index 85779e8a..3a1e13da 100644 --- a/lib/gollum/committer.rb +++ b/lib/gollum/committer.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum # Responsible for handling the commit process for a Wiki. It sets up the # Git index, provides methods for modifying the tree, and stores callbacks diff --git a/lib/gollum/file.rb b/lib/gollum/file.rb index f9a5e754..e893e9e2 100644 --- a/lib/gollum/file.rb +++ b/lib/gollum/file.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum class File Wiki.file_class = self diff --git a/lib/gollum/file_view.rb b/lib/gollum/file_view.rb index 69002907..cf88dea4 100644 --- a/lib/gollum/file_view.rb +++ b/lib/gollum/file_view.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum =begin FileView requires that: diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 7a987322..e7885011 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ require 'cgi' require 'sinatra' require 'gollum' diff --git a/lib/gollum/frontend/helpers.rb b/lib/gollum/frontend/helpers.rb index 7ae0381a..94c2b140 100644 --- a/lib/gollum/frontend/helpers.rb +++ b/lib/gollum/frontend/helpers.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Precious module Helpers # Extract the path string that Gollum::Wiki expects diff --git a/lib/gollum/git_access.rb b/lib/gollum/git_access.rb index 81213f04..333ac69a 100644 --- a/lib/gollum/git_access.rb +++ b/lib/gollum/git_access.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum # Controls all access to the Git objects from Gollum. Extend this class to # add custom caching for special cases. diff --git a/lib/gollum/gitcode.rb b/lib/gollum/gitcode.rb index a4a8c064..226b345a 100644 --- a/lib/gollum/gitcode.rb +++ b/lib/gollum/gitcode.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ require 'net/http' require 'net/https' # ruby 1.8.7 fix, remove at upgrade require 'uri' diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 9d602bae..f52c2910 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ require 'digest/sha1' require 'cgi' require 'pygments' @@ -74,13 +75,11 @@ module Gollum doc,toc = process_headers(doc) @toc = @sub_page ? ( @parent_page ? @parent_page.toc_data : "[[_TOC_]]" ) : toc yield doc if block_given? - data = doc.to_xhtml(:indent => 0, :encoding => 'UTF-8') - - # fix 4 space indented code blocks introduced by nokogiri. - # tag should not have a newline after it - data.gsub!(/
\s*(.+)<\/code>\s*<\/pre>/m) do
-        "
#{$1}
" - end + # nokogiri's save options are xored together. FORMAT has a value of 1 so ^ 1 removes it. + # formatting will create extra spaces in pre tags. + # https://github.com/sparklemotion/nokogiri/issues/782 + # DEFAULT_HTML encodes unicode so XHTML is used for proper unicode support in href. + data = doc.to_xml( { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' } ) data = process_toc_tags(data) data = process_wsd(data) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index fa825cb5..31ee542a 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum class Page include Pagination diff --git a/lib/gollum/pagination.rb b/lib/gollum/pagination.rb index 8ed2a336..c1f7621d 100644 --- a/lib/gollum/pagination.rb +++ b/lib/gollum/pagination.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum module Pagination def self.included(klass) @@ -58,4 +59,4 @@ module Gollum self.class.log_pagination_options(options) end end -end \ No newline at end of file +end diff --git a/lib/gollum/sanitization.rb b/lib/gollum/sanitization.rb index 5229d8d1..8656cb52 100644 --- a/lib/gollum/sanitization.rb +++ b/lib/gollum/sanitization.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum # Encapsulate sanitization options. # diff --git a/lib/gollum/web_sequence_diagram.rb b/lib/gollum/web_sequence_diagram.rb index fd549c57..0125ef2c 100644 --- a/lib/gollum/web_sequence_diagram.rb +++ b/lib/gollum/web_sequence_diagram.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ require 'net/http' require 'uri' require 'open-uri' diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index df42d2f2..0154e940 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ module Gollum class Wiki include Pagination diff --git a/test/test_gitcode.rb b/test/test_gitcode.rb index c2c9f319..0a7890e9 100644 --- a/test/test_gitcode.rb +++ b/test/test_gitcode.rb @@ -25,7 +25,7 @@ context "gitcode" do end test 'that the rendered output is correctly fetched and rendered as html code' do - assert_equal %Q{

a

\n\n
\n
<ol class=\"tree\">\n  <li class=\"file\"><a href=\"0\">0</a></li>\n</ol>\n
\n
\n\n

b

}, @rendered + assert_equal %Q{

a

\n\n
<ol class=\"tree\">\n  <li class=\"file\"><a href=\"0\">0</a></li>\n</ol>\n
\n\n

b

}, @rendered end test 'contents' do diff --git a/test/test_markup.rb b/test/test_markup.rb index 9d033945..056028ff 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -193,7 +193,7 @@ context "Markup" do test "wiki link within inline code block" do @wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details) page = @wiki.page("Potato") - assert_equal "

\n sed -i '' 's/[[:space:]]*$//'\n

", page.formatted_data + assert_equal "

sed -i '' 's/[[:space:]]*$//'

", page.formatted_data end test "regexp gsub! backref (#383)" do @@ -212,7 +212,7 @@ context "Markup" do assert_equal expected, output end - test "~~~ code blocks #537" do + test "tilda code blocks #537" do page = 'test_rgx' @wiki.write_page(page, :markdown, %Q(~~~ {.ruby} @@ -220,11 +220,12 @@ context "Markup" do ~~~ ), commit_details) output = @wiki.page(page).formatted_data - expected = %Q{
\n
'hi'\n
\n
} + expected = %Q{
'hi'\n
} assert_equal expected, output end - test "~~~ code blocks #537 with more than one class" do + # Issue #537 + test "tilda code blocks with more than one class" do page = 'test_rgx' @wiki.write_page(page, :markdown, %Q(~~~ {#hi .ruby .sauce} @@ -232,11 +233,12 @@ context "Markup" do ~~~ ), commit_details) output = @wiki.page(page).formatted_data - expected = %Q{
\n
'hi'\n
\n
} + expected = %Q{
'hi'\n
} assert_equal expected, output end - test "~~~ code blocks #537 with lots of tildes" do + # Issue #537 + test "tilda code blocks with lots of tildes" do page = 'test_rgx' @wiki.write_page(page, :markdown, %Q(~~~~~~ {#hi .ruby .sauce} @@ -245,7 +247,7 @@ context "Markup" do ~~~~~~ ), commit_details) output = @wiki.page(page).formatted_data - expected = %Q{
\n
~~\n'hi'~\n
\n
} + expected = %Q{
~~\n'hi'~\n
} assert_equal expected, output end @@ -268,7 +270,7 @@ context "Markup" do test "piped wiki link within code block" do @wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details) page = @wiki.page("Potato") - assert_equal "

\n make a link [[home|sweet home]]\n

", page.formatted_data + assert_equal "

make a link [[home|sweet home]]

", page.formatted_data end ######################################################################### @@ -469,9 +471,9 @@ context "Markup" do # ######################################################################### - test "code blocks" do + test "regular code blocks" do content = "a\n\n```ruby\nx = 1\n```\n\nb" - output = %Q{

a

\n\n
\n
x = 1\n
\n
\n\n

b

} + output = %Q{

a

\n\n
x = 1\n
\n\n

b

} index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) @@ -484,7 +486,7 @@ context "Markup" do test "code blocks with carriage returns" do content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb" - output = %Q{

a

\n\n
\n
x = 1\n
\n
\n\n

b

} + output = %Q{

a

\n\n
x = 1\n
\n\n

b

} index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) @@ -515,7 +517,7 @@ context "Markup" do test "code blocks with multibyte caracters indent" do content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb" - output = %Q{

a

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

b

} + output = %Q{

a

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

b

} index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) index.commit("Add alpha.jpg") @@ -575,7 +577,7 @@ np.array([[2,2],[1,3]],np.float) output_page = @wiki.page("page").formatted_data assert_equal %Q{

a b

}, output_script - assert_equal %Q{
\n
<p>a  b</p>\n
\n
}, output_page + assert_equal %Q{
<p>a  b</p>\n
}, output_page end test "embed code page absolute link" do @@ -584,7 +586,7 @@ np.array([[2,2],[1,3]],np.float) page = @wiki.page("a") output = page.formatted_data - assert_equal %Q{

a\n

\n
<p>a\n!base</p>\n
\n
\n}, output + assert_equal %Q{

a\n

<p>a\n!base</p>\n
\n}, output end test "embed code page relative link" do @@ -593,7 +595,7 @@ np.array([[2,2],[1,3]],np.float) page = @wiki.page("a") output = page.formatted_data - assert_equal %Q{

a\n

\n
<p>a\n!rel</p>\n
\n
\n}, output + assert_equal %Q{

a\n

<p>a\n!rel</p>\n
\n}, output end test "code block in unsupported language" do