Class: Mdtoc::Markdown::Parser

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mdtoc/markdown/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(depth, url) ⇒ Parser



13
14
15
16
# File 'lib/mdtoc/markdown/parser.rb', line 13

def initialize(depth, url)
  @depth = depth
  @url = url
end

Instance Method Details

#headers(lines) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mdtoc/markdown/parser.rb', line 19

def headers(lines)
  # TODO: Skip headers within multi-line comments.
  # TODO: Handle --- and === style headers.
  skip = T.let(false, T::Boolean)
  lines.filter_map do |line|
    # Skip code blocks.
    if line.start_with?('```') && !T.must(line[3..]).strip.end_with?('```')
      skip = !skip
    end
    next if skip || !line.start_with?('#')

    header(line)
  end
end