This commit is contained in:
wangjinlei
2024-12-31 10:28:40 +08:00
parent 145b0ab8a5
commit a54a837670
1179 changed files with 2686 additions and 230376 deletions

View File

@@ -19,7 +19,7 @@ class MathML implements ReaderInterface
/** @var DOMDocument */
private $dom;
/** @var DOMXpath */
/** @var DOMXPath */
private $xpath;
public function read(string $content): ?Math
@@ -48,7 +48,7 @@ class MathML implements ReaderInterface
*/
protected function parseNode(?DOMNode $nodeRowElement, $parent): void
{
$this->xpath = new DOMXpath($this->dom);
$this->xpath = new DOMXPath($this->dom);
foreach ($this->xpath->query('*', $nodeRowElement) ?: [] as $nodeElement) {
if ($parent instanceof Element\Semantics
&& $nodeElement instanceof DOMElement
@@ -61,12 +61,7 @@ class MathML implements ReaderInterface
continue;
}
$element = $this->getElement($nodeElement);
$parent->add($element);
if ($element instanceof Element\AbstractGroupElement) {
$this->parseNode($nodeElement, $element);
}
$parent->add($this->getElement($nodeElement));
}
}
@@ -108,7 +103,11 @@ class MathML implements ReaderInterface
return new Element\Operator($nodeValue);
case 'mrow':
return new Element\Row();
$mrow = new Element\Row();
$this->parseNode($nodeElement, $mrow);
return $mrow;
case 'msup':
$nodeList = $this->xpath->query('*', $nodeElement);
if ($nodeList && $nodeList->length == 2) {
@@ -124,7 +123,11 @@ class MathML implements ReaderInterface
$nodeElement->nodeName
));
case 'semantics':
return new Element\Semantics();
$semantics = new Element\Semantics();
$this->parseNode($nodeElement, $semantics);
return $semantics;
default:
throw new NotImplementedException(sprintf(
'%s : The tag `%s` is not implemented',

View File

@@ -18,7 +18,7 @@ class OfficeMathML implements ReaderInterface
/** @var Math */
protected $math;
/** @var DOMXpath */
/** @var DOMXPath */
protected $xpath;
/** @var string[] */
@@ -52,7 +52,7 @@ class OfficeMathML implements ReaderInterface
*/
protected function parseNode(?DOMNode $nodeRowElement, $parent): void
{
$this->xpath = new DOMXpath($this->dom);
$this->xpath = new DOMXPath($this->dom);
foreach ($this->xpath->query('*', $nodeRowElement) ?: [] as $nodeElement) {
$element = $this->getElement($nodeElement);
$parent->add($element);