Skip to content

Commit 61ba29d

Browse files
committed
TocFilter: keep using the old punctuation stripping on 1.8.7
The UTF regexp doesn't seem to work correctly under 1.8.7 and causes existing tests to fail. We don't really care about fixing this case for 1.8.7 but we don't want the gem to be unusable, so we'll just special case it for now.
1 parent 4fc3a60 commit 61ba29d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/html/pipeline/toc_filter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ class Pipeline
77
# eventually generating the Table of Contents itself, with links
88
# to each header
99
class TableOfContentsFilter < Filter
10+
PUNCTUATION_REGEXP = RUBY_VERSION > "1.9" ? /[^\p{Word}\- ]/u : /[^\w\- ]/
11+
1012
def call
1113
headers = Hash.new(0)
1214
doc.css('h1, h2, h3, h4, h5, h6').each do |node|
1315
name = node.text.downcase
14-
name.gsub!(/[^\p{Word}\- ]/u, '') # remove punctuation
16+
name.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation
1517
name.gsub!(' ', '-') # replace spaces with dash
1618

1719
uniq = (headers[name] > 0) ? "-#{headers[name]}" : ''

test/html/pipeline/toc_filter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ def test_anchors_with_utf8_characters
5454
rendered_h1s[0]
5555
assert_equal "<h1>\n<a name=\"%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9\" class=\"anchor\" href=\"#%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9\"><span class=\"octicon octicon-link\"></span></a>Русский</h1>",
5656
rendered_h1s[1]
57-
end
57+
end if RUBY_VERSION > "1.9" # not sure how to make this work on 1.8.7
5858
end

0 commit comments

Comments
 (0)