Sha256: d9f8cabed5bf22078cd9ff5ab0fb2e152b70494fcc15f9615a52a48109f7ef4a

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

module CommonMarker
  class Node
    include Enumerable

    # Public: An iterator that "walks the tree," descending into children recursively.
    #
    # blk - A {Proc} representing the action to take for each child
    def walk(&block)
      return enum_for(:walk) unless block_given?

      yield self
      each do |child|
        child.walk(&block)
      end
    end

    # Public: Convert the node to an HTML string.
    #
    # options - A {Symbol} or {Array of Symbol}s indicating the render options
    #
    # Returns a {String}.
    def to_html(options = :default)
      opts = Config.process_options(options, :render)
      _render_html(opts).force_encoding('utf-8')
    end

    # Public: Iterate over the children (if any) of the current pointer.
    def each(&block)
      return enum_for(:each) unless block_given?

      child = first_child
      while child
        nextchild = child.next
        yield child
        child = nextchild
      end
    end

    # Deprecated: Please use `each` instead
    def each_child(&block)
      warn '[DEPRECATION] `each_child` is deprecated.  Please use `each` instead.'
      each(&block)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
commonmarker-0.13.0 lib/commonmarker/node.rb
commonmarker-0.12.0 lib/commonmarker/node.rb
commonmarker-0.10.0 lib/commonmarker/node.rb
commonmarker-0.9.2 lib/commonmarker/node.rb
commonmarker-0.9.1 lib/commonmarker/node.rb
commonmarker-0.9.0 lib/commonmarker/node.rb