Class: SlideEmUp::Markdown

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/slide-em-up/markdown.rb

Constant Summary collapse

PARSER_OPTIONS =
{
  :no_intra_emphasis  => true,
  :tables             => true,
  :fenced_code_blocks => true,
  :autolink           => true,
  :strikethrough      => true,
  :superscript        => true
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render(text) ⇒ Object



17
18
19
20
21
# File 'lib/slide-em-up/markdown.rb', line 17

def self.render(text)
  text ||= ""
  markdown = Redcarpet::Markdown.new(self, PARSER_OPTIONS)
  markdown.render(text)
end

Instance Method Details

#block_code(code, lang) ⇒ Object



23
24
25
26
# File 'lib/slide-em-up/markdown.rb', line 23

def block_code(code, lang)
  colorized = Pygments.highlight(code, :lexer => lang || "text", :options => {:nowrap => true})
  "<pre><code class=\"#{lang}\">#{colorized}</code></pre>"
end

#normal_text(text) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/slide-em-up/markdown.rb', line 32

def normal_text(text)
  text.gsub!('« ', '«&nbsp;')
  text.gsub!(/ ([:;»!?])/, '&nbsp;\1')
  text.gsub!(' -- ', '')
  text.gsub!('...', '')
  text
end

#strikethrough(text) ⇒ Object



28
29
30
# File 'lib/slide-em-up/markdown.rb', line 28

def strikethrough(text)
  "<s>#{text}</s>"
end