Sha256: b1d492e137638f6085a3424c83b56e8a53b7340a4dbf5863b0864ea6e69f4d8d

Contents?: true

Size: 1.22 KB

Versions: 32

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'pp'

module CommonMarker
  class Node
    module Inspect
      PP_INDENT_SIZE = 2

      def inspect
        PP.pp(self, String.new, Float::INFINITY)
      end

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

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

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

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

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
commonmarker-0.20.2 lib/commonmarker/node/inspect.rb
commonmarker-0.20.1 lib/commonmarker/node/inspect.rb
commonmarker-0.20.0 lib/commonmarker/node/inspect.rb
commonmarker-0.19.0 lib/commonmarker/node/inspect.rb
commonmarker-0.18.2 lib/commonmarker/node/inspect.rb
commonmarker-0.18.1 lib/commonmarker/node/inspect.rb
commonmarker-0.18.0 lib/commonmarker/node/inspect.rb
commonmarker-0.17.13 lib/commonmarker/node/inspect.rb
commonmarker-0.17.12 lib/commonmarker/node/inspect.rb
commonmarker-0.17.11 lib/commonmarker/node/inspect.rb
commonmarker-0.17.10 lib/commonmarker/node/inspect.rb
tdiary-5.0.8 vendor/bundle/gems/commonmarker-0.17.9/lib/commonmarker/node/inspect.rb
commonmarker-0.17.9 lib/commonmarker/node/inspect.rb
commonmarker-0.17.8 lib/commonmarker/node/inspect.rb
commonmarker-0.17.7.1 lib/commonmarker/node/inspect.rb
commonmarker-0.17.7 lib/commonmarker/node/inspect.rb
commonmarker-0.17.6 lib/commonmarker/node/inspect.rb
commonmarker-0.17.5 lib/commonmarker/node/inspect.rb
commonmarker-0.17.4 lib/commonmarker/node/inspect.rb
commonmarker-0.17.2 lib/commonmarker/node/inspect.rb