File tree Expand file tree Collapse file tree 4 files changed +54
-1
lines changed Expand file tree Collapse file tree 4 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 3
3
## Enhancements
4
4
5
5
- Added support for PHP 8.4 by [ @Progi1984 ] ( https://github/Progi1984 ) in [ #18 ] ( https://github.com/PHPOffice/Math/pull/18 )
6
+ - MathML Writer : Write Semantics by [ @codinglist ] ( https://github/codinglist ) & [ @Progi1984 ] ( https://github/Progi1984 ) in [ #19 ] ( https://github.com/PHPOffice/Math/pull/19 ) & [ #20 ] ( https://github.com/PHPOffice/Math/pull/20 )
6
7
7
8
## Bug fixes
8
9
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ Math is an open source project licensed under the terms of [MIT](https://github.
48
48
| ** Simple** | Fraction | :material-check: | :material-check: |
49
49
| | Superscript | :material-check: | |
50
50
| ** Architectural** | Row | :material-check: | :material-check: |
51
- | | Semantics | | |
51
+ | | Semantics | :material-check: | |
52
52
53
53
## Contributing
54
54
Original file line number Diff line number Diff line change @@ -40,6 +40,26 @@ protected function writeElementItem(Element\AbstractElement $element): void
40
40
{
41
41
$ tagName = $ this ->getElementTagName ($ element );
42
42
43
+ // Element\AbstractGroupElement
44
+ if ($ element instanceof Element \Semantics) {
45
+ $ this ->output ->startElement ($ tagName );
46
+ // Write elements
47
+ foreach ($ element ->getElements () as $ childElement ) {
48
+ $ this ->writeElementItem ($ childElement );
49
+ }
50
+
51
+ // Write annotations
52
+ foreach ($ element ->getAnnotations () as $ encoding => $ annotation ) {
53
+ $ this ->output ->startElement ('annotation ' );
54
+ $ this ->output ->writeAttribute ('encoding ' , $ encoding );
55
+ $ this ->output ->text ($ annotation );
56
+ $ this ->output ->endElement ();
57
+ }
58
+ $ this ->output ->endElement ();
59
+
60
+ return ;
61
+ }
62
+
43
63
// Element\AbstractGroupElement
44
64
if ($ element instanceof Element \AbstractGroupElement) {
45
65
$ this ->output ->startElement ($ tagName );
@@ -121,6 +141,9 @@ protected function getElementTagName(Element\AbstractElement $element): string
121
141
if ($ element instanceof Element \Operator) {
122
142
return 'mo ' ;
123
143
}
144
+ if ($ element instanceof Element \Semantics) {
145
+ return 'semantics ' ;
146
+ }
124
147
125
148
throw new NotImplementedException (sprintf (
126
149
'%s : The element of the class `%s` has no tag name ' ,
Original file line number Diff line number Diff line change @@ -80,6 +80,35 @@ public function testWriteFraction(): void
80
80
$ this ->assertIsSchemaMathMLValid ($ output );
81
81
}
82
82
83
+ public function testWriteSemantics (): void
84
+ {
85
+ $ opTimes = new Element \Operator ('⁢ ' );
86
+
87
+ $ math = new Math ();
88
+
89
+ $ semantics = new Element \Semantics ();
90
+ $ semantics ->add (new Element \Identifier ('y ' ));
91
+ $ semantics ->addAnnotation ('application/x-tex ' , ' y ' );
92
+
93
+ $ math ->add ($ semantics );
94
+
95
+ $ writer = new MathML ();
96
+ $ output = $ writer ->write ($ math );
97
+
98
+ $ expected = '<?xml version="1.0" encoding="UTF-8"?> '
99
+ . PHP_EOL
100
+ . '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"> '
101
+ . '<math xmlns="http://www.w3.org/1998/Math/MathML"> '
102
+ . '<semantics> '
103
+ . '<mi>y</mi> '
104
+ . '<annotation encoding="application/x-tex"> y </annotation> '
105
+ . '</semantics> '
106
+ . '</math> '
107
+ . PHP_EOL ;
108
+ $ this ->assertEquals ($ expected , $ output );
109
+ $ this ->assertIsSchemaMathMLValid ($ output );
110
+ }
111
+
83
112
public function testWriteNotImplemented (): void
84
113
{
85
114
$ this ->expectException (NotImplementedException::class);
You can’t perform that action at this time.
0 commit comments