Class: Danger::Toc::Extractor

Inherits:
Kramdown::Converter::Base
  • Object
show all
Defined in:
lib/toc/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, options) ⇒ Extractor

Returns a new instance of Extractor.



6
7
8
9
10
11
# File 'lib/toc/extractor.rb', line 6

def initialize(root, options)
  super
  @toc_start = nil
  @toc_end = nil
  @in_toc = false
end

Instance Method Details

#convert(el) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/toc/extractor.rb', line 13

def convert(el)
  if el.type == :header && el.options[:raw_text] == Danger::Toc.config.header
    @in_toc = true
    @toc_start = el.options[:location]
  elsif el.type == :header
    @toc_end = el.options[:location] if @in_toc && !@toc_end
    @in_toc = false
  else
    el.children.each { |child| convert(child) }
  end
  [@toc_start, @toc_end]
end