Class: Nexmo::Markdown::VoltaRender

Inherits:
HTML
  • Object
show all
Includes:
Concerns::PrismCodeSnippet
Defined in:
lib/nexmo_markdown_renderer/filters/markdown_filter.rb

Instance Method Summary collapse

Methods included from Concerns::PrismCodeSnippet

#code_language_to_prism, #code_snippet_body, #prism_css_classes

Constructor Details

#initialize(options) ⇒ VoltaRender

Returns a new instance of VoltaRender.



33
34
35
36
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 33

def initialize(options)
  @options = options
  super(options)
end

Instance Method Details

#block_code(code, language) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 83

def block_code(code, language)
  lexer = ::Rouge::Lexer.find_fancy(language, code) || ::Rouge::Lexers::PlainText

  # XXX HACK: Redcarpet strips hard tabs out of code blocks,
  # so we assume you're not using leading spaces that aren't tabs,
  # and just replace them here.
  if lexer.tag == 'make'
    code.gsub! /^    /, "\t"
  end

  formatter ||= Rouge::Formatters::HTML.new
  highlighted_source = formatter.format(lexer.lex(code))

  code_snippet_body(lexer, highlighted_source, @options)
end

#block_quote(quote) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 53

def block_quote(quote)
  '<div class="Vlt-callout Vlt-callout--tip">' \
    '<i></i>' \
    '<div class="Vlt-callout__content">' \
      "#{quote}" \
    '</div>' \
  '</div>'
end

#image(link, _title, _alt_text) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 62

def image(link, _title, _alt_text)
  <<~IMAGE
    <figure>
      <img src="#{link}" alt="#{_alt_text}">
      <figcaption class="Vlt-center"><em>#{_alt_text}</em></figcaption>
    </figure>
  IMAGE
end

#list(contents, list_type) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 71

def list(contents, list_type)
  if "#{list_type}" == 'unordered'
    '<ul class="Vlt-list Vlt-list--simple">' \
    "#{contents}" \
    '</ul>'
  else
    '<ol class="Vlt-list Vlt-list--simple">' \
    "#{contents}" \
    '</ol>' \
  end
end

#paragraph(text) ⇒ Object



38
39
40
41
42
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 38

def paragraph(text)
  return text if @options[:skip_paragraph_surround]

  "<p>#{text}</p>"
end

#table(header, body) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/nexmo_markdown_renderer/filters/markdown_filter.rb', line 44

def table(header, body)
  '<div class="Vlt-table Vlt-table--bordered">' \
  '<table>' \
    "<thead>#{header}</thead>" \
    "<tbody>#{body}</tbody>" \
  '</table>' \
  '</div>'
end