diff --git a/src/MathMathML.php b/src/MathMathML.php index 6efa5b1..5b343a0 100644 --- a/src/MathMathML.php +++ b/src/MathMathML.php @@ -480,6 +480,9 @@ class MathMathML extends MathRenderer { if ( $this->getID() !== '' ) { $attribs['id'] = $this->getID(); } + if ( isset( $this->params['qid'] ) && preg_match( '/Q\d+/', $this->params['qid'] ) ) { + $attribs['data-qid'] = $this->params['qid']; + } $output = Html::openElement( $element, $attribs ); // MathML has to be wrapped into a div or span in order to be able to hide it. // Remove displayStyle attributes set by the MathML converter diff --git a/tests/phpunit/MathMathMLTest.php b/tests/phpunit/MathMathMLTest.php index 45d8b40..5b7bb32 100644 --- a/tests/phpunit/MathMathMLTest.php +++ b/tests/phpunit/MathMathMLTest.php @@ -260,6 +260,19 @@ class MathMathMLTest extends MediaWikiTestCase { ->with( 'math-tracking-category-mhchem-deprecation' ); $renderer->addTrackingCategories( $parser ); } + + public function testGetHtmlOutputQID() { + $math = new MathMathML( "a+b", [ "qid" => "Q123" ] ); + $out = $math->getHtmlOutput(); + $this->assertContains( "data-qid=\"Q123\"", $out ); + } + + public function testGetHtmlOutputInvalidQID() { + // test with not valid ID. An ID must match /Q\d+/ + $math = new MathMathML( "a+b", [ "qid" => "123" ] ); + $out = $math->getHtmlOutput(); + $this->assertNotContains( "data-qid", $out ); + } } /**