Module: Jekyll::TableOfContents::Helper
- Included in:
- Parser
- Defined in:
- lib/table_of_contents/helper.rb
Overview
helper methods for Parser
Constant Summary collapse
- PUNCTUATION_REGEXP =
/[^\p{Word}\- ]/u
Instance Method Summary collapse
Instance Method Details
#extract_text(node, only_direct_text: false) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/table_of_contents/helper.rb', line 16 def extract_text(node, only_direct_text: false) if only_direct_text node.children.select(&:text?).map { |child| child.text.strip }.reject(&:empty?).join(' ') else node.text.strip end end |
#generate_toc_id(text) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/table_of_contents/helper.rb', line 9 def generate_toc_id(text) text = text.downcase .gsub(PUNCTUATION_REGEXP, '') # remove punctuation .tr(' ', '-') # replace spaces with dash CGI.escape(text) end |