Fix anchor for Firefox.
This commit is contained in:
@@ -87,14 +87,14 @@ module Gollum
|
||||
def process_headers(doc)
|
||||
toc = nil
|
||||
doc.css('h1,h2,h3,h4,h5,h6').each do |h|
|
||||
id = CGI::escape(h.content.gsub(' ','-'))
|
||||
id = encodeURIComponent(h.content.gsub(' ','-'))
|
||||
level = h.name.gsub(/[hH]/,'').to_i
|
||||
|
||||
# Add anchors
|
||||
anchor = Nokogiri::XML::Node.new('a', doc)
|
||||
anchor['class'] = 'anchor'
|
||||
anchor['id'] = id
|
||||
anchor['href'] = '#' + id
|
||||
anchor['href'] = '#' + id.gsub('%', '%25')
|
||||
h.add_child(anchor)
|
||||
|
||||
# Build TOC
|
||||
|
||||
+16
-1
@@ -15,12 +15,27 @@ context "Unicode Support" do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "create and read non-latin page" do
|
||||
test "create and read non-latin page with anchor" do
|
||||
@wiki.write_page("test", :markdown, "# 한글")
|
||||
|
||||
page = @wiki.page("test")
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert_equal "# 한글", utf8(page.raw_data)
|
||||
|
||||
# markup.rb
|
||||
# #简介
|
||||
# href.gsub('%', '%25') so the anchor works in Firefox.
|
||||
# <a href="#%25ED%2595%259C%25EA%25B8%2580" id="%ED%95%9C%EA%B8%80" class="anchor"></a>
|
||||
doc = Nokogiri::HTML page.formatted_data
|
||||
h1s = doc / :h1
|
||||
h1 = h1s.first
|
||||
anchors = h1 / :a
|
||||
assert_equal 1, h1s.size
|
||||
assert_equal 1, anchors.size
|
||||
assert_equal '#%25ED%2595%259C%25EA%25B8%2580', anchors[0]['href']
|
||||
assert_equal '%ED%95%9C%EA%B8%80', anchors[0]['id']
|
||||
assert_equal 'anchor', anchors[0]['class']
|
||||
assert_equal '', anchors[0].text
|
||||
end
|
||||
|
||||
test "unicode with existing format rules" do
|
||||
|
||||
Reference in New Issue
Block a user