Class: Monograph::MarkdownRenderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/monograph/markdown_renderer.rb

Instance Method Summary collapse

Instance Method Details

#block_code(code, language) ⇒ Object



4
5
6
# File 'lib/monograph/markdown_renderer.rb', line 4

def block_code(code, language)
  Pygments.highlight(code, :lexer => language)
end

#image(src, title, alt) ⇒ Object

Images need positioning ability



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/monograph/markdown_renderer.rb', line 18

def image(src, title, alt)
  if alt.gsub!(/\*([\w\-\s]+)\z/, '')
    klass = "imgcontainer #{$1}"
  else
    klass = nil
  end
  String.new.tap do |s|
    s << "<span class='#{klass}'>"
    if klass == "imgcontainer captioned"
      s << "<span class='image'><img src='#{src}' title='#{title}' alt='#{alt}'></span>"
      s << "<span class='caption'>#{alt}</span>"
    else
      s << "<img src='#{src}' title='#{title}' alt='#{alt}'>"
    end
    s << "</span>"
  end
end

#paragraph(text) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/monograph/markdown_renderer.rb', line 8

def paragraph(text)
  klass = ''
  text.gsub!(/\A\[([A-Z]+)\]/) do
    klass = " class='#{$1.downcase}'"
    ''
  end
  "<p#{klass}>#{text}</p>"
end