Module: Playbook::Markdown::Helper

Included in:
PbDocs::KitExample
Defined in:
lib/playbook/markdown/helper.rb

Instance Method Summary collapse

Instance Method Details

#markdown(text) ⇒ Object



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
39
# File 'lib/playbook/markdown/helper.rb', line 11

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



41
42
43
44
45
# File 'lib/playbook/markdown/helper.rb', line 41

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/playbook/markdown/helper.rb', line 47

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