Class: Coradoc::Markdown::Heading
- Defined in:
- lib/coradoc/markdown/model/heading.rb
Overview
Heading model representing a Markdown heading (# to ######).
Instance Method Summary collapse
-
#auto_id ⇒ String
Generate an auto ID from the heading text.
-
#heading_id ⇒ String
Get the ID for this heading (uses explicit id if set, otherwise auto_id).
Methods inherited from Base
Instance Method Details
#auto_id ⇒ String
Generate an auto ID from the heading text
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/coradoc/markdown/model/heading.rb', line 19 def auto_id return '' if text.nil? || text.empty? # Downcase, replace non-alphanumeric with hyphens, collapse multiple hyphens slug = text.to_s .downcase .gsub(/[^a-z0-9]+/, '-') .gsub(/^-+|-+$/, '') slug.empty? ? 'section' : slug end |
#heading_id ⇒ String
Get the ID for this heading (uses explicit id if set, otherwise auto_id)
33 34 35 |
# File 'lib/coradoc/markdown/model/heading.rb', line 33 def heading_id id || auto_id end |