Class: Coradoc::Input::Html::Converters::Math

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/html/input/converters/math.rb

Constant Summary collapse

INSTANCE =
new

Instance Method Summary collapse

Methods inherited from Base

#extract_leading_trailing_whitespace, #extract_text_from_content, #extract_title, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#to_coradoc(node, _state = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/coradoc/html/input/converters/math.rb', line 10

def to_coradoc(node, _state = {})
  stem = node.to_s.tr("\n", ' ')
  if Coradoc::Html::Input.config.mathml2asciimath
    require 'plurimath'
    stem = Plurimath::Math.parse(stem, :mathml).to_asciimath
  end

  unless stem.nil?
    stem = stem.gsub('[', '\\[')
    stem = stem.gsub(']', '\\]')
    loop do
      new_stem = stem.gsub(/\(\(([^)]{1,100})\)\)/, '(\\1)')
      break if new_stem == stem

      stem = new_stem
    end
  end

  Coradoc::CoreModel::StemElement.new(
    content: stem,
    stem_type: 'mathml'
  )
end