Class: Ecrire::Markdown::Nodes::CodeBlock

Inherits:
Ecrire::Markdown::Node show all
Defined in:
lib/ecrire/markdown/nodes/code_block.rb

Instance Attribute Summary

Attributes inherited from Ecrire::Markdown::Node

#content

Instance Method Summary collapse

Constructor Details

#initialize(language, title, nodes) ⇒ CodeBlock

Returns a new instance of CodeBlock.



6
7
8
9
10
# File 'lib/ecrire/markdown/nodes/code_block.rb', line 6

def initialize(language, title, nodes)
  @content = ERB::Util.html_escape(nodes.join("\n"))
  @title = title
  @language = language
end

Instance Method Details

#to_sObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ecrire/markdown/nodes/code_block.rb', line 12

def to_s
  str = "<pre>"
  str << "<header>#{@title}</header>"

  str << "<code"

  unless @language.nil?
    str << " class='language-#{@language}'>"
  end


  str << @content
  str << "</code></pre>"
  str
end