Class: Paru::PandocFilter::DefinitionListItem
- Defined in:
- lib/paru/filter/definition_list_item.rb
Overview
A DefinitionListItem is a helper node to represent the pair of a term and its definition in a DefinitionList
Instance Attribute Summary collapse
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(item) ⇒ DefinitionListItem
constructor
Create a new DefinitionListItem.
-
#to_array ⇒ Array
Convert this DefinitionListItem to a pair of term and definition.
-
#to_ast ⇒ Object
Create an AST representation of this DefinitionListItem.
Methods inherited from Block
Methods inherited from Node
#ast_contents, #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_s, #type
Methods included from ASTManipulation
#append, #delete, #each_depth_first, #find_index, #get, #insert, #prepend, #remove_at, #replace, #replace_at
Constructor Details
#initialize(item) ⇒ DefinitionListItem
Create a new DefinitionListItem
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/paru/filter/definition_list_item.rb', line 41 def initialize(item) super([]) @term = Block.new item[0] @term.parent = self @children << @term @definition = List.new item[1] @definition.parent = self @children << @definition end |
Instance Attribute Details
#definition ⇒ List
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/paru/filter/definition_list_item.rb', line 35 class DefinitionListItem < Block attr_accessor :term, :definition # Create a new DefinitionListItem # # @param item [Array] the [term, definition] def initialize(item) super([]) @term = Block.new item[0] @term.parent = self @children << @term @definition = List.new item[1] @definition.parent = self @children << @definition end # Create an AST representation of this DefinitionListItem def to_ast [ @term.ast_contents, @definition.ast_contents ] end # Convert this DefinitionListItem to a pair of term and definition # # @return [Array] def to_array term = @term.children.map { |c| c.markdown.strip }.reject(&:empty?).join(' ').strip definition = @definition.children.map { |c| c.children.map(&:markdown) }.join("\n").strip [term, definition] end end |
#term ⇒ Block
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/paru/filter/definition_list_item.rb', line 35 class DefinitionListItem < Block attr_accessor :term, :definition # Create a new DefinitionListItem # # @param item [Array] the [term, definition] def initialize(item) super([]) @term = Block.new item[0] @term.parent = self @children << @term @definition = List.new item[1] @definition.parent = self @children << @definition end # Create an AST representation of this DefinitionListItem def to_ast [ @term.ast_contents, @definition.ast_contents ] end # Convert this DefinitionListItem to a pair of term and definition # # @return [Array] def to_array term = @term.children.map { |c| c.markdown.strip }.reject(&:empty?).join(' ').strip definition = @definition.children.map { |c| c.children.map(&:markdown) }.join("\n").strip [term, definition] end end |
Instance Method Details
#to_array ⇒ Array
Convert this DefinitionListItem to a pair of term and definition
64 65 66 67 68 |
# File 'lib/paru/filter/definition_list_item.rb', line 64 def to_array term = @term.children.map { |c| c.markdown.strip }.reject(&:empty?).join(' ').strip definition = @definition.children.map { |c| c.children.map(&:markdown) }.join("\n").strip [term, definition] end |
#to_ast ⇒ Object
Create an AST representation of this DefinitionListItem
54 55 56 57 58 59 |
# File 'lib/paru/filter/definition_list_item.rb', line 54 def to_ast [ @term.ast_contents, @definition.ast_contents ] end |