class Asciidoctor::Callouts

Public: Maintains a catalog of callouts and their associations.

def callout_ids(li_ordinal)

Returns A space-separated String of callout ids associated with the specified list item

retrieve the callouts
li_ordinal - the Integer ordinal (1-based) of the list item for which to

Public: Get a space-separated list of callout ids for the specified list item
def callout_ids(li_ordinal)
  current_list.inject([]) {|collector, element|
    collector << element[:id] if element[:ordinal] == li_ordinal
    collector
  } * ' '
end

def current_list

Returns The Array of callouts at the position of the list index pointer

Public: The current list for which callouts are being collected
def current_list
  @lists[@list_index - 1]
end

def generate_callout_id(list_index, co_index)

Returns A unique String id for a callout

co_index - The 1-based Integer index of the callout since the end of the last callout list
list_index - The 1-based Integer index of the callout list within the document

Internal: Generate a unique id for the callout at the specified position
def generate_callout_id(list_index, co_index)
  "CO#{list_index}-#{co_index}"
end

def generate_next_callout_id

Returns A unique String id for this callout

Internal: Generate a unique id for the callout based on the internal indexes
def generate_next_callout_id
  generate_callout_id(@list_index, @co_index)
end

def initialize

def initialize
  @lists = []
  @list_index = 0
  next_list
end

def next_list

Returns nothing

Public: Advance to the next callout list in the document
def next_list
  @list_index += 1
  if @lists.size < @list_index
    @lists << []
  end
  @co_index = 1
  nil
end

def read_next_id

Returns The unique String id of the next callout in the document

callout that was generated during lexing.
This method is used during rendering to retrieve the unique id of the
Reads the next callout index in the document and advances the pointer.

Public: Get the next callout index in the document
def read_next_id
  id = nil
  list = current_list
  if @co_index <= list.size
    id = list[@co_index - 1][:id]
  end
  @co_index += 1
  id
end

def register(li_ordinal)

Returns The unique String id of this callout

# => "CO2-1"
callouts.register(2)
callouts.next_list
# => "CO1-1"
callouts.register(1)
callouts = Asciidoctor::Callouts.new

Examples

callout is to be associated
li_ordinal - the Integer ordinal (1-based) of the list item to which this

callout list.
list in the document and the index of this callout since the end of the last
Generates a unique id for this callout based on the index of the next callout

Public: Register a new callout for the given list item ordinal.
def register(li_ordinal)
  current_list << {:ordinal => li_ordinal.to_i, :id => (id = generate_next_callout_id)}
  @co_index += 1
  id
end

def rewind

Returns nothing

from the parsing to rendering phase.
Public: Rewind the list index pointer, intended to be used when switching
def rewind
  @list_index = 1
  @co_index = 1
  
  nil
end