Class: Paru::PandocFilter::DefinitionList
- 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.
Class Method Summary collapse
-
.from_array(definitions) ⇒ DefinitionList
Create a new DefinitionList based on a hash of term => definitions.
Instance Method Summary collapse
-
#ast_contents ⇒ Object
Create an AST representation of this DefinitionList node.
-
#initialize(contents) ⇒ DefinitionList
constructor
Create a new DefinitionList node.
-
#to_array ⇒ Array
Convert this DefinitionList to a hash of term => definitions.
Constructor Details
#initialize(contents) ⇒ DefinitionList
Create a new DefinitionList node
30 31 32 33 34 35 36 37 38 |
# 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 |
Class Method Details
.from_array(definitions) ⇒ DefinitionList
Create a new DefinitionList based on a hash of term => definitions
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 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 |
Instance Method Details
#ast_contents ⇒ Object
Create an AST representation of this DefinitionList node
41 42 43 |
# File 'lib/paru/filter/definition_list.rb', line 41 def ast_contents @children.map {|child| child.to_ast} end |
#to_array ⇒ Array
Convert this DefinitionList to a hash of term => definitions
48 49 50 51 52 |
# File 'lib/paru/filter/definition_list.rb', line 48 def to_array() @children.map do |def_item| def_item.to_array end end |