diff options
Diffstat (limited to 'lib/banzai/filter/table_of_contents_filter.rb')
-rw-r--r-- | lib/banzai/filter/table_of_contents_filter.rb | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb index a2c8e92e560..b362607aed2 100644 --- a/lib/banzai/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -17,7 +17,7 @@ module Banzai # :toc - String containing Table of Contents data as a `ul` element with # `li` child elements. class TableOfContentsFilter < HTML::Pipeline::Filter - PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze + include Gitlab::Utils::Markdown def call return doc if context[:no_header_anchors] @@ -29,14 +29,7 @@ module Banzai doc.css('h1, h2, h3, h4, h5, h6').each do |node| if header_content = node.children.first - id = node - .text - .strip - .downcase - .gsub(PUNCTUATION_REGEXP, '') # remove punctuation - .tr(' ', '-') # replace spaces with dash - .squeeze('-') # replace multiple dashes with one - .gsub(/\A(\d+)\z/, 'anchor-\1') # digits-only hrefs conflict with issue refs + id = string_to_anchor(node.text) uniq = headers[id] > 0 ? "-#{headers[id]}" : '' headers[id] += 1 |