Class: Ecrire::Markdown::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ecrire/markdown/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Document

Returns a new instance of Document.



9
10
11
12
13
# File 'lib/ecrire/markdown/document.rb', line 9

def initialize(content)
  @nodes = content.lines.map do |text|
    Node.new(text.chomp)
  end
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



7
8
9
# File 'lib/ecrire/markdown/document.rb', line 7

def nodes
  @nodes
end

Instance Method Details

#parse!Object



26
27
28
29
30
# File 'lib/ecrire/markdown/document.rb', line 26

def parse!
  parsers.each do |parser|
    parser.parse!(self)
  end
end

#parsersObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/ecrire/markdown/document.rb', line 15

def parsers
  [
    Ecrire::Markdown::Parsers::Code,
    Ecrire::Markdown::Parsers::Heading,
    Ecrire::Markdown::Parsers::Image,
    Ecrire::Markdown::Parsers::List,
    Ecrire::Markdown::Parsers::Word,
    Ecrire::Markdown::Parsers::Link
  ]
end

#to_htmlObject



32
33
34
35
36
37
38
39
40
# File 'lib/ecrire/markdown/document.rb', line 32

def to_html
  @nodes.map do |node|
    if node.instance_of?(Ecrire::Markdown::Node)
      "<p>#{node.to_s}</p>"
    else
      node.to_s
    end
  end.join
end