Module: Playbook::Markdown::Helper

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

Defined Under Namespace

Classes: HTML

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(template, _source) ⇒ Object



11
12
13
# File 'lib/playbook/markdown/helper.rb', line 11

def self.call(template, _source)
  markdown(template.source)
end

.markdown(text) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/playbook/markdown/helper.rb', line 21

def self.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 = {
    lax_spacing: true,
    no_intra_emphasis: true,
    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)
  # toc_renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true)
  # @TOC = Redcarpet::Markdown.new(toc_renderer)
  # puts "TOC: #{@TOC.inspect}"
  markdown = Redcarpet::Markdown.new(renderer, extensions)
  "#{markdown.render(text).inspect}.html_safe;"
end

Instance Method Details

#render_markdown(text) ⇒ Object



15
16
17
18
19
# File 'lib/playbook/markdown/helper.rb', line 15

def render_markdown(text)
  # rubocop:disable Security/Eval
  eval(Playbook::Markdown::Helper.markdown(text))
  # rubocop:enable Security/Eval
end

#rouge(text, language) ⇒ Object



55
56
57
58
59
# File 'lib/playbook/markdown/helper.rb', line 55

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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/playbook/markdown/helper.rb', line 65

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