mml 2.2.0 → 2.3.0

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.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +14 -4
  3. data/CLAUDE.md +79 -0
  4. data/README.adoc +226 -83
  5. data/lib/mml/base/deprecated_font_attributes.rb +31 -0
  6. data/lib/mml/base/maction.rb +28 -0
  7. data/lib/mml/base/maligngroup.rb +26 -0
  8. data/lib/mml/base/malignmark.rb +26 -0
  9. data/lib/mml/base/math.rb +23 -0
  10. data/lib/mml/base/menclose.rb +27 -0
  11. data/lib/mml/base/merror.rb +25 -0
  12. data/lib/mml/base/mfenced.rb +34 -0
  13. data/lib/mml/base/mfrac.rb +33 -0
  14. data/lib/mml/base/mfraction.rb +33 -0
  15. data/lib/mml/base/mglyph.rb +42 -0
  16. data/lib/mml/base/mi.rb +32 -0
  17. data/lib/mml/base/mlabeledtr.rb +37 -0
  18. data/lib/mml/base/mlongdiv.rb +31 -0
  19. data/lib/mml/base/mmultiscripts.rb +31 -0
  20. data/lib/mml/base/mn.rb +32 -0
  21. data/lib/mml/base/mo.rb +76 -0
  22. data/lib/mml/base/mover.rb +29 -0
  23. data/lib/mml/base/mpadded.rb +35 -0
  24. data/lib/mml/base/mphantom.rb +25 -0
  25. data/lib/mml/base/mprescripts.rb +24 -0
  26. data/lib/mml/base/mroot.rb +25 -0
  27. data/lib/mml/base/mrow.rb +29 -0
  28. data/lib/mml/base/ms.rb +37 -0
  29. data/lib/mml/base/mscarries.rb +33 -0
  30. data/lib/mml/base/mscarry.rb +29 -0
  31. data/lib/mml/base/msgroup.rb +31 -0
  32. data/lib/mml/base/msline.rb +34 -0
  33. data/lib/mml/base/mspace.rb +52 -0
  34. data/lib/mml/base/msqrt.rb +25 -0
  35. data/lib/mml/base/msrow.rb +27 -0
  36. data/lib/mml/base/mstack.rb +33 -0
  37. data/lib/mml/base/mstyle.rb +189 -0
  38. data/lib/mml/base/msub.rb +27 -0
  39. data/lib/mml/base/msubsup.rb +29 -0
  40. data/lib/mml/base/msup.rb +27 -0
  41. data/lib/mml/base/mtable.rb +57 -0
  42. data/lib/mml/base/mtd.rb +29 -0
  43. data/lib/mml/base/mtext.rb +32 -0
  44. data/lib/mml/base/mtr.rb +35 -0
  45. data/lib/mml/base/munder.rb +31 -0
  46. data/lib/mml/base/munderover.rb +31 -0
  47. data/lib/mml/base/none.rb +24 -0
  48. data/lib/mml/base/semantics.rb +23 -0
  49. data/lib/mml/base/v3_only/operator_attrs.rb +24 -0
  50. data/lib/mml/base/v3_only/style_attrs.rb +31 -0
  51. data/lib/mml/base/v3_only/table_attrs.rb +28 -0
  52. data/lib/mml/base/v3_only.rb +11 -0
  53. data/lib/mml/base/v4_attributes.rb +30 -0
  54. data/lib/mml/base.rb +51 -0
  55. data/lib/mml/common_elements.rb +85 -0
  56. data/lib/mml/context_configuration.rb +118 -0
  57. data/lib/mml/context_options.rb +64 -0
  58. data/lib/mml/namespace.rb +10 -0
  59. data/lib/mml/v3/common_elements.rb +8 -0
  60. data/lib/mml/v3/configuration.rb +4 -96
  61. data/lib/mml/v3/maction.rb +2 -14
  62. data/lib/mml/v3/maligngroup.rb +2 -12
  63. data/lib/mml/v3/malignmark.rb +2 -12
  64. data/lib/mml/v3/math.rb +3 -10
  65. data/lib/mml/v3/menclose.rb +3 -14
  66. data/lib/mml/v3/merror.rb +3 -12
  67. data/lib/mml/v3/mfenced.rb +3 -21
  68. data/lib/mml/v3/mfrac.rb +3 -20
  69. data/lib/mml/v3/mfraction.rb +3 -20
  70. data/lib/mml/v3/mglyph.rb +3 -38
  71. data/lib/mml/v3/mi.rb +3 -30
  72. data/lib/mml/v3/mlabeledtr.rb +2 -23
  73. data/lib/mml/v3/mlongdiv.rb +3 -18
  74. data/lib/mml/v3/mmultiscripts.rb +3 -20
  75. data/lib/mml/v3/mn.rb +3 -30
  76. data/lib/mml/v3/mo.rb +4 -78
  77. data/lib/mml/v3/mover.rb +3 -16
  78. data/lib/mml/v3/mpadded.rb +3 -22
  79. data/lib/mml/v3/mphantom.rb +3 -12
  80. data/lib/mml/v3/mprescripts.rb +2 -10
  81. data/lib/mml/v3/mroot.rb +3 -12
  82. data/lib/mml/v3/mrow.rb +3 -18
  83. data/lib/mml/v3/ms.rb +4 -36
  84. data/lib/mml/v3/mscarries.rb +3 -20
  85. data/lib/mml/v3/mscarry.rb +3 -16
  86. data/lib/mml/v3/msgroup.rb +3 -18
  87. data/lib/mml/v3/msline.rb +2 -20
  88. data/lib/mml/v3/mspace.rb +3 -50
  89. data/lib/mml/v3/msqrt.rb +3 -12
  90. data/lib/mml/v3/msrow.rb +3 -14
  91. data/lib/mml/v3/mstack.rb +3 -20
  92. data/lib/mml/v3/mstyle.rb +5 -204
  93. data/lib/mml/v3/msub.rb +3 -14
  94. data/lib/mml/v3/msubsup.rb +3 -16
  95. data/lib/mml/v3/msup.rb +3 -14
  96. data/lib/mml/v3/mtable.rb +3 -53
  97. data/lib/mml/v3/mtd.rb +3 -16
  98. data/lib/mml/v3/mtext.rb +3 -30
  99. data/lib/mml/v3/mtr.rb +2 -21
  100. data/lib/mml/v3/munder.rb +3 -18
  101. data/lib/mml/v3/munderover.rb +3 -18
  102. data/lib/mml/v3/namespace.rb +1 -4
  103. data/lib/mml/v3/none.rb +2 -10
  104. data/lib/mml/v3/semantics.rb +3 -12
  105. data/lib/mml/v3.rb +51 -77
  106. data/lib/mml/v4/a.rb +4 -13
  107. data/lib/mml/v4/common_elements.rb +13 -0
  108. data/lib/mml/v4/configuration.rb +4 -97
  109. data/lib/mml/v4/maction.rb +4 -19
  110. data/lib/mml/v4/maligngroup.rb +4 -17
  111. data/lib/mml/v4/malignmark.rb +4 -17
  112. data/lib/mml/v4/math.rb +4 -14
  113. data/lib/mml/v4/menclose.rb +4 -18
  114. data/lib/mml/v4/merror.rb +4 -16
  115. data/lib/mml/v4/mfenced.rb +4 -25
  116. data/lib/mml/v4/mfrac.rb +4 -24
  117. data/lib/mml/v4/mfraction.rb +4 -20
  118. data/lib/mml/v4/mglyph.rb +4 -35
  119. data/lib/mml/v4/mi.rb +4 -30
  120. data/lib/mml/v4/mlabeledtr.rb +6 -23
  121. data/lib/mml/v4/mlongdiv.rb +4 -18
  122. data/lib/mml/v4/mmultiscripts.rb +4 -24
  123. data/lib/mml/v4/mn.rb +4 -29
  124. data/lib/mml/v4/mo.rb +4 -75
  125. data/lib/mml/v4/mover.rb +4 -20
  126. data/lib/mml/v4/mpadded.rb +4 -26
  127. data/lib/mml/v4/mphantom.rb +4 -16
  128. data/lib/mml/v4/mprescripts.rb +4 -11
  129. data/lib/mml/v4/mroot.rb +4 -16
  130. data/lib/mml/v4/mrow.rb +4 -20
  131. data/lib/mml/v4/ms.rb +4 -34
  132. data/lib/mml/v4/mscarries.rb +4 -20
  133. data/lib/mml/v4/mscarry.rb +4 -16
  134. data/lib/mml/v4/msgroup.rb +4 -18
  135. data/lib/mml/v4/msline.rb +4 -21
  136. data/lib/mml/v4/mspace.rb +4 -49
  137. data/lib/mml/v4/msqrt.rb +4 -16
  138. data/lib/mml/v4/msrow.rb +4 -18
  139. data/lib/mml/v4/mstack.rb +4 -24
  140. data/lib/mml/v4/mstyle.rb +4 -186
  141. data/lib/mml/v4/msub.rb +4 -18
  142. data/lib/mml/v4/msubsup.rb +4 -20
  143. data/lib/mml/v4/msup.rb +4 -18
  144. data/lib/mml/v4/mtable.rb +4 -55
  145. data/lib/mml/v4/mtd.rb +4 -20
  146. data/lib/mml/v4/mtext.rb +4 -29
  147. data/lib/mml/v4/mtr.rb +4 -25
  148. data/lib/mml/v4/munder.rb +4 -22
  149. data/lib/mml/v4/munderover.rb +4 -22
  150. data/lib/mml/v4/namespace.rb +1 -4
  151. data/lib/mml/v4/none.rb +6 -11
  152. data/lib/mml/v4/semantics.rb +4 -12
  153. data/lib/mml/v4.rb +52 -74
  154. data/lib/mml/version.rb +1 -1
  155. data/lib/mml/versioned_parser.rb +46 -0
  156. data/lib/mml.rb +33 -25
  157. metadata +60 -4
  158. data/lib/mml/v3/common_attributes.rb +0 -22
  159. data/lib/mml/v4/common_attributes.rb +0 -26
data/lib/mml/v4/msub.rb CHANGED
@@ -2,28 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Msub < Mml::V3::Msub
6
- attribute :mathbackground, :string
7
- attribute :subscriptshift, :string
8
- attribute :mathcolor, :string
9
- attribute :intent, :string
10
- attribute :arg, :string
11
- attribute :displaystyle, :string
12
- attribute :scriptlevel, :integer
5
+ class Msub < CommonElements
6
+ include Base::Msub
7
+ include Base::V4Attributes
13
8
 
14
9
  xml do
15
10
  namespace Namespace
16
- element "msub"
17
- mixed_content
18
-
19
- map_attribute "mathbackground", to: :mathbackground
20
- map_attribute "subscriptshift", to: :subscriptshift
21
- map_attribute "mathcolor", to: :mathcolor
22
- map_attribute "intent", to: :intent
23
- map_attribute "arg", to: :arg
24
- map_attribute "displaystyle", to: :displaystyle
25
- map_attribute "scriptlevel", to: :scriptlevel
26
11
  end
27
12
  end
13
+ Configuration.register_model(Msub, id: :msub)
28
14
  end
29
15
  end
@@ -2,30 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Msubsup < Mml::V3::Msubsup
6
- attribute :mathcolor, :string
7
- attribute :mathbackground, :string
8
- attribute :subscriptshift, :string
9
- attribute :superscriptshift, :string
10
- attribute :intent, :string
11
- attribute :arg, :string
12
- attribute :displaystyle, :string
13
- attribute :scriptlevel, :integer
5
+ class Msubsup < CommonElements
6
+ include Base::Msubsup
7
+ include Base::V4Attributes
14
8
 
15
9
  xml do
16
10
  namespace Namespace
17
- element "msubsup"
18
- mixed_content
19
-
20
- map_attribute "mathcolor", to: :mathcolor
21
- map_attribute "mathbackground", to: :mathbackground
22
- map_attribute "subscriptshift", to: :subscriptshift
23
- map_attribute "superscriptshift", to: :superscriptshift
24
- map_attribute "intent", to: :intent
25
- map_attribute "arg", to: :arg
26
- map_attribute "displaystyle", to: :displaystyle
27
- map_attribute "scriptlevel", to: :scriptlevel
28
11
  end
29
12
  end
13
+ Configuration.register_model(Msubsup, id: :msubsup)
30
14
  end
31
15
  end
data/lib/mml/v4/msup.rb CHANGED
@@ -2,28 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Msup < Mml::V3::Msup
6
- attribute :mathcolor, :string
7
- attribute :mathbackground, :string
8
- attribute :superscriptshift, :string
9
- attribute :intent, :string
10
- attribute :arg, :string
11
- attribute :displaystyle, :string
12
- attribute :scriptlevel, :integer
5
+ class Msup < CommonElements
6
+ include Base::Msup
7
+ include Base::V4Attributes
13
8
 
14
9
  xml do
15
10
  namespace Namespace
16
- element "msup"
17
- mixed_content
18
-
19
- map_attribute "mathcolor", to: :mathcolor
20
- map_attribute "mathbackground", to: :mathbackground
21
- map_attribute "superscriptshift", to: :superscriptshift
22
- map_attribute "intent", to: :intent
23
- map_attribute "arg", to: :arg
24
- map_attribute "displaystyle", to: :displaystyle
25
- map_attribute "scriptlevel", to: :scriptlevel
26
11
  end
27
12
  end
13
+ Configuration.register_model(Msup, id: :msup)
28
14
  end
29
15
  end
data/lib/mml/v4/mtable.rb CHANGED
@@ -2,65 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- autoload(:Mlabeledtr, "mml/v4/mlabeledtr")
6
- autoload(:Mtr, "mml/v4/mtr")
7
- class Mtable < Mml::V3::Mtable
8
- attribute :mathcolor, :string
9
- attribute :mathbackground, :string
10
- attribute :align, :string
11
- attribute :rowalign, :string
12
- attribute :columnalign, :string
13
- attribute :groupalign, :string
14
- attribute :alignmentscope, :string
15
- attribute :columnwidth, :string
16
- attribute :width, :string
17
- attribute :rowspacing, :string
18
- attribute :columnspacing, :string
19
- attribute :rowlines, :string
20
- attribute :columnlines, :string
21
- attribute :frame, :string
22
- attribute :framespacing, :string
23
- attribute :equalrows, :string
24
- attribute :equalcolumns, :string
25
- attribute :displaystyle, :string
26
- attribute :side, :string
27
- attribute :minlabelspacing, :string
28
- attribute :intent, :string
29
- attribute :arg, :string
30
- attribute :scriptlevel, :integer
31
- attribute :mlabeledtr_value, Mlabeledtr, collection: true
32
- attribute :mtr_value, Mtr, collection: true
5
+ class Mtable < Lutaml::Model::Serializable
6
+ include Base::Mtable
7
+ include Base::V4Attributes
33
8
 
34
9
  xml do
35
10
  namespace Namespace
36
- element "mtable"
37
- mixed_content
38
-
39
- map_attribute "mathcolor", to: :mathcolor
40
- map_attribute "mathbackground", to: :mathbackground
41
- map_attribute "align", to: :align
42
- map_attribute "rowalign", to: :rowalign
43
- map_attribute "columnalign", to: :columnalign
44
- map_attribute "alignmentscope", to: :alignmentscope
45
- map_attribute "columnwidth", to: :columnwidth
46
- map_attribute "width", to: :width
47
- map_attribute "rowspacing", to: :rowspacing
48
- map_attribute "columnspacing", to: :columnspacing
49
- map_attribute "rowlines", to: :rowlines
50
- map_attribute "columnlines", to: :columnlines
51
- map_attribute "frame", to: :frame
52
- map_attribute "framespacing", to: :framespacing
53
- map_attribute "equalrows", to: :equalrows
54
- map_attribute "equalcolumns", to: :equalcolumns
55
- map_attribute "displaystyle", to: :displaystyle
56
- map_attribute "side", to: :side
57
- map_attribute "minlabelspacing", to: :minlabelspacing
58
- map_attribute "intent", to: :intent
59
- map_attribute "arg", to: :arg
60
- map_attribute "scriptlevel", to: :scriptlevel
61
- map_element "mlabeledtr", to: :mlabeledtr_value
62
- map_element "mtr", to: :mtr_value
63
11
  end
64
12
  end
13
+ Configuration.register_model(Mtable, id: :mtable)
65
14
  end
66
15
  end
data/lib/mml/v4/mtd.rb CHANGED
@@ -2,30 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Mtd < Mml::V3::Mtd
6
- attribute :mathcolor, :string
7
- attribute :mathbackground, :string
8
- attribute :rowalign, :string
9
- attribute :columnalign, :string
10
- attribute :intent, :string
11
- attribute :arg, :string
12
- attribute :displaystyle, :string
13
- attribute :scriptlevel, :integer
5
+ class Mtd < CommonElements
6
+ include Base::Mtd
7
+ include Base::V4Attributes
14
8
 
15
9
  xml do
16
10
  namespace Namespace
17
- element "mtd"
18
- mixed_content
19
-
20
- map_attribute "mathcolor", to: :mathcolor
21
- map_attribute "mathbackground", to: :mathbackground
22
- map_attribute "rowalign", to: :rowalign
23
- map_attribute "columnalign", to: :columnalign
24
- map_attribute "intent", to: :intent
25
- map_attribute "arg", to: :arg
26
- map_attribute "displaystyle", to: :displaystyle
27
- map_attribute "scriptlevel", to: :scriptlevel
28
11
  end
29
12
  end
13
+ Configuration.register_model(Mtd, id: :mtd)
30
14
  end
31
15
  end
data/lib/mml/v4/mtext.rb CHANGED
@@ -2,39 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Mtext < Mml::V3::Mtext
6
- attribute :value, :string
7
- attribute :mathcolor, :string
8
- attribute :mathbackground, :string
9
- attribute :mathvariant, :string
10
- attribute :mathsize, :string
11
- attribute :dir, :string
12
- attribute :fontfamily, :string
13
- attribute :fontweight, :string
14
- attribute :fontstyle, :string
15
- attribute :fontsize, :string
16
- attribute :color, :string
17
- attribute :background, :string
18
- attribute :intent, :string
19
- attribute :arg, :string
20
- attribute :displaystyle, :string
21
- attribute :scriptlevel, :integer
5
+ class Mtext < Lutaml::Model::Serializable
6
+ include Base::Mtext
7
+ include Base::V4Attributes
22
8
 
23
9
  xml do
24
10
  namespace Namespace
25
- element "mtext"
26
-
27
- map_content to: :value
28
- map_attribute "mathcolor", to: :mathcolor
29
- map_attribute "mathbackground", to: :mathbackground
30
- map_attribute "mathvariant", to: :mathvariant
31
- map_attribute "mathsize", to: :mathsize
32
- map_attribute "dir", to: :dir
33
- map_attribute "intent", to: :intent
34
- map_attribute "arg", to: :arg
35
- map_attribute "displaystyle", to: :displaystyle
36
- map_attribute "scriptlevel", to: :scriptlevel
37
11
  end
38
12
  end
13
+ Configuration.register_model(Mtext, id: :mtext)
39
14
  end
40
15
  end
data/lib/mml/v4/mtr.rb CHANGED
@@ -2,35 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- autoload(:Mtd, "mml/v4/mtd")
6
-
7
- class Mtr < Mml::V3::Mtr
8
- attribute :mathcolor, :string
9
- attribute :mathbackground, :string
10
- attribute :rowalign, :string
11
- attribute :columnalign, :string
12
- attribute :groupalign, :string
13
- attribute :intent, :string
14
- attribute :arg, :string
15
- attribute :displaystyle, :string
16
- attribute :scriptlevel, :integer
17
- attribute :mtd_value, Mtd, collection: true
5
+ class Mtr < Lutaml::Model::Serializable
6
+ include Base::Mtr
7
+ include Base::V4Attributes
18
8
 
19
9
  xml do
20
10
  namespace Namespace
21
- element "mtr"
22
- mixed_content
23
-
24
- map_attribute "mathcolor", to: :mathcolor
25
- map_attribute "mathbackground", to: :mathbackground
26
- map_attribute "rowalign", to: :rowalign
27
- map_attribute "columnalign", to: :columnalign
28
- map_attribute "intent", to: :intent
29
- map_attribute "arg", to: :arg
30
- map_attribute "displaystyle", to: :displaystyle
31
- map_attribute "scriptlevel", to: :scriptlevel
32
- map_element "mtd", to: :mtd_value
33
11
  end
34
12
  end
13
+ Configuration.register_model(Mtr, id: :mtr)
35
14
  end
36
15
  end
data/lib/mml/v4/munder.rb CHANGED
@@ -2,32 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Munder < Mml::V3::Munder
6
- attribute :mathbackground, :string
7
- attribute :accentunder, :string
8
- attribute :mathcolor, :string
9
- attribute :content, :string
10
- attribute :align, :string
11
- attribute :intent, :string
12
- attribute :arg, :string
13
- attribute :displaystyle, :string
14
- attribute :scriptlevel, :integer
5
+ class Munder < CommonElements
6
+ include Base::Munder
7
+ include Base::V4Attributes
15
8
 
16
9
  xml do
17
10
  namespace Namespace
18
- element "munder"
19
- mixed_content
20
-
21
- map_attribute "mathbackground", to: :mathbackground
22
- map_attribute "accentunder", to: :accentunder
23
- map_attribute "mathcolor", to: :mathcolor
24
- map_attribute "align", to: :align
25
- map_attribute "intent", to: :intent
26
- map_attribute "arg", to: :arg
27
- map_attribute "displaystyle", to: :displaystyle
28
- map_attribute "scriptlevel", to: :scriptlevel
29
- map_content to: :content
30
11
  end
31
12
  end
13
+ Configuration.register_model(Munder, id: :munder)
32
14
  end
33
15
  end
@@ -2,32 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Munderover < Mml::V3::Munderover
6
- attribute :mathcolor, :string
7
- attribute :mathbackground, :string
8
- attribute :accent, :string
9
- attribute :accentunder, :string
10
- attribute :align, :string
11
- attribute :intent, :string
12
- attribute :arg, :string
13
- attribute :displaystyle, :string
14
- attribute :scriptlevel, :integer
5
+ class Munderover < CommonElements
6
+ include Base::Munderover
7
+ include Base::V4Attributes
15
8
 
16
9
  xml do
17
10
  namespace Namespace
18
- element "munderover"
19
- mixed_content
20
-
21
- map_attribute "mathcolor", to: :mathcolor
22
- map_attribute "mathbackground", to: :mathbackground
23
- map_attribute "accent", to: :accent
24
- map_attribute "accentunder", to: :accentunder
25
- map_attribute "align", to: :align
26
- map_attribute "intent", to: :intent
27
- map_attribute "arg", to: :arg
28
- map_attribute "displaystyle", to: :displaystyle
29
- map_attribute "scriptlevel", to: :scriptlevel
30
11
  end
31
12
  end
13
+ Configuration.register_model(Munderover, id: :munderover)
32
14
  end
33
15
  end
@@ -2,9 +2,6 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class Namespace < Lutaml::Xml::Namespace
6
- uri "http://www.w3.org/1998/Math/MathML"
7
- prefix_default "mml"
8
- end
5
+ Namespace = Mml::Namespace
9
6
  end
10
7
  end
data/lib/mml/v4/none.rb CHANGED
@@ -2,21 +2,16 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- class None < Mml::V3::None
6
- attribute :mathcolor, :string
7
- attribute :mathbackground, :string
8
- attribute :intent, :string
9
- attribute :arg, :string
5
+ # @deprecated V4 spec marks <none> as deprecated.
6
+ # Use an empty <mrow> instead for MathML Core compatibility.
7
+ class None < Lutaml::Model::Serializable
8
+ include Base::None
9
+ include Base::V4Attributes
10
10
 
11
11
  xml do
12
12
  namespace Namespace
13
- element "none"
14
-
15
- map_attribute "mathcolor", to: :mathcolor
16
- map_attribute "mathbackground", to: :mathbackground
17
- map_attribute "intent", to: :intent
18
- map_attribute "arg", to: :arg
19
13
  end
20
14
  end
15
+ Configuration.register_model(None, id: :none)
21
16
  end
22
17
  end
@@ -2,22 +2,14 @@
2
2
 
3
3
  module Mml
4
4
  module V4
5
- autoload(:Mi, "mml/v4/mi")
6
-
7
- class Semantics < Mml::V3::Semantics
8
- attribute :annotation, Mi, collection: true
9
- attribute :displaystyle, :string
10
- attribute :scriptlevel, :integer
5
+ class Semantics < CommonElements
6
+ include Base::Semantics
7
+ include Base::V4Attributes
11
8
 
12
9
  xml do
13
10
  namespace Namespace
14
- element "semantics"
15
- mixed_content
16
-
17
- map_element :annotation, to: :annotation
18
- map_attribute "displaystyle", to: :displaystyle
19
- map_attribute "scriptlevel", to: :scriptlevel
20
11
  end
21
12
  end
13
+ Configuration.register_model(Semantics, id: :semantics)
22
14
  end
23
15
  end
data/lib/mml/v4.rb CHANGED
@@ -1,81 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mml/v4/configuration"
3
+ require "lutaml/model"
4
+ require_relative "versioned_parser"
5
+ Moxml::Config.default_adapter = Mml::DEFAULT_ADAPTER
6
+
7
+ require_relative "v4/configuration"
8
+ require_relative "v4/namespace"
9
+ require_relative "v4/common_elements"
10
+ require_relative "v4/a"
11
+ require_relative "v4/maction"
12
+ require_relative "v4/maligngroup"
13
+ require_relative "v4/malignmark"
14
+ require_relative "v4/menclose"
15
+ require_relative "v4/merror"
16
+ require_relative "v4/mfenced"
17
+ require_relative "v4/mfrac"
18
+ require_relative "v4/mfraction"
19
+ require_relative "v4/mglyph"
20
+ require_relative "v4/mi"
21
+ require_relative "v4/mlongdiv"
22
+ require_relative "v4/mn"
23
+ require_relative "v4/mo"
24
+ require_relative "v4/mover"
25
+ require_relative "v4/mpadded"
26
+ require_relative "v4/mphantom"
27
+ require_relative "v4/mprescripts"
28
+ require_relative "v4/mroot"
29
+ require_relative "v4/mrow"
30
+ require_relative "v4/ms"
31
+ require_relative "v4/mscarries"
32
+ require_relative "v4/mscarry"
33
+ require_relative "v4/msgroup"
34
+ require_relative "v4/msline"
35
+ require_relative "v4/mspace"
36
+ require_relative "v4/msqrt"
37
+ require_relative "v4/msrow"
38
+ require_relative "v4/mstack"
39
+ require_relative "v4/mstyle"
40
+ require_relative "v4/msub"
41
+ require_relative "v4/msubsup"
42
+ require_relative "v4/msup"
43
+ require_relative "v4/mtd"
44
+ require_relative "v4/mtable"
45
+ require_relative "v4/mtext"
46
+ require_relative "v4/mtr"
47
+ require_relative "v4/mlabeledtr"
48
+ require_relative "v4/munder"
49
+ require_relative "v4/munderover"
50
+ require_relative "v4/mmultiscripts"
51
+ require_relative "v4/none"
52
+ require_relative "v4/semantics"
53
+ require_relative "v4/math"
4
54
 
5
55
  module Mml
6
56
  module V4
7
- autoload :Namespace, "mml/v4/namespace"
8
- autoload :A, "mml/v4/a"
9
- autoload :Maction, "mml/v4/maction"
10
- autoload :Maligngroup, "mml/v4/maligngroup"
11
- autoload :Malignmark, "mml/v4/malignmark"
12
- autoload :Math, "mml/v4/math"
13
- autoload :Menclose, "mml/v4/menclose"
14
- autoload :Merror, "mml/v4/merror"
15
- autoload :Mfenced, "mml/v4/mfenced"
16
- autoload :Mfrac, "mml/v4/mfrac"
17
- autoload :Mfraction, "mml/v4/mfraction"
18
- autoload :Mglyph, "mml/v4/mglyph"
19
- autoload :Mi, "mml/v4/mi"
20
- autoload :Mlabeledtr, "mml/v4/mlabeledtr"
21
- autoload :Mlongdiv, "mml/v4/mlongdiv"
22
- autoload :Mmultiscripts, "mml/v4/mmultiscripts"
23
- autoload :Mn, "mml/v4/mn"
24
- autoload :Mo, "mml/v4/mo"
25
- autoload :Mover, "mml/v4/mover"
26
- autoload :Mpadded, "mml/v4/mpadded"
27
- autoload :Mphantom, "mml/v4/mphantom"
28
- autoload :Mprescripts, "mml/v4/mprescripts"
29
- autoload :Mroot, "mml/v4/mroot"
30
- autoload :Mrow, "mml/v4/mrow"
31
- autoload :Ms, "mml/v4/ms"
32
- autoload :Mscarries, "mml/v4/mscarries"
33
- autoload :Mscarry, "mml/v4/mscarry"
34
- autoload :Msgroup, "mml/v4/msgroup"
35
- autoload :Msline, "mml/v4/msline"
36
- autoload :Mspace, "mml/v4/mspace"
37
- autoload :Msqrt, "mml/v4/msqrt"
38
- autoload :Msrow, "mml/v4/msrow"
39
- autoload :Mstack, "mml/v4/mstack"
40
- autoload :Mstyle, "mml/v4/mstyle"
41
- autoload :Msub, "mml/v4/msub"
42
- autoload :Msubsup, "mml/v4/msubsup"
43
- autoload :Msup, "mml/v4/msup"
44
- autoload :Mtable, "mml/v4/mtable"
45
- autoload :Mtd, "mml/v4/mtd"
46
- autoload :Mtext, "mml/v4/mtext"
47
- autoload :Mtr, "mml/v4/mtr"
48
- autoload :Munder, "mml/v4/munder"
49
- autoload :Munderover, "mml/v4/munderover"
50
- autoload :None, "mml/v4/none"
51
- autoload :Semantics, "mml/v4/semantics"
52
-
53
- # Ensure that the CommonAttributes class is loaded after all
54
- # other classes
55
- require "mml/v4/common_attributes"
56
-
57
- def self.update_attributes
58
- Configuration::COMMON_ATTRIBUTES_CLASSES.each do |klass|
59
- const_get(klass).import_model(CommonAttributes)
60
- end
61
- end
62
-
63
- def self.parse(input, namespace_exist: true)
64
- Configuration.adapter ||= DEFAULT_ADAPTER
65
-
66
- return parse_with_no_namespace(input) unless namespace_exist
67
-
68
- Mml::V4::Math.from_xml(input)
69
- end
70
-
71
- def self.parse_with_no_namespace(input)
72
- with_ns = Nokogiri::XML.parse(input).tap do |doc|
73
- doc.root["xmlns"] = Namespace.uri
74
- end.to_xml
75
-
76
- Mml::V4::Math.from_xml(with_ns)
77
- end
57
+ extend Mml::VersionedParser
78
58
  end
79
59
  end
80
-
81
- Mml::V4.update_attributes
data/lib/mml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mml
4
- VERSION = "2.2.0"
4
+ VERSION = "2.3.0"
5
5
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mml
4
+ module VersionedParser
5
+ # Shared parse entrypoint for versioned modules.
6
+ def parse(input, namespace_exist: true,
7
+ context: Mml::UNSPECIFIED_CONTEXT, register: nil)
8
+ self::Configuration.adapter ||= Mml::DEFAULT_ADAPTER
9
+ context_id = parse_context_id(context, register)
10
+ root_class = Lutaml::Model::GlobalContext.resolve_type(
11
+ :math,
12
+ context_id,
13
+ )
14
+
15
+ root_class.from_xml(
16
+ xml_input(input, namespace_exist),
17
+ register: context_id,
18
+ )
19
+ end
20
+
21
+ # Namespace-less MathML is normalized before handing it to lutaml-model.
22
+ def parse_with_no_namespace(input)
23
+ adapter = self::Configuration.adapter || Mml::DEFAULT_ADAPTER
24
+ Moxml.new(adapter).parse(input).tap do |doc|
25
+ doc.root.add_namespace(nil, self::Namespace.uri)
26
+ end.to_xml
27
+ end
28
+
29
+ # Version modules keep their own default context id.
30
+ def parse_context_id(context, register)
31
+ Mml::ContextOptions.normalize_context_option(
32
+ context: context,
33
+ register: register,
34
+ default_context: self::Configuration.context_id,
35
+ warning_source: "#{name}.parse",
36
+ )
37
+ end
38
+
39
+ # Keep the main parse flow readable by separating namespace normalization.
40
+ def xml_input(input, namespace_exist)
41
+ return input if namespace_exist
42
+
43
+ parse_with_no_namespace(input)
44
+ end
45
+ end
46
+ end