Class: Coradoc::Mirror::ReverseBuilder::Figure

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/mirror/reverse_builder.rb

Overview

JS @metanorma/mirror ‘figure` wraps an image plus an optional caption. Reverse: collapse back to a single CoreModel::Image, promoting the caption child to `caption:` if present.

Instance Attribute Summary

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from Base

#apply_mark, #build_content, #build_inline_children, #build_node, #extract_text, #initialize, #inline_content, registers

Constructor Details

This class inherits a constructor from Coradoc::Mirror::ReverseBuilder::Base

Instance Method Details

#build(node) ⇒ Object



356
357
358
359
360
361
362
363
364
# File 'lib/coradoc/mirror/reverse_builder.rb', line 356

def build(node)
  image_child = node.content&.find { |c| c.is_a?(Node) && c.type == 'image' }
  return nil unless image_child

  image = build_node(image_child)
  caption = extract_caption(node)
  image.caption = caption if caption && !image.caption
  image
end