diff options
-rw-r--r-- | lib/banzai/filter/table_of_contents_filter.rb | 3 | ||||
-rw-r--r-- | spec/lib/banzai/filter/table_of_contents_filter_spec.rb | 2 |
2 files changed, 2 insertions, 3 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb index 8d79f5bd58b..ade4d260be1 100644 --- a/lib/banzai/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -18,7 +18,6 @@ module Banzai # `li` child elements. class TableOfContentsFilter < HTML::Pipeline::Filter PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze - LEADING_OR_TRAILING_SPACE_REGEXP = /^\p{Space}+|\p{Space}+$/.freeze def call return doc if context[:no_header_anchors] @@ -32,7 +31,7 @@ module Banzai if header_content = node.children.first id = node .text - .gsub(LEADING_OR_TRAILING_SPACE_REGEXP, '') # remove leading and trailing spaces + .strip .downcase .gsub(PUNCTUATION_REGEXP, '') # remove punctuation .tr(' ', '-') # replace spaces with dash diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb index f776e21a89e..4a9880ac85a 100644 --- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -59,7 +59,7 @@ describe Banzai::Filter::TableOfContentsFilter do end it 'removes any leading or trailing spaces' do - doc = filter(header(1, " \r\n \t Title with spaces \r\n\t ")) + doc = filter(header(1, " \r\n\tTitle with spaces\r\n\t ")) expect(doc.css('h1 a').first.attr('href')).to eq '#title-with-spaces' end |