Module: Playbook::RedcarpetHelper

Defined in:
app/helpers/playbook/redcarpet_helper.rb

Instance Method Summary collapse

Instance Method Details

#markdown(text) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/playbook/redcarpet_helper.rb', line 10

def markdown(text)
  options = {
    filter_html: false,
    hard_wrap: true,
    link_attributes: { rel: "nofollow", target: "_blank" },
    space_after_headers: true,
    fenced_code_blocks: true,
    no_styles: false,
    safe_links_only: true,
  }

  extensions = {
    autolink: true,
    superscript: true,
    fenced_code_blocks: true,
    tables: true,
    disable_indented_code_blocks: false,
    strikethrough: true,
    underline: true,
    highlight: true,
    footnotes: true,
    with_toc_data: true,
  }

  renderer = HTMLBlockCode.new(options)
  markdown = Redcarpet::Markdown.new(renderer, extensions)

  markdown.render(text).html_safe
end

#rouge(text, language) ⇒ Object



40
41
42
43
44
# File 'app/helpers/playbook/redcarpet_helper.rb', line 40

def rouge(text, language)
  formatter = Rouge::Formatters::HTML.new(scope: ".highlight")
  lexer = Rouge::Lexer.find(language)
  formatter.format(lexer.lex(text))
end

#rouge_markdown(text) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/playbook/redcarpet_helper.rb', line 46

def rouge_markdown(text)
  render_options = {
    filter_html: true,
    hard_wrap: true,
    link_attributes: { rel: "nofollow" },
  }
  renderer = HTML.new(render_options)

  extensions = {
    autolink: true,
    fenced_code_blocks: true,
    lax_spacing: true,
    no_intra_emphasis: true,
    strikethrough: true,
    superscript: true,
  }
  markdown = Redcarpet::Markdown.new(renderer, extensions)
  markdown.render(text)
end