Module: Metanorma::Mirror::Handlers::Formula

Defined in:
lib/metanorma/mirror/handlers/formula.rb

Constant Summary collapse

EXTRA =
{ unnumbered: nil, inequality: nil }.freeze

Class Method Summary collapse

Class Method Details

.call(element, context:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/metanorma/mirror/handlers/formula.rb', line 9

def self.call(element, context:)
  attrs = Handlers.extract_attrs(element, extra_attrs: EXTRA)

  stem = SafeAttr.read(element, :stem)
  if stem
    attrs[:stem_type] = SafeAttr.read(stem, :stem_type)

    asciimath = SafeAttr.read(stem, :asciimath)
    if asciimath&.value && !asciimath.value.strip.empty?
      attrs[:asciimath] =
        asciimath.value
    end

    math = SafeAttr.read(stem, :math)
    attrs[:mathml] = MathUtil.mathml_from_math(math) if math
  end

  # Legacy fallback: some older documents store text directly
  text = SafeAttr.read(element, :text)
  attrs[:math_text] = Array(text).join if text && !attrs[:asciimath]

  Handlers.build_node("formula", attrs: attrs.compact)
end