diff options
-rw-r--r-- | lib/banzai/filter/table_of_contents_filter.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb index f2ae17b44fa..d4cf08be0ae 100644 --- a/lib/banzai/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -18,6 +18,7 @@ module Banzai # `li` child elements. class TableOfContentsFilter < HTML::Pipeline::Filter PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u + LEADING_OR_TRAILING_SPACE_REGEXP = /^\p{Space}|\p{Space}$/ def call return doc if context[:no_header_anchors] @@ -31,6 +32,7 @@ module Banzai if header_content = node.children.first id = node .text + .gsub(LEADING_OR_TRAILING_SPACE_REGEXP, '') # remove leading and trailing spaces .downcase .gsub(PUNCTUATION_REGEXP, '') # remove punctuation .tr(' ', '-') # replace spaces with dash |