lib/plurimath/math/function/text.rb in plurimath-0.8.17 vs lib/plurimath/math/function/text.rb in plurimath-0.8.18
- old
+ new
@@ -1,16 +1,23 @@
# frozen_string_literal: true
require "htmlentities"
require_relative "unary_function"
+require_relative "../../mathml/utility"
module Plurimath
module Math
module Function
class Text < UnaryFunction
+ include Mathml::Utility
+
PARSER_REGEX = %r{unicode\[:(?<unicode>\w{1,})\]}.freeze
+ def initialize(parameter_one = "")
+ super(parameter_one)
+ end
+
def to_asciimath(**)
"\"#{parse_text('asciimath') || parameter_one}\""
end
def to_mathml_without_math_tag(intent, **)
@@ -65,15 +72,28 @@
def to_omml_math_zone(spacing, _, _, display_style:, options:)
"#{spacing}\"#{dump_omml(self, display_style, options: options)}\" text\n"
end
+ def to_unicodemath_math_zone(spacing, _, _, options:)
+ "#{spacing}#{to_unicodemath(options: options)} text\n"
+ end
+
def value
parameter_one
end
- def to_unicodemath_math_zone(spacing, _, _, options:)
- "#{spacing}#{to_unicodemath(options: options)} text\n"
+ def element_order=(*); end
+
+ def value=(text)
+ text = text.join if text.is_a?(Array)
+ entities = HTMLEntities.new
+ symbols = Mathml::Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
+ text = entities.encode(text, :hexadecimal)
+ symbols.each do |code, string|
+ text = text.gsub(code.downcase, "unicode[:#{string}]")
+ end
+ self.parameter_one = text
end
protected
def symbol_value(unicode)