Class: ReferenceVisitor

Inherits:
Visitor show all
Defined in:
lib/jay_flavored_markdown/markdown_converter.rb

Constant Summary

Constants inherited from Visitor

Visitor::DISPATCHER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Visitor

#traverse

Constructor Details

#initializeReferenceVisitor



350
351
352
353
354
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 350

def initialize
  @xref_table = {}
  @item_table = []
  @section_table = []
end

Instance Attribute Details

#item_tableObject (readonly)

Returns the value of attribute item_table.



355
356
357
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 355

def item_table
  @item_table
end

#section_tableObject (readonly)

Returns the value of attribute section_table.



355
356
357
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 355

def section_table
  @section_table
end

#xref_tableObject (readonly)

Returns the value of attribute xref_table.



355
356
357
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 355

def xref_table
  @xref_table
end

Instance Method Details

#visit_header(el) ⇒ Object



375
376
377
378
379
380
381
382
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 375

def visit_header(el)
  el.options[:relative_position] = @section_table.size
  @section_table << el
  el.children.each do |child|
    traverse(child)
  end
  return el
end

#visit_label(el) ⇒ Object



357
358
359
360
361
362
363
364
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 357

def visit_label(el)
  ref = el.find_first_ancestor(:header) || el.find_first_ancestor(:li)
  @xref_table[el.value] = ref.value if ref.value
  el.children.each do |child|
    traverse(child)
  end
  return el
end

#visit_li(el) ⇒ Object



366
367
368
369
370
371
372
373
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 366

def visit_li(el)
  el.options[:relative_position] = @item_table.size
  @item_table << el
  el.children.each do |child|
    traverse(child)
  end
  return el
end