Implement mhchemParser maintenance in PHP

Change-Id: I4c97d493a35b2ae536422c0121eec6a33c3ce7ec
This commit is contained in:
Stegmujo 2023-06-16 08:37:25 +00:00 committed by Physikerwelt
parent e0d66eab55
commit 8c5a694656
2 changed files with 31 additions and 2 deletions

View file

@ -10,6 +10,10 @@
<exclude name="MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage" />
<exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
</rule>
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>/src/TexVC/Mhchem/MhchemPatterns.php</exclude-pattern>
<exclude-pattern>/src/TexVC/Mhchem/MhchemStateMachines.php</exclude-pattern>
</rule>
<exclude-pattern>/src/TexVC/Parser.php</exclude-pattern>
<file>.</file>
<arg name="extensions" value="php" />

View file

@ -83,13 +83,24 @@ class JsonToMathML extends Maintenance {
}
}
$mmlLaTeXML = $this->fetchMathML( $entry['tex'], $entry['type'], 'latexml' );
$allEntries[] = [
$entryToAdd = [
"tex" => $entry['tex'],
"type" => $entry['type'],
"mmlMathoid" => $mmlMathoid,
"mmlLaTeXML" => $mmlLaTeXML
];
if ( array_key_exists( "texNew", $entry ) ) {
$entryToAdd["texNew"] = $entry["texNew"];
}
if ( array_key_exists( "typeC", $entry ) ) {
$entryToAdd["typeC"] = $entry["typeC"];
}
if ( array_key_exists( "description", $entry ) ) {
$entryToAdd["description"] = $entry["description"];
}
$allEntries[] = $entryToAdd;
} catch ( Exception $e ) {
$allEntries[] = [
"tex" => $entry['tex'],
@ -140,6 +151,20 @@ class JsonToMathML extends Maintenance {
];
}
break;
case 3:
// Example file Mhchemv4tex.json
foreach ( $fileData as $group => $cases ) {
foreach ( $cases as $case ) {
$inputF[] = [
"description" => $group,
"tex" => $case["tex"],
"texNew" => $case["texNew"],
"type" => "chem",
"typeC" => $case["type"]
];
}
}
break;
}
return $inputF;
}