plurimath 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04338f1ee3f1e78d5383c40bb04b3d3b48c11d04180eefaa0eafeb7ae2980efc'
4
- data.tar.gz: 912bd2f8fa6d6bcfddc287214f06d537bb7084c7bd82945a7b57e981fc0943ab
3
+ metadata.gz: 10dc48ba50b0b3ace7230a0dc8c55ea8fa208e1b8e124cbbf19e2b081ddb6918
4
+ data.tar.gz: 36aa56b4193aa367343195e33160d5213dbd3efe9655b110a387b5fa84374e22
5
5
  SHA512:
6
- metadata.gz: 4bbf747cf01f27e17fa1ea5b4138f59b5978f0cfcb493caaf3cb96885d2d36b42aa2bd6893ce1da8c302daaa80334c1b35a2283e7b6a3296d82b17b577700364
7
- data.tar.gz: 01d79594d56773f04dee88a5830f5ae39087d034975566dffb6db4b64e853c517ed596f8951b5b64b391f5df96e7607b026e114a05fabbee19929f2a4d7dd69c
6
+ metadata.gz: 59b85358ee2f0de5f345a0179aca97243483aa5d31e0a7a858ef4c9421ce546d9a9ee72094a4306c704b350d7caa80315bc331b7e8d500ffbf0175a0d1c859b5
7
+ data.tar.gz: c3ada4b68b411110f533dfb2297f9d0f9cad47200a5b39475b300c9f1687b18ed5e199fd12b5d8d0f3ff971ae1790187d28629e162eba14edd575aafeab1ee74
@@ -1117,6 +1117,12 @@ module Plurimath
1117
1117
  Math::Function::Text.new(text)
1118
1118
  end
1119
1119
 
1120
+ rule(lparen: simple(:lparen),
1121
+ text: sequence(:text),
1122
+ rparen: simple(:rparen)) do
1123
+ Math::Function::Text.new(text.flatten.compact.join)
1124
+ end
1125
+
1120
1126
  rule(lparen: simple(:lparen),
1121
1127
  rgb_color: sequence(:color),
1122
1128
  rparen: simple(:rparen)) do
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "binary_function"
4
+
5
+ module Plurimath
6
+ module Math
7
+ module Function
8
+ class Semantics < BinaryFunction
9
+ def to_mathml_without_math_tag
10
+ first_value = parameter_one&.to_mathml_without_math_tag
11
+ second_value = other_tags(parameter_two)
12
+ Utility.update_nodes(
13
+ Utility.ox_element("semantics"),
14
+ second_value.insert(0, first_value),
15
+ )
16
+ end
17
+
18
+ def to_latex
19
+ parameter_one&.to_latex
20
+ end
21
+
22
+ def to_asciimath
23
+ parameter_one&.to_asciimath
24
+ end
25
+
26
+ protected
27
+
28
+ def other_tags(array)
29
+ contented = []
30
+ array&.each do |hash|
31
+ hash.each do |tag, content|
32
+ tag_element = Utility.ox_element(tag&.to_s)
33
+ contented << Utility.update_nodes(
34
+ tag_element,
35
+ content&.map(&:to_mathml_without_math_tag),
36
+ )
37
+ end
38
+ end
39
+ contented
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -42,9 +42,9 @@ module Plurimath
42
42
  "&#x3a8;": "Psi",
43
43
  "&#x3c9;": "omega",
44
44
  "&#x3a9;": "omega",
45
- "&#x22c5;": "dot",
45
+ "&#x22c5;": "cdot",
46
46
  "&#x2219;": "*",
47
- "&#xb7;": ".",
47
+ "&#x2e;": ".",
48
48
  "&#x2217;": "**",
49
49
  "&#x22c6;": "***",
50
50
  "&#xd7;": "xx",
@@ -6,6 +6,7 @@ module Plurimath
6
6
  class Mathml
7
7
  class Parser
8
8
  attr_accessor :text
9
+ SUPPORTED_ATTRIBUTES = %w[columnlines mathvariant mathcolor notation close open].freeze
9
10
 
10
11
  def initialize(text)
11
12
  @text = text
@@ -28,7 +29,7 @@ module Plurimath
28
29
  elsif !node.attributes.empty?
29
30
  {
30
31
  node.name.to_sym => {
31
- attributes: node.attributes.transform_keys(&:to_sym),
32
+ attributes: validate_attributes(node.attributes),
32
33
  value: parse_nodes(node.nodes),
33
34
  },
34
35
  }
@@ -37,6 +38,11 @@ module Plurimath
37
38
  end
38
39
  end
39
40
  end
41
+
42
+ def validate_attributes(attributes)
43
+ attributes&.select! { |key, _| SUPPORTED_ATTRIBUTES.include?(key&.to_s) }
44
+ attributes&.transform_keys(&:to_sym) if attributes&.any?
45
+ end
40
46
  end
41
47
  end
42
48
  end
@@ -6,13 +6,9 @@ module Plurimath
6
6
  rule(mi: simple(:mi)) { mi }
7
7
  rule(mo: simple(:mo)) { mo }
8
8
  rule(mo: sequence(:mo)) { Utility.mathml_unary_classes(mo) }
9
- rule(xref: simple(:xref)) { nil }
10
9
  rule(mtd: sequence(:mtd)) { Math::Function::Td.new(mtd) }
11
10
  rule(mtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
12
- rule(accent: simple(:acc)) { nil }
13
11
  rule(none: sequence(:none)) { nil }
14
- rule(maxsize: simple(:att)) { nil }
15
- rule(minsize: simple(:att)) { nil }
16
12
  rule(notation: simple(:att)) { Math::Function::Menclose.new(att) }
17
13
  rule(mtable: simple(:table)) { table }
18
14
  rule(msqrt: sequence(:sqrt)) { Math::Function::Sqrt.new(sqrt.first) }
@@ -25,7 +21,6 @@ module Plurimath
25
21
  rule(mfenced: simple(:mfenced)) { mfenced }
26
22
  rule(mtable: sequence(:mtable)) { Math::Function::Table.new(mtable) }
27
23
  rule(mscarry: sequence(:scarry)) { nil }
28
- rule(displaystyle: simple(:att)) { nil }
29
24
  rule(menclose: simple(:enclose)) { enclose }
30
25
  rule(mlabeledtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
31
26
  rule(mpadded: sequence(:padded)) { Utility.filter_values(padded) }
@@ -204,10 +199,10 @@ module Plurimath
204
199
  )
205
200
  end
206
201
 
207
- rule(mtext: sequence(:mtext)) do
202
+ rule(mtext: subtree(:mtext)) do
208
203
  entities = HTMLEntities.new
209
204
  symbols = Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
210
- text = entities.encode(mtext.first, :hexadecimal)
205
+ text = entities.encode(mtext.flatten.join, :hexadecimal)
211
206
  symbols.each do |code, string|
212
207
  text.gsub!(code.downcase, "unicode[:#{string}]")
213
208
  end
@@ -227,7 +222,7 @@ module Plurimath
227
222
  rule(mfenced: sequence(:fenced)) do
228
223
  Math::Function::Fenced.new(
229
224
  Math::Symbol.new("("),
230
- fenced,
225
+ fenced.compact,
231
226
  Math::Symbol.new(")"),
232
227
  )
233
228
  end
@@ -281,14 +276,21 @@ module Plurimath
281
276
 
282
277
  rule(attributes: simple(:attrs),
283
278
  value: subtree(:value)) do
284
- Utility.join_attr_value(attrs, value.flatten)
279
+ Utility.join_attr_value(attrs, value&.flatten&.compact)
280
+ end
281
+
282
+ rule(semantics: subtree(:value)) do
283
+ Math::Function::Semantics.new(
284
+ value.shift,
285
+ value,
286
+ )
285
287
  end
286
288
 
287
289
  rule(attributes: subtree(:attrs),
288
290
  value: sequence(:value)) do
289
291
  Utility.join_attr_value(
290
292
  attrs.is_a?(Hash) ? nil : attrs,
291
- value.flatten,
293
+ value&.flatten.compact,
292
294
  )
293
295
  end
294
296
  end
@@ -315,7 +315,7 @@ module Plurimath
315
315
  attrs.parameter_two = filter_values(value)
316
316
  attrs
317
317
  elsif attrs.is_a?(Math::Function::Fenced)
318
- attrs.parameter_two = value
318
+ attrs.parameter_two = value.compact
319
319
  attrs
320
320
  elsif attrs.is_a?(Math::Function::FontStyle)
321
321
  attrs.parameter_one = filter_values(value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plurimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-13 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -158,6 +158,7 @@ files:
158
158
  - lib/plurimath/math/function/scarry.rb
159
159
  - lib/plurimath/math/function/sec.rb
160
160
  - lib/plurimath/math/function/sech.rb
161
+ - lib/plurimath/math/function/semantics.rb
161
162
  - lib/plurimath/math/function/sin.rb
162
163
  - lib/plurimath/math/function/sinh.rb
163
164
  - lib/plurimath/math/function/sqrt.rb