Class: GfmToBlockkit::Converters::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/gfm_to_blockkit/converters/image.rb

Constant Summary collapse

MAX_ALT_TEXT_LENGTH =
2000

Instance Method Summary collapse

Methods inherited from Base

#convert, converter_for, handles, #initialize, #render_child_as_elements

Constructor Details

This class inherits a constructor from GfmToBlockkit::Converters::Base

Instance Method Details

#convert_node(node) ⇒ Object

Called by Paragraph converter for standalone images.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gfm_to_blockkit/converters/image.rb', line 9

def convert_node(node)
  return [] unless node

  alt = plain_text_from(node)
  alt = "image" if alt.strip.empty?
  alt = alt[0, MAX_ALT_TEXT_LENGTH] if alt.length > MAX_ALT_TEXT_LENGTH

  block = {
    type: "image",
    image_url: node.url,
    alt_text: alt
  }

  title = node.title
  if title && !title.strip.empty?
    block[:title] = {type: "plain_text", text: title}
  end

  [block]
end