Class: Paru::PandocFilter::List

Inherits:
Block show all
Defined in:
lib/paru/filter/list.rb

Overview

A List node is a base node for various List node types

Direct Known Subclasses

BulletList, LineBlock, OrderedList

Instance Attribute Summary

Attributes inherited from Node

#children, #parent

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_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, node_class = Block) ⇒ List

Create a new List node based on contents

Parameters:



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

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

    @children.push child
  end
end

Instance Method Details

#ast_contentsObject

Create an AST representation of this List node



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

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

#has_block?Boolean

Has this List node block contents?

Returns:

  • (Boolean)

    true



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

def has_block?
  true
end

#to_arrayString[]

Convert this List to an array of markdown strings

Returns:

  • (String[])


57
58
59
60
61
# File 'lib/paru/filter/list.rb', line 57

def to_array
  @children.map do |block|
    block.children.map { |c| c.markdown.strip }.join("\n")
  end
end