Class: Paru::PandocFilter::DefinitionList

Inherits:
Block
  • Object
show all
Defined in:
lib/paru/filter/definition_list.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Node

#children, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Block

#is_block?

Methods inherited from Node

#ast_type, #can_act_as_both_block_and_inline?, #each, from_markdown, #get_replacement, #has_been_replaced?, #has_block?, #has_children?, #has_class?, #has_inline?, #has_parent?, #has_string?, #is_block?, #is_inline?, #is_leaf?, #is_node?, #is_root?, #markdown, #markdown=, #toMetadata, #to_ast, #to_s, #type

Methods included from ASTManipulation

#append, #delete, #each_depth_first, #find_index, #get, #insert, #prepend, #remove_at, #replace, #replace_at

Constructor Details

#initialize(contents) ⇒ DefinitionList

Create a new DefinitionList node

Parameters:

  • contents (Array)

    the contents of this definition list.



32
33
34
35
36
37
38
39
40
# File 'lib/paru/filter/definition_list.rb', line 32

def initialize(contents)
  super([])
  contents.each do |item|
    child = DefinitionListItem.new item
    child.parent = self

    @children.push child
  end
end

Class Method Details

.from_array(definitions) ⇒ DefinitionList

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

Parameters:

  • definitions (Array)

    Array of arrays with terms and their definitions

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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 defin.has_block?
      defin = defin.children.map(&:to_ast)
    else
      para = Para.new []
      para.inner_markdown = definition[1]
      defin = [para.to_ast]
    end

    [term, [defin]]
  end

  DefinitionList.new ast_items
end

Instance Method Details

#ast_contentsObject

Create an AST representation of this DefinitionList node



43
44
45
# File 'lib/paru/filter/definition_list.rb', line 43

def ast_contents
  @children.map(&:to_ast)
end

#to_arrayArray

Convert this DefinitionList to a hash of term => definitions

Returns:

  • (Array)


50
51
52
# File 'lib/paru/filter/definition_list.rb', line 50

def to_array
  @children.map(&:to_array)
end