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

#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?, #children, #children=, #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)


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

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

Instance Attribute Details

#list_attributesListAttributes

Returns:



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

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 = if config.has_key? :start then config[:start] else 1 end
        style = if config.has_key? :style then config[:style] else "Decimal" end
        delim = if config.has_key? :delim then config[:delim] else "Period" end
        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:



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

def self.from_array(items, **config )
    start = if config.has_key? :start then config[:start] else 1 end
    style = if config.has_key? :style then config[:style] else "Decimal" end
    delim = if config.has_key? :delim then config[:delim] else "Period" end
    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)


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

def ast_contents()
    [
        @list_attributes.to_ast,
        super
    ] 
end