Sha256: 22badd964465466a458edb4cb70a8a6ed4c91f2dd397232c919f8805f8c5e8bd

Contents?: true

Size: 1.27 KB

Versions: 12

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'pp'

module Markly
  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[
            source_position
            string_content
            url
            title
            header_level
            list_type
            list_start
            list_tight
            fence_info
          ].map do |name|
            begin
              [name, __send__(name)]
            rescue Error
              nil
            end
          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

12 entries across 12 versions & 1 rubygems

Version Path
markly-0.7.0 lib/markly/node/inspect.rb
markly-0.6.1 lib/markly/node/inspect.rb
markly-0.6.0 lib/markly/node/inspect.rb
markly-0.5.2 lib/markly/node/inspect.rb
markly-0.5.1 lib/markly/node/inspect.rb
markly-0.5.0 lib/markly/node/inspect.rb
markly-0.4.0 lib/markly/node/inspect.rb
markly-0.3.0 lib/markly/node/inspect.rb
markly-0.2.2 lib/markly/node/inspect.rb
markly-0.2.1 lib/markly/node/inspect.rb
markly-0.2.0 lib/markly/node/inspect.rb
markly-0.1.0 lib/markly/node/inspect.rb