Sha256: 723da453204bc5692b977dc99cd8dcc257affe098ae948acdb9db2360c05091e

Contents?: true

Size: 833 Bytes

Versions: 16

Compression:

Stored size: 833 Bytes

Contents

module Ecrire::Markdown::Parsers
  class List < Base
    UL = /^(-\s)(.+)?$/i
    OL = /^(\d+\.\s)(.+)?$/i

    def parse!

      unless @node.instance_of?(Ecrire::Markdown::Node)
        return @node
      end

      if match = UL.match(@node.content)
        list! match, Ecrire::Markdown::Nodes::UnorderedList
      elsif match = OL.match(@node.content)
        list! match, Ecrire::Markdown::Nodes::OrderedList
      end
      return @node
    end

    def list!(match, tag)
      previous_node = @document.nodes[@index - 1]
      if previous_node.nil? || !previous_node.instance_of?(tag)
        @node = tag.new(match[2])
        @document.nodes[@index] = @node
      else
        @index -= 1
        @document.nodes.delete(@node)
        previous_node.append(match[2])
        @node = previous_node
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ecrire-0.30.3 lib/ecrire/markdown/parsers/list.rb
ecrire-0.30.2 lib/ecrire/markdown/parsers/list.rb
ecrire-0.30.1 lib/ecrire/markdown/parsers/list.rb
ecrire-0.30.0 lib/ecrire/markdown/parsers/list.rb
ecrire-0.29.0 lib/ecrire/markdown/parsers/list.rb
ecrire-0.28.3 lib/ecrire/markdown/parsers/list.rb
ecrire-0.28.2 lib/ecrire/markdown/parsers/list.rb
ecrire-0.28.1 lib/ecrire/markdown/parsers/list.rb
ecrire-0.28.0 lib/ecrire/markdown/parsers/list.rb
ecrire-0.27.0 lib/ecrire/markdown/parsers/list.rb
ecrire-0.26.3 lib/ecrire/markdown/parsers/list.rb
ecrire-0.26.2 lib/ecrire/markdown/parsers/list.rb
ecrire-0.26.1 lib/ecrire/markdown/parsers/list.rb
ecrire-0.26.0 lib/ecrire/markdown/parsers/list.rb
ecrire-0.25.2 lib/ecrire/markdown/parsers/list.rb
ecrire-0.25.1 lib/ecrire/markdown/parsers/list.rb