Class: Jekyll::Premonition::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/premonition/processor.rb

Overview

Class that does all of the rendering magic within Premonition.

Instance Method Summary collapse

Constructor Details

#initialize(resources) ⇒ Processor

Returns a new instance of Processor.



8
9
10
# File 'lib/premonition/processor.rb', line 8

def initialize(resources)
  @resources = resources
end

Instance Method Details

#adder(content) ⇒ Object

Called by the registered pre_render hooks.

This function takes markdown content as input and converts all the block quotes, with a Premonition header, into html.

content - Markdown content



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/premonition/processor.rb', line 18

def adder(content)
  o = []
  references = ["\n"]
  b = nil
  is_code_block = false
  content.each_line do |l|
    is_code_block = !is_code_block if code_block_line?(l)
    if is_code_block
      o << l
    elsif blockquote?(l) && empty_block?(b)

      if (m = l.match(/^\s*\>\s+([a-z]+)\s+\"(.*)\"\s+(\[.*\])?\s*$/i))
        y, t, attrs = m.captures
        b = { 'title' => t.strip, 'type' => y.strip.downcase, 'content' => [], 'attrs' => attrs }
      else
        o << l
      end
    elsif blockquote?(l) && !empty_block?(b)
      b['content'] << l.match(/^\s*\>\s?(.*)$/i).captures[0]
    else
      if !blockquote?(l) && !empty_block?(b)
        references = load_references(content)
        o << render_block(b, references)
        b = nil
      end
      o << l
    end
  end
  o << render_block(b, references) unless empty_block?(b)
  o.join
end