Class: Downr::Markdown

Inherits:
Object
  • Object
show all
Defined in:
lib/downr/markdown.rb

Overview

This class is a wrapper for the render method on Redcarpet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMarkdown

Creates a new Markdown object



19
20
21
22
23
24
25
# File 'lib/downr/markdown.rb', line 19

def initialize
  @@options = Downr.configuration.options
  
  render  = Render.new(@@options)

  @@renderer = Redcarpet::Markdown.new(render, @@options)
end

Instance Attribute Details

#rendererRedcarpet::Markdown

Returns the current value of renderer.

Returns:

  • (Redcarpet::Markdown)

    the current value of renderer



9
10
11
# File 'lib/downr/markdown.rb', line 9

def renderer
  @renderer
end

Class Method Details

.render(text) ⇒ String

Renders markdown

Parameters:

  • text (String)

Returns:

  • (String)

    html



31
32
33
34
35
36
37
38
39
# File 'lib/downr/markdown.rb', line 31

def self.render text 
  html = @@renderer.render(text)
  
  if(@@options[:sanitize_html].present? && @@options[:sanitize_html])
    html = self.sanitize_html(html)
  end
  
  html
end

.sanitize_html(html) ⇒ String

Sanitizes html input removing tags that are considered "unsafe"

Parameters:

  • html (String)

Returns:

  • (String)

    html



47
48
49
# File 'lib/downr/markdown.rb', line 47

def self.sanitize_html(html)
  HTML::Pipeline::SanitizationFilter.new(html).call.to_s
end