File: helper.rb

package info (click to toggle)
ruby-jekyll-toc 0.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 244 kB
  • sloc: ruby: 912; makefile: 9
file content (17 lines) | stat: -rw-r--r-- 417 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

module Jekyll
  module TableOfContents
    # helper methods for Parser
    module Helper
      PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze

      def generate_toc_id(text)
        text = text.downcase
                   .gsub(PUNCTUATION_REGEXP, '') # remove punctuation
                   .tr(' ', '-') # replace spaces with dash
        CGI.escape(text)
      end
    end
  end
end