class Paru::PandocFilter::DefinitionList

A DefinitionList is a list of term-definition pairs, respecitively an Inline list and a Block list.

Public Class Methods

from_array(definitions) click to toggle source

Create a new DefinitionList based on a hash of term => definitions

@param definitions [Array] Array of arrays with terms and their definitions @return [DefinitionList]

# File lib/paru/filter/definition_list.rb, line 59
def self.from_array(definitions)
    ast_items = definitions.map do |definition| 
        term = Block.from_markdown(definition[0]).ast_contents
        defin = List.from_markdown(definition[1])

        if not defin.has_block?
            para = Para.new []
            para.inner_markdown = definition[1]
            defin = [para.to_ast]
        else
            defin = defin.children.map{|c| c.to_ast}
        end

        [term, [defin]]
    end

    DefinitionList.new ast_items
end
new(contents) click to toggle source

Create a new DefinitionList node

@param contents [Array] the contents of this definition list.

Calls superclass method
# File lib/paru/filter/definition_list.rb, line 30
def initialize(contents)
    super []
    contents.each do |item|
        child = DefinitionListItem.new item
        child.parent = self

        @children.push child
    end
end

Public Instance Methods

ast_contents() click to toggle source

Create an AST representation of this DefinitionList node

# File lib/paru/filter/definition_list.rb, line 41
def ast_contents
    @children.map {|child| child.to_ast}
end
to_array() click to toggle source

Convert this DefinitionList to a hash of term => definitions

@return [Array]

# File lib/paru/filter/definition_list.rb, line 48
def to_array()
    @children.map do |def_item|
        def_item.to_array 
    end
end