mml 2.0.3 → 2.1.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.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +10 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +11 -74
- data/Gemfile +2 -1
- data/README.adoc +313 -4
- data/lib/mml/common_attributes.rb +0 -2
- data/lib/mml/configuration.rb +2 -3
- data/lib/mml/maction.rb +6 -5
- data/lib/mml/maligngroup.rb +5 -4
- data/lib/mml/malignmark.rb +5 -4
- data/lib/mml/math.rb +18 -0
- data/lib/mml/menclose.rb +6 -4
- data/lib/mml/merror.rb +5 -3
- data/lib/mml/mfenced.rb +8 -6
- data/lib/mml/mfrac.rb +9 -7
- data/lib/mml/mfraction.rb +9 -7
- data/lib/mml/mglyph.rb +18 -17
- data/lib/mml/mi.rb +13 -12
- data/lib/mml/mlabeledtr.rb +9 -7
- data/lib/mml/mlongdiv.rb +8 -6
- data/lib/mml/mmultiscripts.rb +7 -5
- data/lib/mml/mn.rb +13 -12
- data/lib/mml/mo.rb +36 -35
- data/lib/mml/mover.rb +7 -5
- data/lib/mml/mpadded.rb +10 -8
- data/lib/mml/mphantom.rb +5 -3
- data/lib/mml/mprescripts.rb +4 -3
- data/lib/mml/mroot.rb +5 -3
- data/lib/mml/mrow.rb +7 -5
- data/lib/mml/ms.rb +16 -14
- data/lib/mml/mscarries.rb +9 -8
- data/lib/mml/mscarry.rb +7 -5
- data/lib/mml/msgroup.rb +7 -5
- data/lib/mml/msline.rb +9 -8
- data/lib/mml/mspace.rb +24 -23
- data/lib/mml/msqrt.rb +5 -3
- data/lib/mml/msrow.rb +6 -4
- data/lib/mml/mstack.rb +9 -7
- data/lib/mml/mstyle.rb +99 -102
- data/lib/mml/msub.rb +6 -4
- data/lib/mml/msubsup.rb +7 -5
- data/lib/mml/msup.rb +6 -4
- data/lib/mml/mtable.rb +23 -21
- data/lib/mml/mtd.rb +7 -5
- data/lib/mml/mtext.rb +13 -12
- data/lib/mml/mtr.rb +8 -6
- data/lib/mml/munder.rb +7 -5
- data/lib/mml/munderover.rb +8 -6
- data/lib/mml/namespace.rb +9 -0
- data/lib/mml/none.rb +4 -3
- data/lib/mml/semantics.rb +3 -1
- data/lib/mml/version.rb +1 -1
- data/lib/mml.rb +67 -19
- data/mml.gemspec +1 -1
- metadata +8 -8
- data/lib/mml/math_with_namespace.rb +0 -14
- data/lib/mml/math_with_nil_namespace.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0edf00bb97f74177c28a416132046bd265a61a8720de3a0a9d1b9515721170db
|
|
4
|
+
data.tar.gz: 9b11f8ecc3869145617584f9afb422ae3ced36db62994f89750483f039e1bb99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce86364277e4aae63f893d64ccbabb3752beb2acb11f634caaab20fb01b2768902180eab714dbcb69ab91fcc183778004dcbbf50fb3da4f976071effc687d293
|
|
7
|
+
data.tar.gz: b3ae2643d010604f0a293fbf35ca7d5ad776055a67b9c90293e4fd7a97a7b8ae70735526c5cd3bf2c96cd2528f3d27048069a481590d6119f7fed7a2d9a365da
|
|
@@ -2,20 +2,26 @@
|
|
|
2
2
|
# See https://github.com/metanorma/cimas
|
|
3
3
|
name: release
|
|
4
4
|
|
|
5
|
+
permissions:
|
|
6
|
+
contents: write
|
|
7
|
+
packages: write
|
|
8
|
+
id-token: write
|
|
9
|
+
|
|
5
10
|
on:
|
|
6
11
|
workflow_dispatch:
|
|
7
12
|
inputs:
|
|
8
13
|
next_version:
|
|
9
14
|
description: |
|
|
10
|
-
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
|
15
|
+
Next release version. Possible values: x.y.z, major, minor, patch (or pre|rc|etc).
|
|
16
|
+
Also, you can pass 'skip' to skip 'git tag' and do 'gem push' for the current version
|
|
11
17
|
required: true
|
|
12
18
|
default: 'skip'
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
repository_dispatch:
|
|
20
|
+
types: [ do-release ]
|
|
15
21
|
|
|
16
22
|
jobs:
|
|
17
23
|
release:
|
|
18
|
-
uses:
|
|
24
|
+
uses: relaton/support/.github/workflows/release.yml@main
|
|
19
25
|
with:
|
|
20
26
|
next_version: ${{ github.event.inputs.next_version }}
|
|
21
27
|
secrets:
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -1,81 +1,35 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on
|
|
3
|
+
# on 2026-03-26 05:47:46 UTC using RuboCop version 1.86.0.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
# Offense count: 2
|
|
10
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
11
|
-
# Configuration parameters: Include.
|
|
12
|
-
# Include: **/*.gemspec
|
|
13
|
-
Gemspec/AddRuntimeDependency:
|
|
14
|
-
Exclude:
|
|
15
|
-
- 'mml.gemspec'
|
|
16
|
-
|
|
17
|
-
# Offense count: 1
|
|
18
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
19
|
-
# Configuration parameters: Severity, Include.
|
|
20
|
-
# Include: **/*.gemspec
|
|
21
|
-
Gemspec/DeprecatedAttributeAssignment:
|
|
22
|
-
Exclude:
|
|
23
|
-
- 'mml.gemspec'
|
|
24
|
-
|
|
25
|
-
# Offense count: 1
|
|
26
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
27
|
-
# Configuration parameters: Severity, Include.
|
|
28
|
-
# Include: **/*.gemspec
|
|
29
|
-
Gemspec/RequireMFA:
|
|
30
|
-
Exclude:
|
|
31
|
-
- 'mml.gemspec'
|
|
32
|
-
|
|
33
9
|
# Offense count: 1
|
|
34
10
|
# This cop supports safe autocorrection (--autocorrect).
|
|
35
11
|
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
36
12
|
# SupportedStyles: with_first_argument, with_fixed_indentation
|
|
37
13
|
Layout/ArgumentAlignment:
|
|
38
14
|
Exclude:
|
|
39
|
-
- '
|
|
40
|
-
|
|
41
|
-
# Offense count: 6
|
|
42
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
43
|
-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
|
|
44
|
-
# SupportedHashRocketStyles: key, separator, table
|
|
45
|
-
# SupportedColonStyles: key, separator, table
|
|
46
|
-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
|
47
|
-
Layout/HashAlignment:
|
|
48
|
-
Exclude:
|
|
49
|
-
- 'lib/mml/mscarries.rb'
|
|
50
|
-
- 'lib/mml/mstyle.rb'
|
|
51
|
-
|
|
52
|
-
# Offense count: 1
|
|
53
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
54
|
-
# Configuration parameters: EnforcedStyle.
|
|
55
|
-
# SupportedStyles: normal, indented_internal_methods
|
|
56
|
-
Layout/IndentationConsistency:
|
|
57
|
-
Exclude:
|
|
58
|
-
- 'mml.gemspec'
|
|
15
|
+
- 'spec/mml_spec.rb'
|
|
59
16
|
|
|
60
|
-
# Offense count:
|
|
17
|
+
# Offense count: 5
|
|
61
18
|
# This cop supports safe autocorrection (--autocorrect).
|
|
62
|
-
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes,
|
|
19
|
+
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
|
|
63
20
|
# URISchemes: http, https
|
|
64
21
|
Layout/LineLength:
|
|
65
22
|
Exclude:
|
|
66
|
-
- 'lib/mml/common_attributes.rb'
|
|
67
|
-
- 'lib/mml/mscarries.rb'
|
|
68
|
-
- 'lib/mml/mstyle.rb'
|
|
69
23
|
- 'mml.gemspec'
|
|
24
|
+
- 'spec/mml_spec.rb'
|
|
25
|
+
- 'spec/spec_helper.rb'
|
|
70
26
|
|
|
71
|
-
# Offense count:
|
|
27
|
+
# Offense count: 1
|
|
72
28
|
# This cop supports safe autocorrection (--autocorrect).
|
|
73
29
|
# Configuration parameters: AllowInHeredoc.
|
|
74
30
|
Layout/TrailingWhitespace:
|
|
75
31
|
Exclude:
|
|
76
|
-
- '
|
|
77
|
-
- 'lib/mml/mscarries.rb'
|
|
78
|
-
- 'lib/mml/mstyle.rb'
|
|
32
|
+
- 'spec/mml_spec.rb'
|
|
79
33
|
|
|
80
34
|
# Offense count: 1
|
|
81
35
|
# Configuration parameters: Prefixes, AllowedPatterns.
|
|
@@ -84,32 +38,15 @@ RSpec/ContextWording:
|
|
|
84
38
|
Exclude:
|
|
85
39
|
- 'spec/mml_spec.rb'
|
|
86
40
|
|
|
87
|
-
# Offense count:
|
|
88
|
-
|
|
89
|
-
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
|
|
90
|
-
# SupportedStyles: described_class, explicit
|
|
91
|
-
RSpec/DescribedClass:
|
|
92
|
-
Exclude:
|
|
93
|
-
- 'spec/mml_spec.rb'
|
|
94
|
-
|
|
95
|
-
# Offense count: 2
|
|
96
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
97
|
-
Style/FileRead:
|
|
41
|
+
# Offense count: 1
|
|
42
|
+
RSpec/PendingWithoutReason:
|
|
98
43
|
Exclude:
|
|
99
44
|
- 'spec/mml_spec.rb'
|
|
100
45
|
|
|
101
|
-
# Offense count:
|
|
46
|
+
# Offense count: 1
|
|
102
47
|
# This cop supports safe autocorrection (--autocorrect).
|
|
103
48
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
|
104
49
|
# SupportedStyles: single_quotes, double_quotes
|
|
105
50
|
Style/StringLiterals:
|
|
106
|
-
Exclude:
|
|
107
|
-
- 'mml.gemspec'
|
|
108
|
-
|
|
109
|
-
# Offense count: 2
|
|
110
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
111
|
-
# Configuration parameters: EnforcedStyle.
|
|
112
|
-
# SupportedStyles: single_quotes, double_quotes
|
|
113
|
-
Style/StringLiteralsInInterpolation:
|
|
114
51
|
Exclude:
|
|
115
52
|
- 'spec/mml_spec.rb'
|
data/Gemfile
CHANGED
|
@@ -5,7 +5,8 @@ source "https://rubygems.org"
|
|
|
5
5
|
gemspec
|
|
6
6
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
7
7
|
|
|
8
|
-
gem "
|
|
8
|
+
gem "canon"
|
|
9
|
+
gem "lutaml-model", github: "lutaml/lutaml-model", branch: "main"
|
|
9
10
|
gem "ox"
|
|
10
11
|
gem "pry"
|
|
11
12
|
gem "rake", "~> 12.0"
|
data/README.adoc
CHANGED
|
@@ -1,9 +1,318 @@
|
|
|
1
|
-
=
|
|
1
|
+
= Mml: MathML parser and builder
|
|
2
|
+
|
|
3
|
+
:toc:
|
|
4
|
+
:toclevels: 2
|
|
2
5
|
|
|
3
6
|
== Purpose
|
|
4
7
|
|
|
5
|
-
Mml
|
|
8
|
+
Mml provides MathML 3 XML parsing and serialization for Ruby. It maps the full
|
|
9
|
+
MathML element set into Ruby model classes using the
|
|
10
|
+
https://github.com/lutaml/lutaml-model[lutaml-model] framework and is used by
|
|
11
|
+
https://github.com/plurimath/plurimath[Plurimath] for mathematical formula
|
|
12
|
+
representation.
|
|
13
|
+
|
|
14
|
+
Key features:
|
|
15
|
+
|
|
16
|
+
* **MathML 3 element support**: 43 elements including presentation markup,
|
|
17
|
+
tables, scripts, fractions, and more
|
|
18
|
+
* **Namespace handling**: Default `xmlns`, prefixed `mml:`, and namespace-less
|
|
19
|
+
input
|
|
20
|
+
* **Round-trip fidelity**: Parse XML to an object graph, modify, and serialize
|
|
21
|
+
back
|
|
22
|
+
* **Opal support**: Runs in the browser via Ruby-to-JavaScript compilation
|
|
23
|
+
|
|
24
|
+
== Installation
|
|
25
|
+
|
|
26
|
+
Add to your application's Gemfile:
|
|
27
|
+
|
|
28
|
+
[source,ruby]
|
|
29
|
+
----
|
|
30
|
+
gem 'mml'
|
|
31
|
+
----
|
|
32
|
+
|
|
33
|
+
Then execute:
|
|
34
|
+
|
|
35
|
+
[source,bash]
|
|
36
|
+
----
|
|
37
|
+
$ bundle install
|
|
38
|
+
----
|
|
39
|
+
|
|
40
|
+
Or install directly:
|
|
41
|
+
|
|
42
|
+
[source,bash]
|
|
43
|
+
----
|
|
44
|
+
$ gem install mml
|
|
45
|
+
----
|
|
46
|
+
|
|
47
|
+
== Quick start
|
|
48
|
+
|
|
49
|
+
=== Parse with a namespace (compliant)
|
|
50
|
+
|
|
51
|
+
`Mml.parse` expects a namespace by default (`namespace_exist: true`). It accepts
|
|
52
|
+
both default and prefixed forms:
|
|
53
|
+
|
|
54
|
+
[source,ruby]
|
|
55
|
+
----
|
|
56
|
+
require "mml"
|
|
57
|
+
|
|
58
|
+
# Default namespace
|
|
59
|
+
math = Mml.parse('<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi></math>')
|
|
60
|
+
|
|
61
|
+
# Prefixed namespace
|
|
62
|
+
math = Mml.parse('<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>x</mml:mi></mml:math>')
|
|
63
|
+
----
|
|
64
|
+
|
|
65
|
+
=== Parse without namespace (non-compliant)
|
|
66
|
+
|
|
67
|
+
Some XML schemas embed MathML without a namespace declaration, which is
|
|
68
|
+
non-compliant but common in practice. Pass `namespace_exist: false` to handle
|
|
69
|
+
this — the namespace is injected internally before parsing:
|
|
70
|
+
|
|
71
|
+
[source,ruby]
|
|
72
|
+
----
|
|
73
|
+
math = Mml.parse("<math><mi>x</mi></math>", namespace_exist: false)
|
|
74
|
+
----
|
|
75
|
+
|
|
76
|
+
=== Serialize to XML
|
|
77
|
+
|
|
78
|
+
[source,ruby]
|
|
79
|
+
----
|
|
80
|
+
# Default namespace (default)
|
|
81
|
+
math.to_xml
|
|
82
|
+
# => "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>x</mi></math>"
|
|
83
|
+
|
|
84
|
+
# Prefixed namespace
|
|
85
|
+
math.to_xml(prefix: true)
|
|
86
|
+
# => "<mml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"><mml:mi>x</mml:mi></mml:math>"
|
|
87
|
+
|
|
88
|
+
# Omit XML declaration
|
|
89
|
+
math.to_xml(declaration: false)
|
|
90
|
+
----
|
|
91
|
+
|
|
92
|
+
== Building MathML with the API
|
|
93
|
+
|
|
94
|
+
=== Leaf elements
|
|
95
|
+
|
|
96
|
+
Leaf elements (`Mi`, `Mn`, `Mo`, `Ms`, `Mtext`) hold text content in the `value`
|
|
97
|
+
attribute:
|
|
98
|
+
|
|
99
|
+
[source,ruby]
|
|
100
|
+
----
|
|
101
|
+
# An identifier: <mi>x</mi>
|
|
102
|
+
Mml::Mi.new(value: "x")
|
|
103
|
+
|
|
104
|
+
# A number: <mn>42</mn>
|
|
105
|
+
Mml::Mn.new(value: "42")
|
|
106
|
+
|
|
107
|
+
# An operator: <mo>+</mo>
|
|
108
|
+
Mml::Mo.new(value: "+")
|
|
109
|
+
|
|
110
|
+
# With attributes: <mi mathvariant="bold">x</mi>
|
|
111
|
+
Mml::Mi.new(value: "x", mathvariant: "bold")
|
|
112
|
+
----
|
|
113
|
+
|
|
114
|
+
=== Container elements
|
|
115
|
+
|
|
116
|
+
Container elements hold child elements via collection attributes named
|
|
117
|
+
`#{tag}_value`. The supported child types come from the `CommonAttributes` model
|
|
118
|
+
mixed into container classes.
|
|
119
|
+
|
|
120
|
+
[source,ruby]
|
|
121
|
+
----
|
|
122
|
+
# <mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow>
|
|
123
|
+
Mml::Mrow.new(
|
|
124
|
+
mi_value: [Mml::Mi.new(value: "x")],
|
|
125
|
+
mo_value: [Mml::Mo.new(value: "+")],
|
|
126
|
+
mn_value: [Mml::Mn.new(value: "1")],
|
|
127
|
+
)
|
|
128
|
+
----
|
|
129
|
+
|
|
130
|
+
=== Composing complex expressions
|
|
131
|
+
|
|
132
|
+
Build an expression tree by nesting elements, then wrap in `Mml::Math`:
|
|
133
|
+
|
|
134
|
+
[source,ruby]
|
|
135
|
+
----
|
|
136
|
+
# <math xmlns="http://www.w3.org/1998/Math/MathML">
|
|
137
|
+
# <mfrac><mi>a</mi><mi>b</mi></mfrac>
|
|
138
|
+
# </math>
|
|
139
|
+
math = Mml::Math.new(
|
|
140
|
+
mfrac_value: [
|
|
141
|
+
Mml::Mfrac.new(
|
|
142
|
+
mi_value: [Mml::Mi.new(value: "a"), Mml::Mi.new(value: "b")],
|
|
143
|
+
),
|
|
144
|
+
],
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
math.to_xml
|
|
148
|
+
----
|
|
149
|
+
|
|
150
|
+
=== Fractions, subscripts, and superscripts
|
|
151
|
+
|
|
152
|
+
[source,ruby]
|
|
153
|
+
----
|
|
154
|
+
# <msup><mi>x</mi><mn>2</mn></msup> — x²
|
|
155
|
+
Mml::Msup.new(mi_value: [Mml::Mi.new(value: "x")],
|
|
156
|
+
mn_value: [Mml::Mn.new(value: "2")])
|
|
157
|
+
|
|
158
|
+
# <msub><mi>a</mi><mn>1</mn></msup> — a₁
|
|
159
|
+
Mml::Msub.new(mi_value: [Mml::Mi.new(value: "a")],
|
|
160
|
+
mn_value: [Mml::Mn.new(value: "1")])
|
|
161
|
+
|
|
162
|
+
# <msubsup><mi>b</mi><mn>1</mn><mn>2</mn></msubsup> — b₁²
|
|
163
|
+
Mml::Msubsup.new(mi_value: [Mml::Mi.new(value: "b")],
|
|
164
|
+
mn_value: [Mml::Mn.new(value: "1"),
|
|
165
|
+
Mml::Mn.new(value: "2")])
|
|
166
|
+
|
|
167
|
+
# <mfrac linethickness="0"><mi>a</mi><mi>b</mi></mfrac> — a/b
|
|
168
|
+
Mml::Mfrac.new(
|
|
169
|
+
linethickness: "0",
|
|
170
|
+
mi_value: [Mml::Mi.new(value: "a"), Mml::Mi.new(value: "b")],
|
|
171
|
+
)
|
|
172
|
+
----
|
|
173
|
+
|
|
174
|
+
=== Tables
|
|
175
|
+
|
|
176
|
+
`Mtable` uses typed `mtr_value` and `mlabeledtr_value` attributes for its rows:
|
|
177
|
+
|
|
178
|
+
[source,ruby]
|
|
179
|
+
----
|
|
180
|
+
# <mtable>
|
|
181
|
+
# <mtr><mtd><mi>a</mi></mtd><mtd><mi>b</mi></mtd></mtr>
|
|
182
|
+
# </mtable>
|
|
183
|
+
Mml::Mtable.new(
|
|
184
|
+
mtr_value: [
|
|
185
|
+
Mml::Mtr.new(
|
|
186
|
+
mtd_value: [
|
|
187
|
+
Mml::Mtd.new(mi_value: [Mml::Mi.new(value: "a")]),
|
|
188
|
+
Mml::Mtd.new(mi_value: [Mml::Mi.new(value: "b")]),
|
|
189
|
+
],
|
|
190
|
+
),
|
|
191
|
+
],
|
|
192
|
+
)
|
|
193
|
+
----
|
|
194
|
+
|
|
195
|
+
=== Parsing, modifying, and re-serializing
|
|
196
|
+
|
|
197
|
+
The object graph is fully mutable — parse, modify attributes or children, then
|
|
198
|
+
serialize back:
|
|
199
|
+
|
|
200
|
+
[source,ruby]
|
|
201
|
+
----
|
|
202
|
+
math = Mml.parse('<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi></math>')
|
|
203
|
+
|
|
204
|
+
# Modify the root element's display attribute
|
|
205
|
+
math.display = "block"
|
|
206
|
+
|
|
207
|
+
# Serialize with the changes
|
|
208
|
+
math.to_xml
|
|
209
|
+
# => "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\">...</math>"
|
|
210
|
+
----
|
|
211
|
+
|
|
212
|
+
== Architecture
|
|
213
|
+
|
|
214
|
+
Mml follows a data mapper pattern where each MathML element is a Ruby class
|
|
215
|
+
under the `Mml::` namespace, inheriting from `Lutaml::Model::Serializable`.
|
|
216
|
+
|
|
217
|
+
=== Element classes
|
|
218
|
+
|
|
219
|
+
Two element patterns:
|
|
220
|
+
|
|
221
|
+
* *Leaf elements* (`Mi`, `Mn`, `Mo`, `Ms`, `Mtext`, `Mspace`): hold text content
|
|
222
|
+
via `map_content to: :value`
|
|
223
|
+
* *Container elements* (`Math`, `Mrow`, `Mfrac`, `Mtable`, `Msubsup`): hold
|
|
224
|
+
child elements via `mixed_content`
|
|
225
|
+
|
|
226
|
+
[source,ruby]
|
|
227
|
+
----
|
|
228
|
+
# Leaf element — text content
|
|
229
|
+
module Mml
|
|
230
|
+
class Mi < Lutaml::Model::Serializable
|
|
231
|
+
attribute :value, :string
|
|
232
|
+
|
|
233
|
+
xml do
|
|
234
|
+
namespace Namespace
|
|
235
|
+
element "mi"
|
|
236
|
+
map_content to: :value
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Container element — child elements
|
|
242
|
+
module Mml
|
|
243
|
+
class Mrow < Lutaml::Model::Serializable
|
|
244
|
+
xml do
|
|
245
|
+
namespace Namespace
|
|
246
|
+
element "mrow"
|
|
247
|
+
mixed_content
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
----
|
|
252
|
+
|
|
253
|
+
=== CommonAttributes
|
|
254
|
+
|
|
255
|
+
Container elements that can hold arbitrary MathML children use a shared
|
|
256
|
+
`CommonAttributes` model.
|
|
257
|
+
|
|
258
|
+
The classes that receive it are listed in
|
|
259
|
+
`Configuration::COMMON_ATTRIBUTES_CLASSES`.
|
|
260
|
+
|
|
261
|
+
=== Namespace
|
|
262
|
+
|
|
263
|
+
All elements declare `namespace Namespace` using the MathML namespace URI
|
|
264
|
+
(`http://www.w3.org/1998/Math/MathML`) with prefix `mml`. The `Mml.parse`
|
|
265
|
+
method handles three input forms:
|
|
266
|
+
|
|
267
|
+
* Default namespace: `<math xmlns="http://www.w3.org/1998/Math/MathML">`
|
|
268
|
+
* Prefixed: `<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">`
|
|
269
|
+
* No namespace: handled by injecting the namespace before parsing
|
|
270
|
+
|
|
271
|
+
=== Configuration
|
|
272
|
+
|
|
273
|
+
[source,ruby]
|
|
274
|
+
----
|
|
275
|
+
# Switch XML adapter
|
|
276
|
+
Mml::Configuration.adapter = :nokogiri
|
|
277
|
+
|
|
278
|
+
# Register custom model replacements
|
|
279
|
+
Mml::Configuration.custom_models = { Mi => MyCustomMi }
|
|
280
|
+
----
|
|
281
|
+
|
|
282
|
+
== Supported elements
|
|
283
|
+
|
|
284
|
+
Mml supports the following MathML 3 presentation elements:
|
|
285
|
+
|
|
286
|
+
`math`, `mi`, `mn`, `mo`, `ms`, `mtext`, `mspace`, `mglyph`
|
|
287
|
+
`mrow`, `mfrac`, `msqrt`, `mroot`, `mstyle`, `merror`, `mpadded`,
|
|
288
|
+
`mphantom`, `mfenced`, `menclose`, `maction`
|
|
289
|
+
`msub`, `msup`, `msubsup`, `munder`, `mover`, `munderover`,
|
|
290
|
+
`mmultiscripts`, `mprescripts`
|
|
291
|
+
`mtable`, `mtr`, `mtd`, `mlabeledtr`
|
|
292
|
+
`mstack`, `msrow`, `mscarries`, `mscarry`, `msline`, `msgroup`, `mlongdiv`
|
|
293
|
+
`mfraction`, `semantics`, `none`
|
|
294
|
+
|
|
295
|
+
== Development
|
|
296
|
+
|
|
297
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then run
|
|
298
|
+
`rake` to run the tests and linter. You can also run `bin/console` for an
|
|
299
|
+
interactive prompt.
|
|
300
|
+
|
|
301
|
+
[source,bash]
|
|
302
|
+
----
|
|
303
|
+
rake # Run specs + rubocop
|
|
304
|
+
bundle exec rspec # Run tests
|
|
305
|
+
bundle exec rubocop # Lint
|
|
306
|
+
bin/console # Interactive IRB
|
|
307
|
+
----
|
|
308
|
+
|
|
309
|
+
== Contributing
|
|
310
|
+
|
|
311
|
+
Bug reports and pull requests are welcome on GitHub at
|
|
312
|
+
https://github.com/plurimath/mml.
|
|
313
|
+
|
|
314
|
+
== Copyright and license
|
|
6
315
|
|
|
7
|
-
|
|
316
|
+
Copyright Ribose Inc.
|
|
8
317
|
|
|
9
|
-
|
|
318
|
+
https://opensource.org/licenses/BSD-2-Clause[BSD-2-Clause License].
|
data/lib/mml/configuration.rb
CHANGED
|
@@ -43,8 +43,7 @@ module Mml
|
|
|
43
43
|
].freeze
|
|
44
44
|
|
|
45
45
|
COMMON_ATTRIBUTES_CLASSES = %w[
|
|
46
|
-
|
|
47
|
-
MathWithNamespace
|
|
46
|
+
Math
|
|
48
47
|
Mmultiscripts
|
|
49
48
|
Munderover
|
|
50
49
|
Semantics
|
|
@@ -94,7 +93,7 @@ module Mml
|
|
|
94
93
|
end
|
|
95
94
|
|
|
96
95
|
def adapter=(adapter)
|
|
97
|
-
Lutaml::Model::Config.xml_adapter_type = adapter
|
|
96
|
+
Lutaml::Model::Config.xml_adapter_type = adapter
|
|
98
97
|
end
|
|
99
98
|
|
|
100
99
|
def class_for(class_name)
|
data/lib/mml/maction.rb
CHANGED
|
@@ -8,12 +8,13 @@ module Mml
|
|
|
8
8
|
attribute :selection, :string
|
|
9
9
|
|
|
10
10
|
xml do
|
|
11
|
-
|
|
11
|
+
namespace Namespace
|
|
12
|
+
element "maction"
|
|
12
13
|
|
|
13
|
-
map_attribute "mathcolor", to: :mathcolor
|
|
14
|
-
map_attribute "mathbackground", to: :mathbackground
|
|
15
|
-
map_attribute "actiontype", to: :actiontype
|
|
16
|
-
map_attribute "selection", to: :selection
|
|
14
|
+
map_attribute "mathcolor", to: :mathcolor
|
|
15
|
+
map_attribute "mathbackground", to: :mathbackground
|
|
16
|
+
map_attribute "actiontype", to: :actiontype
|
|
17
|
+
map_attribute "selection", to: :selection
|
|
17
18
|
end
|
|
18
19
|
end
|
|
19
20
|
end
|
data/lib/mml/maligngroup.rb
CHANGED
|
@@ -7,11 +7,12 @@ module Mml
|
|
|
7
7
|
attribute :groupalign, :string
|
|
8
8
|
|
|
9
9
|
xml do
|
|
10
|
-
|
|
10
|
+
namespace Namespace
|
|
11
|
+
element "maligngroup"
|
|
11
12
|
|
|
12
|
-
map_attribute "mathcolor", to: :mathcolor
|
|
13
|
-
map_attribute "mathbackground", to: :mathbackground
|
|
14
|
-
map_attribute "groupalign", to: :groupalign
|
|
13
|
+
map_attribute "mathcolor", to: :mathcolor
|
|
14
|
+
map_attribute "mathbackground", to: :mathbackground
|
|
15
|
+
map_attribute "groupalign", to: :groupalign
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
end
|
data/lib/mml/malignmark.rb
CHANGED
|
@@ -7,11 +7,12 @@ module Mml
|
|
|
7
7
|
attribute :edge, :string
|
|
8
8
|
|
|
9
9
|
xml do
|
|
10
|
-
|
|
10
|
+
namespace Namespace
|
|
11
|
+
element "malignmark"
|
|
11
12
|
|
|
12
|
-
map_attribute "mathcolor", to: :mathcolor
|
|
13
|
-
map_attribute "mathbackground", to: :mathbackground
|
|
14
|
-
map_attribute "edge", to: :edge
|
|
13
|
+
map_attribute "mathcolor", to: :mathcolor
|
|
14
|
+
map_attribute "mathbackground", to: :mathbackground
|
|
15
|
+
map_attribute "edge", to: :edge
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
end
|
data/lib/mml/math.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mml
|
|
4
|
+
class Math < Lutaml::Model::Serializable
|
|
5
|
+
attribute :display, :string
|
|
6
|
+
|
|
7
|
+
xml do
|
|
8
|
+
namespace Namespace
|
|
9
|
+
element "math"
|
|
10
|
+
mixed_content
|
|
11
|
+
|
|
12
|
+
map_attribute :display, to: :display
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# For backward compatibility, we keep MathWithNamespace as an alias to Math.
|
|
17
|
+
MathWithNamespace = Math
|
|
18
|
+
end
|
data/lib/mml/menclose.rb
CHANGED
|
@@ -7,11 +7,13 @@ module Mml
|
|
|
7
7
|
attribute :notation, :string
|
|
8
8
|
|
|
9
9
|
xml do
|
|
10
|
-
|
|
10
|
+
namespace Namespace
|
|
11
|
+
element "menclose"
|
|
12
|
+
mixed_content
|
|
11
13
|
|
|
12
|
-
map_attribute "mathcolor", to: :mathcolor
|
|
13
|
-
map_attribute "mathbackground", to: :mathbackground
|
|
14
|
-
map_attribute "notation", to: :notation
|
|
14
|
+
map_attribute "mathcolor", to: :mathcolor
|
|
15
|
+
map_attribute "mathbackground", to: :mathbackground
|
|
16
|
+
map_attribute "notation", to: :notation
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
end
|
data/lib/mml/merror.rb
CHANGED
|
@@ -6,10 +6,12 @@ module Mml
|
|
|
6
6
|
attribute :mathcolor, :string
|
|
7
7
|
|
|
8
8
|
xml do
|
|
9
|
-
|
|
9
|
+
namespace Namespace
|
|
10
|
+
element "merror"
|
|
11
|
+
mixed_content
|
|
10
12
|
|
|
11
|
-
map_attribute "mathcolor", to: :mathcolor
|
|
12
|
-
map_attribute "mathbackground", to: :mathbackground
|
|
13
|
+
map_attribute "mathcolor", to: :mathcolor
|
|
14
|
+
map_attribute "mathbackground", to: :mathbackground
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|
data/lib/mml/mfenced.rb
CHANGED
|
@@ -10,15 +10,17 @@ module Mml
|
|
|
10
10
|
attribute :open, :string
|
|
11
11
|
|
|
12
12
|
xml do
|
|
13
|
-
|
|
13
|
+
namespace Namespace
|
|
14
|
+
element "mfenced"
|
|
15
|
+
mixed_content
|
|
14
16
|
|
|
15
17
|
map_content to: :content
|
|
16
18
|
|
|
17
|
-
map_attribute "mathbackground", to: :mathbackground
|
|
18
|
-
map_attribute "separators", to: :separators
|
|
19
|
-
map_attribute "mathcolor", to: :mathcolor
|
|
20
|
-
map_attribute "close", to: :close
|
|
21
|
-
map_attribute "open", to: :open
|
|
19
|
+
map_attribute "mathbackground", to: :mathbackground
|
|
20
|
+
map_attribute "separators", to: :separators
|
|
21
|
+
map_attribute "mathcolor", to: :mathcolor
|
|
22
|
+
map_attribute "close", to: :close
|
|
23
|
+
map_attribute "open", to: :open
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
end
|