Class: UltraMarkdown::MarkdownProcessor

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ultra_markdown.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMarkdownProcessor

Returns a new instance of MarkdownProcessor.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ultra_markdown.rb', line 32

def initialize
  options = {
    :autolink => true,
    :strikethrough => true,
    :space_after_headers => false,
    :tables => true,
    :lax_spacing => true,
    :no_intra_emphasis => true,
    :footnotes => true
  }

  @converter = Redcarpet::Markdown.new(HTMLforPost.new, options)
  @converter_for_rss = Redcarpet::Markdown.new(HTMLforRSS.new, options)
end

Class Method Details

.compile(raw) ⇒ Object



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

def self.compile(raw)
  self.instance.format(raw)
end

.compile_for_rss(raw) ⇒ Object



51
52
53
# File 'lib/ultra_markdown.rb', line 51

def self.compile_for_rss(raw)
  self.instance.format(raw, true)
end

Instance Method Details

#format(raw, is_rss = false) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ultra_markdown.rb', line 56

def format(raw, is_rss = false)
  text = raw.clone
  return '' if text.blank?

  result = if is_rss
    @converter_for_rss.render(text)
  else
    @converter.render(text)
  end

  #result = Modules::ResultSanitize.clean(result)

  doc = Nokogiri::HTML.fragment(result)

  return doc.to_html
rescue => e
  Airbrake.notify(e)
  puts "MarkdownTopicConverter.format ERROR: #{e}"
  return text
end