Class: PREParser

Inherits:
Parser show all
Defined in:
lib/Parsers/PREParser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#setNext

Constructor Details

#initialize(isForJekyll) ⇒ PREParser

Returns a new instance of PREParser.



9
10
11
# File 'lib/Parsers/PREParser.rb', line 9

def initialize(isForJekyll)
    @isForJekyll = isForJekyll
end

Instance Attribute Details

#isForJekyllObject

Returns the value of attribute isForJekyll.



7
8
9
# File 'lib/Parsers/PREParser.rb', line 7

def isForJekyll
  @isForJekyll
end

#nextParserObject

Returns the value of attribute nextParser.



7
8
9
# File 'lib/Parsers/PREParser.rb', line 7

def nextParser
  @nextParser
end

Class Method Details

.isPRE(paragraph) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/Parsers/PREParser.rb', line 13

def self.isPRE(paragraph)
    if paragraph.nil? 
        false
    else
        paragraph.type == "PRE"
    end
end

Instance Method Details

#parse(paragraph) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/Parsers/PREParser.rb', line 21

def parse(paragraph)
    if PREParser.isPRE(paragraph)
        
        lang = ""
        if !paragraph..nil?
            lang = paragraph..lang
        end

        result = "```#{lang}\n"
        
        paragraph.text.each_line do |p|
            result += p
        end

        result = result.chomp
        result += "\n```"

        result
    else
        if !nextParser.nil?
            nextParser.parse(paragraph)
        end
    end
end