Sha256: 6580a9cc76c47d0d2a4ff88a46c170437ef7f22f8c8cad92903bb5dd1396ff54
Contents?: true
Size: 947 Bytes
Versions: 2
Compression:
Stored size: 947 Bytes
Contents
require 'commonmarker' require 'grokdown' require 'grokdown/matching' require 'grokdown/never_consumes' module Grokdown class Document def initialize(markdown, options: %i[DEFAULT], extensions: %i[table tasklist strikethrough autolink]) @walk = [] @nodes = [] CommonMarker.render_doc(markdown,options,extensions).reduce(self) do |doc, node| decorated_node = case node when Matching Matching.for(node).build(node) else NeverConsumes.new(node) end doc.push decorated_node end end def push(node) if accepts = @walk.reverse.find {|i| i.consumes?(node) } accepts.consume(node) else @nodes.push(node) end @walk.push(node) self end attr_reader :nodes include Enumerable def each(&block) @nodes.each(&block) end def walk(&block) @walk.each(&block) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grokdown-0.1.1 | lib/grokdown/document.rb |
grokdown-0.1.0 | lib/grokdown/document.rb |