Skip to content

Commit

Permalink
Merge pull request #73 from jakedouglas/fix_ruby_1_8_anchors
Browse files Browse the repository at this point in the history
TocFilter: keep using the old punctuation stripping on 1.8.7
  • Loading branch information
jch committed Jul 16, 2013
2 parents 4fc3a60 + 61ba29d commit 8d12fa4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/html/pipeline/toc_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class Pipeline
# eventually generating the Table of Contents itself, with links
# to each header
class TableOfContentsFilter < Filter
PUNCTUATION_REGEXP = RUBY_VERSION > "1.9" ? /[^\p{Word}\- ]/u : /[^\w\- ]/

def call
headers = Hash.new(0)
doc.css('h1, h2, h3, h4, h5, h6').each do |node|
name = node.text.downcase
name.gsub!(/[^\p{Word}\- ]/u, '') # remove punctuation
name.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation
name.gsub!(' ', '-') # replace spaces with dash

uniq = (headers[name] > 0) ? "-#{headers[name]}" : ''
Expand Down
2 changes: 1 addition & 1 deletion test/html/pipeline/toc_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ def test_anchors_with_utf8_characters
rendered_h1s[0]
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>",
rendered_h1s[1]
end
end if RUBY_VERSION > "1.9" # not sure how to make this work on 1.8.7
end

0 comments on commit 8d12fa4

Please sign in to comment.