Class: Paru::PandocFilter::OrderedList

Inherits:
List show all
Defined in:
lib/paru/filter/ordered_list.rb

Overview

An OrderedList Node

It has an ListAttributes object and a list of items

Examples:

In markdown an ordered list looks like

1. this is the first item
2. this the second
3. and so on

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

#has_block?, #to_array

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) ⇒ OrderedList

Create a new OrderedList node based on the contents

Parameters:

  • contents (Array)


44
45
46
47
# File 'lib/paru/filter/ordered_list.rb', line 44

def initialize(contents)
  super(contents[1])
  @list_attributes = ListAttributes.new contents[0]
end

Instance Attribute Details

#list_attributesListAttributes

Returns:



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
70
71
72
73
# File 'lib/paru/filter/ordered_list.rb', line 38

class OrderedList < List
  attr_accessor :list_attributes

  # Create a new OrderedList node based on the contents
  #
  # @param contents [Array]
  def initialize(contents)
    super(contents[1])
    @list_attributes = ListAttributes.new contents[0]
  end

  # The AST contents
  #
  # @return [Array]
  def ast_contents
    [
      @list_attributes.to_ast,
      super
    ]
  end

  # Create a new OrderedList from an array of markdown strings
  #
  # @param items [String[]] an array of markdown strings
  # @param config [Hash] configuration of the list. Can have
  # properties :start (Int), :style (String), and :delim (String)
  #
  # @return [OrderedList]
  def self.from_array(items, **config)
    start = config.key?(:start) ? config[:start] : 1
    style = config.key?(:style) ? config[:style] : 'Decimal'
    delim = config.key?(:delim) ? config[:delim] : 'Period'
    ast_items = items.map { |item| [Block.from_markdown(item).to_ast] }
    OrderedList.new [[start, { 't' => style }, { 't' => delim }], ast_items]
  end
end

Class Method Details

.from_array(items, **config) ⇒ OrderedList

Create a new OrderedList from an array of markdown strings

properties :start (Int), :style (String), and :delim (String)

Parameters:

  • items (String[])

    an array of markdown strings

  • config (Hash)

    configuration of the list. Can have

Returns:



66
67
68
69
70
71
72
# File 'lib/paru/filter/ordered_list.rb', line 66

def self.from_array(items, **config)
  start = config.key?(:start) ? config[:start] : 1
  style = config.key?(:style) ? config[:style] : 'Decimal'
  delim = config.key?(:delim) ? config[:delim] : 'Period'
  ast_items = items.map { |item| [Block.from_markdown(item).to_ast] }
  OrderedList.new [[start, { 't' => style }, { 't' => delim }], ast_items]
end

Instance Method Details

#ast_contentsArray

The AST contents

Returns:

  • (Array)


52
53
54
55
56
57
# File 'lib/paru/filter/ordered_list.rb', line 52

def ast_contents
  [
    @list_attributes.to_ast,
    super
  ]
end