Class: Danger::Toc::Constructor
- Inherits:
-
Kramdown::Converter::Toc
- Object
- Kramdown::Converter::Toc
- Danger::Toc::Constructor
- Defined in:
- lib/toc/constructor.rb
Instance Method Summary collapse
Instance Method Details
#convert(el) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/toc/constructor.rb', line 24 def convert(el) toc = flatten(super(el)) has_toc = false headers = [] toc.each do |line| if !has_toc && line[:text] == Danger::Toc.config.header headers = [] # drop any headers prior to TOC has_toc = true else headers << line end end headers end |
#flatten(el) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/toc/constructor.rb', line 6 def flatten(el) return [] unless el.type == :toc result = [] if el.value result << { id: el.attr[:id], text: el.value.[:raw_text], depth: el.value.[:level] } end if el.children el.children.each do |child| result.concat(flatten(child)) end end result end |