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.
Instance Attribute Summary
Attributes inherited from Node
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.
Methods inherited from 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
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
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_contents ⇒ Object
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_array ⇒ Array
Convert this DefinitionList to a hash of term => definitions
50 51 52 |
# File 'lib/paru/filter/definition_list.rb', line 50 def to_array @children.map(&:to_array) end |