Module: CommonMarker::Node::Inspect

Included in:
CommonMarker::Node
Defined in:
lib/commonmarker/node/inspect.rb

Constant Summary collapse

PP_INDENT_SIZE =
2

Instance Method Summary collapse

Instance Method Details

#inspectObject



10
11
12
# File 'lib/commonmarker/node/inspect.rb', line 10

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

#pretty_print(pp) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/commonmarker/node/inspect.rb', line 15

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