Sha256: 59a80cc68fc2ffcc6a4579563b3335ed2941900bb48e1d61edab42be75e317b6

Contents?: true

Size: 1.94 KB

Versions: 17

Compression:

Stored size: 1.94 KB

Contents

require 'commonmarker/node/inspect'

module CommonMarker
  class Node
    include Enumerable
    include Inspect

    # 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
    # extensions - An {Array of Symbol}s indicating the extensions to use
    #
    # Returns a {String}.
    def to_html(options = :DEFAULT, extensions = [])
      opts = Config.process_options(options, :render)
      _render_html(opts, extensions).force_encoding('utf-8')
    end

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

    # Public: Convert the node to a plain text string.
    #
    # options - A {Symbol} or {Array of Symbol}s indicating the render options
    #
    # Returns a {String}.
    def to_plaintext(options = :DEFAULT)
      opts = Config.process_options(options, :render)
      _render_plaintext(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

17 entries across 17 versions & 1 rubygems

Version Path
commonmarker-0.17.7.1 lib/commonmarker/node.rb
commonmarker-0.17.7 lib/commonmarker/node.rb
commonmarker-0.17.6 lib/commonmarker/node.rb
commonmarker-0.17.5 lib/commonmarker/node.rb
commonmarker-0.17.4 lib/commonmarker/node.rb
commonmarker-0.17.2 lib/commonmarker/node.rb
commonmarker-0.17.1 lib/commonmarker/node.rb
commonmarker-0.17.0 lib/commonmarker/node.rb
commonmarker-0.16.8 lib/commonmarker/node.rb
commonmarker-0.16.7 lib/commonmarker/node.rb
commonmarker-0.16.6 lib/commonmarker/node.rb
commonmarker-0.16.5 lib/commonmarker/node.rb
commonmarker-0.16.4 lib/commonmarker/node.rb
commonmarker-0.16.1 lib/commonmarker/node.rb
commonmarker-0.16.2 lib/commonmarker/node.rb
commonmarker-0.16.3 lib/commonmarker/node.rb
commonmarker-0.16.0 lib/commonmarker/node.rb