Class: MDOM::CodeBlock

Inherits:
BlockNode show all
Defined in:
lib/mdom/nodes.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#attributes, #children, #parent, #type

Instance Method Summary collapse

Methods inherited from Node

#[], #ancestors, #append, #children?, #depth, #each_child, #empty?, #find, #find_all, #insert_after, #insert_before, #inspect, #plain_text, #pretty_print, #remove, #replace, #root, #text?, #to_markdown, #walk

Constructor Details

#initialize(literal, lang: nil, fenced: true, attributes: {}) ⇒ CodeBlock

lang: language string (may be nil), fenced: true/false, literal: source text



81
82
83
84
85
86
87
# File 'lib/mdom/nodes.rb', line 81

def initialize(literal, lang: nil, fenced: true, attributes: {})
  attrs = { fenced: fenced }.merge(attributes)
  attrs[:lang] = lang unless lang.nil?
  super(Types::CODE_BLOCK, attributes: attrs)
  # Code block text is kept as a raw string, not child nodes.
  @literal = literal
end

Instance Attribute Details

#literalObject (readonly)

Returns the value of attribute literal.



89
90
91
# File 'lib/mdom/nodes.rb', line 89

def literal
  @literal
end

Instance Method Details

#fenced?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/mdom/nodes.rb', line 95

def fenced?
  attributes[:fenced]
end

#langObject



91
92
93
# File 'lib/mdom/nodes.rb', line 91

def lang
  attributes[:lang]
end

#to_sObject



99
100
101
# File 'lib/mdom/nodes.rb', line 99

def to_s
  "#<MDOM::CodeBlock fenced=#{fenced?} lang=#{lang.inspect}>"
end