class Minidown::CodeBlockElement

Public Class Methods

new(*_) click to toggle source
Calls superclass method Minidown::Element::new
# File lib/minidown/elements/code_block_element.rb, line 4
def initialize *_
  super
  @code_block_handler = doc.options[:code_block_handler]
end

Public Instance Methods

children_html() click to toggle source
# File lib/minidown/elements/code_block_element.rb, line 29
def children_html
  children.map(&:to_html).join("\n".freeze)
end
lang() click to toggle source
# File lib/minidown/elements/code_block_element.rb, line 25
def lang
  @lang ||= content.empty? ? nil : content
end
parse() click to toggle source
# File lib/minidown/elements/code_block_element.rb, line 9
def parse
  nodes << self
  while(line = unparsed_lines.shift) do
    case line
    when Utils::Regexp[:code_block]
      break
    else
      child = TextElement.new(doc, line)
      child.escape = false
      child.sanitize = @code_block_handler.nil?
      child.convert = false
      children << child
    end
  end
end
to_html() click to toggle source
# File lib/minidown/elements/code_block_element.rb, line 33
def to_html
  if @code_block_handler
    @code_block_handler.call(lang, children_html).to_s
  else
    attr = lang ? {class: lang} : nil
    build_tag 'pre'.freeze do |pre|
      pre << build_tag('code'.freeze, attr){ |code| code << children_html }
    end
  end
end