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

Class Method Summary collapse

Instance Method Summary collapse

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