Class: Mdtoc::Markdown::Parser
- Inherits:
-
Object
- Object
- Mdtoc::Markdown::Parser
- Extended by:
- T::Sig
- Defined in:
- lib/mdtoc/markdown.rb
Instance Method Summary collapse
- #headers(lines) ⇒ Object
-
#initialize(depth, url) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(depth, url) ⇒ Parser
Returns a new instance of Parser.
45 46 47 48 |
# File 'lib/mdtoc/markdown.rb', line 45 def initialize(depth, url) @depth = depth @url = url end |
Instance Method Details
#headers(lines) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mdtoc/markdown.rb', line 51 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 |