Class: Plurimath::Mathml::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/mathml/parser.rb

Constant Summary collapse

SUPPORTED_ATTRS =
%w[
  linebreakstyle
  linethickness
  columnlines
  mathvariant
  accentunder
  separators
  linebreak
  mathcolor
  notation
  bevelled
  rowlines
  intent
  accent
  height
  frame
  depth
  height
  width
  index
  close
  alt
  src
  open
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



36
37
38
# File 'lib/plurimath/mathml/parser.rb', line 36

def initialize(text)
  @text = text
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/plurimath/mathml/parser.rb', line 8

def text
  @text
end

Instance Method Details

#parseObject



40
41
42
43
44
45
46
47
48
# File 'lib/plurimath/mathml/parser.rb', line 40

def parse
  ox_nodes = Plurimath.xml_engine.load(text)
  display_style = ox_nodes&.locate("mstyle/@displaystyle")&.first
  nodes = parse_nodes(Array(ox_nodes))
  Math::Formula.new(
    Transform.new.apply(nodes).flatten.compact,
    display_style: (display_style || true),
  )
end