Module: PersonalBlog::ApplicationHelper

Defined in:
app/helpers/personal_blog/application_helper.rb

Defined Under Namespace

Classes: HTML

Instance Method Summary collapse

Instance Method Details

#markdown(text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/personal_blog/application_helper.rb', line 17

def markdown(text)
  render_options = {
    filter_html: true,
    hard_wrap: true, 
    link_attributes: { rel: 'nofollow', target: "_blank" },
    space_after_headers: true,
    fenced_code_blocks: true,
  }

  extensions = {
    autolink:           true,
    superscript:        true,
    no_intra_emphasis:  true,
    lax_spacing:        true,
    strikethrough:      true,
    fenced_code_blocks: true,
    disable_indented_code_blocks: true
  }

  renderer = HTML.new(render_options)
  markdown = Redcarpet::Markdown.new(renderer, extensions)

  markdown.render(text).html_safe
end