Class: MarkdownCodeBlockParser

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_code_block_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(markdown) ⇒ MarkdownCodeBlockParser

Returns a new instance of MarkdownCodeBlockParser.



4
5
6
7
8
9
# File 'lib/markdown_code_block_parser.rb', line 4

def initialize(markdown)
  @markdown = markdown
  @matches = []
  @pairs = []
  @blocks = []
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



2
3
4
# File 'lib/markdown_code_block_parser.rb', line 2

def blocks
  @blocks
end

#markdownObject (readonly)

Returns the value of attribute markdown.



2
3
4
# File 'lib/markdown_code_block_parser.rb', line 2

def markdown
  @markdown
end

#matchesObject (readonly)

Returns the value of attribute matches.



2
3
4
# File 'lib/markdown_code_block_parser.rb', line 2

def matches
  @matches
end

#pairsObject (readonly)

Returns the value of attribute pairs.



2
3
4
# File 'lib/markdown_code_block_parser.rb', line 2

def pairs
  @pairs
end

Instance Method Details

#display_analysisObject



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/markdown_code_block_parser.rb', line 194

def display_analysis
  puts "Detected #{@matches.length} code block delimiters"
  puts "Formed #{@pairs.length} pairs"
  puts "\nCode blocks found:"

  @blocks.each_with_index do |block, i|
    puts "\nBlock #{i}:"
    puts "  Language: #{block[:language] || 'none'}"
    puts "  Position: #{block[:start_pos]}-#{block[:end_pos]}"
    puts "  Tick count: #{block[:tick_count]}"
    puts "  Nesting depth: #{block[:depth]}"
    puts "  Contains blocks: #{block[:nested_blocks].join(', ')}" unless block[:nested_blocks].empty?

    content_preview = block[:content][0..80].gsub(/\n/, ' ')
    puts "  Content preview: #{content_preview}..."
  end
end

#parseObject



11
12
13
14
15
16
17
# File 'lib/markdown_code_block_parser.rb', line 11

def parse
  find_all_code_blocks
  pair_code_blocks
  build_block_structures
  detect_nesting
  self
end