Skip to content

Commit 4b9168d

Browse files
author
Charlie Somerville
committed
only downcase ascii characters on ruby 2.4+
Starting in Ruby 2.4, the String case conversion methods are Unicode aware. To ensure that anchors in TOC links remain stable when upgrading to Ruby 2.4, we need to preserve the old behaviour by passing :ascii to String#downcase
1 parent 1cc54dd commit 4b9168d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/html/pipeline/toc_filter.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def call
3636
headers = Hash.new(0)
3737
doc.css('h1, h2, h3, h4, h5, h6').each do |node|
3838
text = node.text
39-
id = text.downcase
39+
id = ascii_downcase(text)
4040
id.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation
4141
id.gsub!(' ', '-') # replace spaces with dash
4242

@@ -50,6 +50,16 @@ def call
5050
result[:toc] = %Q{<ul class="section-nav">\n#{result[:toc]}</ul>} unless result[:toc].empty?
5151
doc
5252
end
53+
54+
if RUBY_VERSION >= "2.4"
55+
def ascii_downcase(str)
56+
str.downcase(:ascii)
57+
end
58+
else
59+
def ascii_downcase(str)
60+
str.downcase
61+
end
62+
end
5363
end
5464
end
5565
end

0 commit comments

Comments
 (0)