Module: Markly::Node::Inspect
- Included in:
- Markly::Node
- Defined in:
- lib/markly/node/inspect.rb
Overview
Provides concise pretty-printing for Markdown nodes.
Constant Summary collapse
- PP_INDENT_SIZE =
2
Instance Method Summary collapse
-
#inspect ⇒ Object
Returns a pretty-printed representation of the node.
-
#pretty_print(printer) ⇒ Object
Pretty-print this node and its children.
Instance Method Details
#inspect ⇒ Object
Returns a pretty-printed representation of the node.
21 22 23 |
# File 'lib/markly/node/inspect.rb', line 21 def inspect PP.pp(self, +"", Float::INFINITY) end |
#pretty_print(printer) ⇒ Object
Pretty-print this node and its children.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/markly/node/inspect.rb', line 28 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 code_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 |