Sha256: b7fd7aeafe2f3a0a723ed4b3bb7af27bb378c2f3cc5908d25a3ab951411015b1

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'pp'

module CommonMarker
  class Node
    module Inspect
      PP_INDENT_SIZE = 2

      def inspect
        PP.pp(self, +'', Float::INFINITY)
      end

      # @param printer [PrettyPrint] pp
      def pretty_print(printer)
        printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", '>') do
          printer.breakable

          attrs = %i[
            sourcepos
            string_content
            url
            title
            header_level
            list_type
            list_start
            list_tight
            fence_info
          ].map do |name|
            [name, __send__(name)]
          rescue NodeError
            nil
          end.compact

          printer.seplist(attrs) do |name, value|
            printer.text "#{name}="
            printer.pp value
          end

          if first_child
            printer.breakable
            printer.group(PP_INDENT_SIZE) do
              children = []
              node = first_child
              while node
                children << node
                node = node.next
              end
              printer.text 'children='
              printer.pp children
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
commonmarker-0.23.4 lib/commonmarker/node/inspect.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/commonmarker-0.23.2/lib/commonmarker/node/inspect.rb
commonmarker-0.23.2 lib/commonmarker/node/inspect.rb
commonmarker-0.23.1 lib/commonmarker/node/inspect.rb
commonmarker-0.23.0 lib/commonmarker/node/inspect.rb
commonmarker-0.22.0 lib/commonmarker/node/inspect.rb