mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Fix ce statements and displaystyle for chem rendering on wikipages
* rollback some previous changes for ce env in Parserhookhandler * some minor fixes for feedback in previous commit * set tex mode for mhchem preprocessor, since MediaWiki Hooks add explicit ce tags: i.e. frormula coming to TexVC look like "{\displaystyle \ce{ C6H5-CHO }}" Bug: T348975 Change-Id: Id06852b030f9ea77f016289d4f9e2258d5a9f0d4
This commit is contained in:
parent
5cce2b4512
commit
24bcd11e5b
|
@ -104,8 +104,7 @@ class ParserHooksHandler implements
|
|||
*/
|
||||
public function chemTagHook( ?string $content, array $attributes, Parser $parser ) {
|
||||
$attributes['chem'] = true;
|
||||
$content = $parser->getOptions()->getOption( 'math' ) == "native" ? $content : "\ce{" . $content . "}";
|
||||
return $this->mathTagHook( $content, $attributes, $parser );
|
||||
return $this->mathTagHook( '\ce{' . $content . '}', $attributes, $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,8 +91,8 @@ class LocalChecker extends BaseChecker {
|
|||
}
|
||||
|
||||
public function runCheck(): array {
|
||||
if ( $this->type === "chem" ) {
|
||||
$options = [ "usemhchem" => true, "usemhchemtexified" => true ];
|
||||
if ( $this->type == 'chem' ) {
|
||||
$options = [ 'usemhchem' => true, 'usemhchemtexified' => true ];
|
||||
$texifyMhchem = true;
|
||||
} else {
|
||||
$options = [];
|
||||
|
|
|
@ -64,7 +64,7 @@ class TexVC {
|
|||
if ( $texifyMhchem && isset( $options["usemhchem"] ) && $options["usemhchem"] ) {
|
||||
// Parse the chemical equations to TeX with mhChemParser in PHP as preprocessor
|
||||
$mhChemParser = new MHChemParser();
|
||||
$input = $mhChemParser->toTex( $input, "ce", true );
|
||||
$input = $mhChemParser->toTex( $input, "tex", true );
|
||||
}
|
||||
|
||||
$options = ParserUtil::createOptions( $options );
|
||||
|
|
|
@ -15,6 +15,17 @@ use MediaWikiUnitTestCase;
|
|||
*/
|
||||
final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
|
||||
|
||||
public function testGUIStyleNotation() {
|
||||
$input = "{\displaystyle \ce{ C6H5-CHO }}";
|
||||
$texVC = new TexVC();
|
||||
$options = [ "usemhchem" => true, "usemhchemtexified" => true ];
|
||||
$warnings = [];
|
||||
$res = $texVC->check( $input, $options, $warnings, true );
|
||||
$mml = $res['input']->renderMML();
|
||||
$this->assertStringContainsString( '<mpadded', $mml );
|
||||
$this->assertStringContainsString( '<mphantom', $mml );
|
||||
}
|
||||
|
||||
public static function provideTestCasesLetters() {
|
||||
return [
|
||||
[ "Alpha" , "A" ],
|
||||
|
@ -206,7 +217,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testSmash1() {
|
||||
$input = "\\smash[t]{2}";
|
||||
$input = "\ce{\\smash[t]{2}}";
|
||||
$texVC = new TexVC();
|
||||
$warnings = [];
|
||||
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
|
||||
|
@ -215,7 +226,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testSmash2() {
|
||||
$input = "\\smash[b]{x}";
|
||||
$input = "\ce{\\smash[b]{x}}";
|
||||
$texVC = new TexVC();
|
||||
$warnings = [];
|
||||
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
|
||||
|
@ -224,7 +235,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testSmash3() {
|
||||
$input = "\\smash[bt]{2}";
|
||||
$input = "\ce{\\smash[bt]{2}}";
|
||||
$texVC = new TexVC();
|
||||
$warnings = [];
|
||||
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
|
||||
|
@ -234,7 +245,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testSmash4() {
|
||||
$input = "\\smash[tb]{2}";
|
||||
$input = "\ce{\\smash[tb]{2}}";
|
||||
$texVC = new TexVC();
|
||||
$warnings = [];
|
||||
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
|
||||
|
@ -244,7 +255,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public function testSmash5() {
|
||||
$input = "\\smash{2}";
|
||||
$input = "\ce{\\smash{2}}";
|
||||
$texVC = new TexVC();
|
||||
$warnings = [];
|
||||
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
|
||||
|
|
Loading…
Reference in a new issue