Class: Paru::PandocFilter::OrderedList
- Defined in:
- lib/paru/filter/ordered_list.rb
Overview
An OrderedList Node
It has an ListAttributes object and a list of items
Instance Attribute Summary collapse
Class Method Summary collapse
-
.from_array(items, **config) ⇒ OrderedList
Create a new OrderedList from an array of markdown strings.
Instance Method Summary collapse
-
#ast_contents ⇒ Array
The AST contents.
-
#initialize(contents) ⇒ OrderedList
constructor
Create a new OrderedList node based on the contents.
Constructor Details
#initialize(contents) ⇒ OrderedList
Create a new OrderedList node based on the contents
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_attributes ⇒ ListAttributes
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)
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_contents ⇒ Array
The AST contents
50 51 52 53 54 55 |
# File 'lib/paru/filter/ordered_list.rb', line 50 def ast_contents() [ @list_attributes.to_ast, super ] end |