mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-24 15:44:33 +00:00
Merge "Support for chemical formulae"
This commit is contained in:
commit
b144031847
|
@ -165,6 +165,7 @@ class MathHooks {
|
|||
*/
|
||||
static function onParserFirstCallInit( $parser ) {
|
||||
$parser->setHook( 'math', array( 'MathHooks', 'mathTagHook' ) );
|
||||
$parser->setHook( 'ce', array( 'MathHooks', 'ceTagHook' ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -371,4 +372,18 @@ class MathHooks {
|
|||
$wgMathDisableTexFilter = MathRenderer::getDisableTexFilter();
|
||||
$wgDefaultUserOptions['math'] = self::mathModeToString( $wgDefaultUserOptions['math'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for the <ce> parser hook.
|
||||
*
|
||||
* @param $content (the LaTeX input)
|
||||
* @param $attributes
|
||||
* @param Parser $parser
|
||||
* @return array
|
||||
*/
|
||||
static function ceTagHook( $content, $attributes, $parser ) {
|
||||
$attributes['chem'] = true;
|
||||
return MathHooks::mathTagHook( '\ce{' . $content . '}', $attributes, $parser );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use MediaWiki\Logger\LoggerFactory;
|
|||
class MathMathML extends MathRenderer {
|
||||
|
||||
protected $defaultAllowedRootElements = array( 'math' );
|
||||
protected $restbaseInputTypes = array( 'tex', 'inline-tex' );
|
||||
protected $restbaseInputTypes = array( 'tex', 'inline-tex', 'chem' );
|
||||
protected $allowedRootElements = '';
|
||||
protected $hosts;
|
||||
|
||||
|
@ -33,6 +33,8 @@ class MathMathML extends MathRenderer {
|
|||
$this->setMathml( '<math>' . $tex . '</math>' );
|
||||
} elseif ( $params['type'] == 'ascii' ) {
|
||||
$this->inputType = 'ascii';
|
||||
} elseif ( $params['type'] == 'chem' ){
|
||||
$this->inputType = 'chem';
|
||||
}
|
||||
}
|
||||
if ( !isset( $params['display'] ) && $this->getMathStyle() == 'inlineDisplaystyle' ) {
|
||||
|
|
|
@ -157,6 +157,10 @@ abstract class MathRenderer {
|
|||
unset( $params['type'] );
|
||||
}
|
||||
}
|
||||
if ( isset( $params['chem'] ) ) {
|
||||
$mode = 'mathml';
|
||||
$params['type'] = 'chem';
|
||||
}
|
||||
switch ( $mode ) {
|
||||
case 'source':
|
||||
$renderer = new MathSource( $tex, $params );
|
||||
|
|
|
@ -54,6 +54,15 @@ class MathRestbaseInterfaceTest extends MediaWikiTestCase {
|
|||
$this->assertEquals( 'Illegal TeX function', $rbi->getError()->error->message );
|
||||
}
|
||||
|
||||
public function testChem() {
|
||||
$input = '\ce{H2O}';
|
||||
$rbi = new MathRestbaseInterface( $input, 'chem' );
|
||||
$this->assertTrue( $rbi->checkTeX(), "Assuming that $input is valid input." );
|
||||
$this->assertTrue( $rbi->getSuccess(), "Assuming that $input is valid input." );
|
||||
$this->assertEquals( '{\ce {H2O}}', $rbi->getCheckedTex() );
|
||||
$this->assertContains( '<msubsup>', $rbi->getMathML() );
|
||||
$this->assertContains( '<mtext>H</mtext>', $rbi->getMathML() );
|
||||
}
|
||||
/**
|
||||
* @expectedException MWException
|
||||
* @expectedExceptionMessage TeX input is invalid.
|
||||
|
|
Loading…
Reference in a new issue