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

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

Instance Method Summary collapse

Methods inherited from Base

#escape_text, #extract_leading_trailing_whitespace, #extract_title, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/coradoc/html/input/converters/math.rb', line 17

def convert(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(']', '\\]')
    # Handle ((...)) patterns - iterate to avoid polynomial regex
    loop do
      new_stem = stem.gsub(/\(\(([^)]{1,100})\)\)/, '(\\1)')
      break if new_stem == stem

      stem = new_stem
    end
  end

  # NOTE: MathML/LaTeX conversion to AsciiDoc stem format
  # This converts HTML math elements to AsciiDoc's stem:[] macro format
  ' stem:[' << stem << '] '
end

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

FIXIT



13
14
15
# File 'lib/coradoc/html/input/converters/math.rb', line 13

def to_coradoc(node, state = {})
  convert(node, state)
end