class Qiita::Markdown::Filters::HeadingAnchor
Public Instance Methods
Source
# File lib/qiita/markdown/filters/heading_anchor.rb, line 7 def call doc.search("h1, h2, h3, h4, h5, h6").each do |heading| heading["id"] = suffixed_id(heading) end doc end
Private Instance Methods
Source
# File lib/qiita/markdown/filters/heading_anchor.rb, line 17 def counter @counter ||= ::Hash.new(0) end
Source
# File lib/qiita/markdown/filters/heading_anchor.rb, line 21 def get_count(id) counter[id] end
Source
# File lib/qiita/markdown/filters/heading_anchor.rb, line 29 def heading_id(node) node.text.downcase.gsub(/[^\p{Word}\- ]/u, "").tr(" ", "-") end
Source
# File lib/qiita/markdown/filters/heading_anchor.rb, line 25 def increment_count(id) counter[id] += 1 end
Source
# File lib/qiita/markdown/filters/heading_anchor.rb, line 33 def suffixed_id(node) id = heading_id(node) count = get_count(id) suffix = count.positive? ? "-#{count}" : "" increment_count(id) "#{id}#{suffix}" end