Sha256: c261ee41e1b17818b92b2e48dcd255b640ac424962296d13d5faecd41a6d3fb9

Contents?: true

Size: 1.28 KB

Versions: 82

Compression:

Stored size: 1.28 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 = [
            :source_position,
            :string_content,
            :url,
            :title,
            :header_level,
            :list_type,
            :list_start,
            :list_tight,
            :fence_info,
          ].filter_map do |name|
            [name, __send__(name)]
          rescue StandardError
            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_sibling
              end
              printer.text("children=")
              printer.pp(children)
            end
          end
        end
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
commonmarker-2.1.1-x86_64-linux-musl lib/commonmarker/node/inspect.rb
commonmarker-2.1.1-x86_64-linux lib/commonmarker/node/inspect.rb
commonmarker-2.1.1-arm64-darwin lib/commonmarker/node/inspect.rb
commonmarker-2.1.1-x64-mingw-ucrt lib/commonmarker/node/inspect.rb
commonmarker-2.1.1-x86_64-darwin lib/commonmarker/node/inspect.rb
commonmarker-2.1.1-aarch64-linux-musl lib/commonmarker/node/inspect.rb
commonmarker-2.1.1-aarch64-linux lib/commonmarker/node/inspect.rb
commonmarker-2.1.1 lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-x86_64-linux-musl lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-aarch64-linux-musl lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-x86_64-darwin lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-arm64-darwin lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-x64-mingw-ucrt lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-aarch64-linux lib/commonmarker/node/inspect.rb
commonmarker-2.1.0-x86_64-linux lib/commonmarker/node/inspect.rb
commonmarker-2.1.0 lib/commonmarker/node/inspect.rb
commonmarker-2.0.4-x86_64-darwin lib/commonmarker/node/inspect.rb
commonmarker-2.0.4-arm64-darwin lib/commonmarker/node/inspect.rb
commonmarker-2.0.4-x64-mingw-ucrt lib/commonmarker/node/inspect.rb
commonmarker-2.0.4-aarch64-linux lib/commonmarker/node/inspect.rb