Class: TipTap::Nodes::Image

Inherits:
TipTap::Node show all
Defined in:
lib/tip_tap/nodes/image.rb

Instance Attribute Summary

Attributes included from HtmlRenderable

#output_buffer

Attributes included from HasContent

#attrs, #content

Instance Method Summary collapse

Methods included from PlainTextRenderable

#to_plain_text

Methods included from JsonRenderable

#to_h

Methods included from HtmlRenderable

#html_attributes, #html_class_name, #html_tag, included, #inline_styles

Methods included from HasContent

#add_content, #blank?, #each, #find_node, included, #initialize, #size

Methods included from Registerable

included, #type_name

Instance Method Details

#altObject



27
28
29
# File 'lib/tip_tap/nodes/image.rb', line 27

def alt
  attrs["alt"]
end

#include_empty_content_in_json?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/tip_tap/nodes/image.rb', line 10

def include_empty_content_in_json?
  false
end

#srcObject



31
32
33
# File 'lib/tip_tap/nodes/image.rb', line 31

def src
  attrs["src"]
end

#to_htmlObject



14
15
16
# File 'lib/tip_tap/nodes/image.rb', line 14

def to_html
  image_tag(src, alt: alt)
end

#to_markdown(context = Markdown::Context.root) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/tip_tap/nodes/image.rb', line 18

def to_markdown(context = Markdown::Context.root)
  return "" if src.blank?

  alt_text = alt.to_s
  escaped_alt = alt_text.gsub("[", "\\[").gsub("]", "\\]")
  escaped_src = src.to_s.gsub("(", "\\(").gsub(")", "\\)")
  "![#{escaped_alt}](#{escaped_src})"
end