Module: Coradoc::Mirror::Handlers::Image

Defined in:
lib/coradoc/mirror/handlers/image.rb

Overview

Image handler.

Two emission shapes:

- Ruby legacy (default): bare `image` node, title/caption in attrs.
- JS @metanorma/mirror (`partition_structural: true`): when the
  source image has a title, wrap it in a `figure` node with the
  image plus a `caption` child, matching the JS schema.

Class Method Summary collapse

Class Method Details

.call(element, context:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coradoc/mirror/handlers/image.rb', line 14

def self.call(element, context:)
  image_node = build_image_node(element)

  return image_node unless context.partition_structural
  return image_node unless caption_text?(element)

  Node::Figure.new(
    attrs: Node::Figure::Attrs.new(id: element.id, title: caption_value(element)),
    content: [image_node, Node::Caption.new(content: caption_text_nodes(element, context))]
  )
end