Method: Yatoc#initialize
- Defined in:
- lib/yatoc.rb
#initialize(content, min_sections: 3, numbered: nil, debug: false) ⇒ Yatoc
Returns a new instance of Yatoc.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/yatoc.rb', line 17 def initialize(content, min_sections: 3, numbered: nil, debug: false) @numbered, @debug, @content = numbered, debug, content @to_html = if content =~ /<index[^>]+>/ then @numbered ||= false puts '1. ready to gen_index'.info if @debug html2 = gen_index(content) puts 'html2: ' + html2.inspect "%s\n\n<div class='main'>%s</div>" % \ [html2, content.sub(/<index[^>]+>/, '')] elsif content =~ /<ix[^>]+>/ then @numbered ||= false puts '2. ready to gen_index'.info if @debug html2 = gen_index(content, threshold: nil) puts 'html2: ' + html2.inspect "%s\n\n<div class='main'>%s</div>" % \ [html2, content.sub(/<ix[^>]+>/, '')] elsif content.scan(/<h\d+/).length > min_sections @numbered ||= true puts 'ready to gen_toc()'.info if @debug gen_toc(content) else content end # note: @to_html is important because this gem is used by the # Martile gem which expect to pass HTML through to render any TOCs. end |