Fix nokogiri rendering

https://github.com/sparklemotion/nokogiri/issues/782
This commit is contained in:
bootstraponline
2012-10-27 18:22:43 -06:00
parent 68465a8651
commit 776df4e6ee
17 changed files with 39 additions and 24 deletions
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
# stdlib # stdlib
require 'digest/md5' require 'digest/md5'
require 'ostruct' require 'ostruct'
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class BlobEntry class BlobEntry
# Gets the String SHA for this blob. # Gets the String SHA for this blob.
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
# Responsible for handling the commit process for a Wiki. It sets up the # Responsible for handling the commit process for a Wiki. It sets up the
# Git index, provides methods for modifying the tree, and stores callbacks # Git index, provides methods for modifying the tree, and stores callbacks
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class File class File
Wiki.file_class = self Wiki.file_class = self
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
=begin =begin
FileView requires that: FileView requires that:
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'cgi' require 'cgi'
require 'sinatra' require 'sinatra'
require 'gollum' require 'gollum'
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Precious module Precious
module Helpers module Helpers
# Extract the path string that Gollum::Wiki expects # Extract the path string that Gollum::Wiki expects
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
# Controls all access to the Git objects from Gollum. Extend this class to # Controls all access to the Git objects from Gollum. Extend this class to
# add custom caching for special cases. # add custom caching for special cases.
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'net/http' require 'net/http'
require 'net/https' # ruby 1.8.7 fix, remove at upgrade require 'net/https' # ruby 1.8.7 fix, remove at upgrade
require 'uri' require 'uri'
+6 -7
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'digest/sha1' require 'digest/sha1'
require 'cgi' require 'cgi'
require 'pygments' require 'pygments'
@@ -74,13 +75,11 @@ module Gollum
doc,toc = process_headers(doc) doc,toc = process_headers(doc)
@toc = @sub_page ? ( @parent_page ? @parent_page.toc_data : "[[_TOC_]]" ) : toc @toc = @sub_page ? ( @parent_page ? @parent_page.toc_data : "[[_TOC_]]" ) : toc
yield doc if block_given? yield doc if block_given?
data = doc.to_xhtml(:indent => 0, :encoding => 'UTF-8') # 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.
# fix 4 space indented code blocks introduced by nokogiri. # https://github.com/sparklemotion/nokogiri/issues/782
# tag should not have a newline after it # DEFAULT_HTML encodes unicode so XHTML is used for proper unicode support in href.
data.gsub!(/<pre>\s*<code>(.+)<\/code>\s*<\/pre>/m) do data = doc.to_xml( { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' } )
"<pre><code>#{$1}</code></pre>"
end
data = process_toc_tags(data) data = process_toc_tags(data)
data = process_wsd(data) data = process_wsd(data)
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class Page class Page
include Pagination include Pagination
+2 -1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
module Pagination module Pagination
def self.included(klass) def self.included(klass)
@@ -58,4 +59,4 @@ module Gollum
self.class.log_pagination_options(options) self.class.log_pagination_options(options)
end end
end end
end end
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
# Encapsulate sanitization options. # Encapsulate sanitization options.
# #
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
require 'net/http' require 'net/http'
require 'uri' require 'uri'
require 'open-uri' require 'open-uri'
+1
View File
@@ -1,3 +1,4 @@
# ~*~ encoding: utf-8 ~*~
module Gollum module Gollum
class Wiki class Wiki
include Pagination include Pagination
+1 -1
View File
@@ -25,7 +25,7 @@ context "gitcode" do
end end
test 'that the rendered output is correctly fetched and rendered as html code' do test 'that the rendered output is correctly fetched and rendered as html code' do
assert_equal %Q{<p>a</p>\n\n<div class=\"highlight\">\n <pre><span class=\"nt\">&lt;ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">&gt;</span>\n <span class=\"nt\">&lt;li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">&gt;&lt;a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">&gt;</span>0<span class=\"nt\">&lt;/a&gt;&lt;/li&gt;</span>\n<span class=\"nt\">&lt;/ol&gt;</span>\n</pre>\n</div>\n\n<p>b</p>}, @rendered assert_equal %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"nt\">&lt;ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">&gt;</span>\n <span class=\"nt\">&lt;li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">&gt;&lt;a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">&gt;</span>0<span class=\"nt\">&lt;/a&gt;&lt;/li&gt;</span>\n<span class=\"nt\">&lt;/ol&gt;</span>\n</pre></div>\n\n<p>b</p>}, @rendered
end end
test 'contents' do test 'contents' do
+17 -15
View File
@@ -193,7 +193,7 @@ context "Markup" do
test "wiki link within inline code block" do test "wiki link within inline code block" do
@wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details) @wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details)
page = @wiki.page("Potato") page = @wiki.page("Potato")
assert_equal "<p>\n <code>sed -i '' 's/[[:space:]]*$//'</code>\n</p>", page.formatted_data assert_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
end end
test "regexp gsub! backref (#383)" do test "regexp gsub! backref (#383)" do
@@ -212,7 +212,7 @@ context "Markup" do
assert_equal expected, output assert_equal expected, output
end end
test "~~~ code blocks #537" do test "tilda code blocks #537" do
page = 'test_rgx' page = 'test_rgx'
@wiki.write_page(page, :markdown, @wiki.write_page(page, :markdown,
%Q(~~~ {.ruby} %Q(~~~ {.ruby}
@@ -220,11 +220,12 @@ context "Markup" do
~~~ ~~~
), commit_details) ), commit_details)
output = @wiki.page(page).formatted_data output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\">\n <pre><span class=\"s1\">'hi'</span>\n</pre>\n</div>} expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
assert_equal expected, output assert_equal expected, output
end 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' page = 'test_rgx'
@wiki.write_page(page, :markdown, @wiki.write_page(page, :markdown,
%Q(~~~ {#hi .ruby .sauce} %Q(~~~ {#hi .ruby .sauce}
@@ -232,11 +233,12 @@ context "Markup" do
~~~ ~~~
), commit_details) ), commit_details)
output = @wiki.page(page).formatted_data output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\">\n <pre><span class=\"s1\">'hi'</span>\n</pre>\n</div>} expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
assert_equal expected, output assert_equal expected, output
end end
test "~~~ code blocks #537 with lots of tildes" do # Issue #537
test "tilda code blocks with lots of tildes" do
page = 'test_rgx' page = 'test_rgx'
@wiki.write_page(page, :markdown, @wiki.write_page(page, :markdown,
%Q(~~~~~~ {#hi .ruby .sauce} %Q(~~~~~~ {#hi .ruby .sauce}
@@ -245,7 +247,7 @@ context "Markup" do
~~~~~~ ~~~~~~
), commit_details) ), commit_details)
output = @wiki.page(page).formatted_data output = @wiki.page(page).formatted_data
expected = %Q{<div class=\"highlight\">\n <pre><span class=\"o\">~~</span>\n<span class=\"s1\">'hi'</span><span class=\"o\">~</span>\n</pre>\n</div>} expected = %Q{<div class=\"highlight\"><pre><span class=\"o\">~~</span>\n<span class=\"s1\">'hi'</span><span class=\"o\">~</span>\n</pre></div>}
assert_equal expected, output assert_equal expected, output
end end
@@ -268,7 +270,7 @@ context "Markup" do
test "piped wiki link within code block" do test "piped wiki link within code block" do
@wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details) @wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details)
page = @wiki.page("Potato") page = @wiki.page("Potato")
assert_equal "<p>\n <code>make a link [[home|sweet home]]</code>\n</p>", page.formatted_data assert_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
end 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" content = "a\n\n```ruby\nx = 1\n```\n\nb"
output = %Q{<p>a</p>\n\n<div class=\"highlight\">\n <pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>} output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>\n\n<p>b</p>}
index = @wiki.repo.index index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content) index.add("Bilbo-Baggins.md", content)
@@ -484,7 +486,7 @@ context "Markup" do
test "code blocks with carriage returns" do test "code blocks with carriage returns" do
content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb" content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
output = %Q{<p>a</p>\n\n<div class=\"highlight\">\n <pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>} output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>\n\n<p>b</p>}
index = @wiki.repo.index index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content) index.add("Bilbo-Baggins.md", content)
@@ -515,7 +517,7 @@ context "Markup" do
test "code blocks with multibyte caracters indent" do test "code blocks with multibyte caracters indent" do
content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb" content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb"
output = %Q{<p>a</p>\n\n<div class=\"highlight\">\n <pre><span class=\"n\">s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'</span>\n</pre>\n</div>\n\n<p>b</p>} output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'</span>\n</pre></div>\n\n<p>b</p>}
index = @wiki.repo.index index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content) index.add("Bilbo-Baggins.md", content)
index.commit("Add alpha.jpg") index.commit("Add alpha.jpg")
@@ -575,7 +577,7 @@ np.array([[2,2],[1,3]],np.float)
output_page = @wiki.page("page").formatted_data output_page = @wiki.page("page").formatted_data
assert_equal %Q{<p>a b</p>}, output_script assert_equal %Q{<p>a b</p>}, output_script
assert_equal %Q{<div class=\"highlight\">\n <pre><span class=\"nt\">&lt;p&gt;</span>a b<span class=\"nt\">&lt;/p&gt;</span>\n</pre>\n</div>}, output_page assert_equal %Q{<div class=\"highlight\"><pre><span class=\"nt\">&lt;p&gt;</span>a b<span class=\"nt\">&lt;/p&gt;</span>\n</pre></div>}, output_page
end end
test "embed code page absolute link" do test "embed code page absolute link" do
@@ -584,7 +586,7 @@ np.array([[2,2],[1,3]],np.float)
page = @wiki.page("a") page = @wiki.page("a")
output = page.formatted_data output = page.formatted_data
assert_equal %Q{<p>a\n</p><div class=\"highlight\">\n <pre><span class=\"nt\">&lt;p&gt;</span>a\n!base<span class=\"nt\">&lt;/p&gt;</span>\n</pre>\n</div>\n}, output assert_equal %Q{<p>a\n</p><div class=\"highlight\"><pre><span class=\"nt\">&lt;p&gt;</span>a\n!base<span class=\"nt\">&lt;/p&gt;</span>\n</pre></div>\n}, output
end end
test "embed code page relative link" do test "embed code page relative link" do
@@ -593,7 +595,7 @@ np.array([[2,2],[1,3]],np.float)
page = @wiki.page("a") page = @wiki.page("a")
output = page.formatted_data output = page.formatted_data
assert_equal %Q{<p>a\n</p><div class=\"highlight\">\n <pre><span class=\"nt\">&lt;p&gt;</span>a\n!rel<span class=\"nt\">&lt;/p&gt;</span>\n</pre>\n</div>\n}, output assert_equal %Q{<p>a\n</p><div class=\"highlight\"><pre><span class=\"nt\">&lt;p&gt;</span>a\n!rel<span class=\"nt\">&lt;/p&gt;</span>\n</pre></div>\n}, output
end end
test "code block in unsupported language" do test "code block in unsupported language" do