Class: Forest::MarkdownRenderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
app/classes/forest/markdown_renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionsObject



2
3
4
5
6
7
8
9
# File 'app/classes/forest/markdown_renderer.rb', line 2

def self.options
  {
    autolink: true,
    no_intra_emphasis: true,
    tables: true,
    space_after_headers: true
  }
end

.render_optionsObject



11
12
13
14
15
16
# File 'app/classes/forest/markdown_renderer.rb', line 11

def self.render_options
  {
    hard_wrap: true,
    safe_links_only: true
  }
end

Instance Method Details

#postprocess(full_document) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/classes/forest/markdown_renderer.rb', line 18

def postprocess(full_document)
  return full_document if full_document.blank?

  begin
    without_leading_trailing_paragraphs = Regexp.new(/\A<p>(.*)<\/p>\Z/mi).match(full_document)[1]
    unless without_leading_trailing_paragraphs.include?('<p>')
      full_document = without_leading_trailing_paragraphs
    end
  rescue StandardError => e
  end

  Redcarpet::Render::SmartyPants.render(full_document)
end