Skip to content

Commit 8d12fa4

Browse files
committed
Merge pull request #73 from jakedouglas/fix_ruby_1_8_anchors
TocFilter: keep using the old punctuation stripping on 1.8.7
2 parents 4fc3a60 + 61ba29d commit 8d12fa4

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)