Class: Daimon::Markdown::Redcarpet::HTMLRenderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Includes:
Rouge::Plugins::Redcarpet
Defined in:
lib/daimon/markdown/redcarpet/html_renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(extensions = {}) ⇒ HTMLRenderer



9
10
11
12
# File 'lib/daimon/markdown/redcarpet/html_renderer.rb', line 9

def initialize(extensions = {})
  super
  @plugins = []
end

Instance Method Details

#postprocess(full_document) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/daimon/markdown/redcarpet/html_renderer.rb', line 20

def postprocess(full_document)
  document = ""
  scanner = StringScanner.new(full_document)
  loop do
    break if scanner.eos?
    if scanner.match?(/{{.+?}}/m)
      document << @plugins.shift
      scanner.pos += scanner.matched_size
    else
      document << scanner.getch
    end
  end
  document
end

#preprocess(full_document) ⇒ Object



14
15
16
17
18
# File 'lib/daimon/markdown/redcarpet/html_renderer.rb', line 14

def preprocess(full_document)
  full_document.scan(/{{.+?}}/m) do |m|
    @plugins << m
  end
end