mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-09-23 02:09:06 +00:00
LaTeXML: Remove SVG fallback images
Removes Fallback images for LaTeXML rendering Change-Id: Id158de53b3f68f85fe55a3f7ace9abdc55c21160
This commit is contained in:
parent
3bb26a3873
commit
4da2778a29
|
@ -148,42 +148,8 @@ class MathLaTeXML extends MathMathML {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the SVG image based on the MathML input
|
||||
* No cache is used.
|
||||
* @return bool
|
||||
*/
|
||||
public function calculateSvg() {
|
||||
$renderer = new MathMathML( $this->getTex() );
|
||||
$renderer->setMathml( $this->getMathml() );
|
||||
$renderer->setMode( MathConfig::MODE_LATEXML );
|
||||
$renderer->setPurge();
|
||||
$res = $renderer->render();
|
||||
if ( $res == true ) {
|
||||
$this->setSvg( $renderer->getSvg() );
|
||||
} else {
|
||||
$lastError = $renderer->getLastError();
|
||||
LoggerFactory::getInstance( 'Math' )->error(
|
||||
'Failed to convert LaTeXML-MathML to SVG:' . $lastError );
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SVG image
|
||||
*
|
||||
* @param string $render if set to 'render' (default) and no SVG image exists, the function
|
||||
* tries to generate it on the fly.
|
||||
* Otherwise, if set to 'cached', and there is no SVG in the database
|
||||
* cache, an empty string is returned.
|
||||
*
|
||||
* @return string XML-Document of the rendered SVG
|
||||
*/
|
||||
public function getSvg( $render = 'render' ) {
|
||||
if ( $render == 'render' && ( $this->isPurge() || $this->svg == '' ) ) {
|
||||
$this->calculateSvg();
|
||||
}
|
||||
return parent::getSvg( $render );
|
||||
public function getHtmlOutput( bool $svg = true ): string {
|
||||
return parent::getHtmlOutput( false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -450,15 +450,18 @@ class MathMathML extends MathRenderer {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool $svg
|
||||
* @return string Html output that is embedded in the page
|
||||
*/
|
||||
public function getHtmlOutput() {
|
||||
public function getHtmlOutput( bool $svg = true ): string {
|
||||
$config = MediaWikiServices::getInstance()->getMainConfig();
|
||||
$enableLinks = $config->get( "MathEnableFormulaLinks" );
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
if ( $this->getMathStyle() === 'display' ) {
|
||||
$element = 'div';
|
||||
$mml_class = 'mwe-math-mathml-display';
|
||||
} else {
|
||||
$element = 'span';
|
||||
$mml_class = 'mwe-math-mathml-inline';
|
||||
}
|
||||
$attribs = [ 'class' => 'mwe-math-element' ];
|
||||
if ( $this->getID() !== '' ) {
|
||||
|
@ -480,10 +483,21 @@ class MathMathML extends MathRenderer {
|
|||
if ( $this->getMathStyle() == 'display' ) {
|
||||
$mml = preg_replace( '/<math/', '<math display="block"', $mml );
|
||||
}
|
||||
$output .= Html::rawElement( $element, [
|
||||
'class' => $this->getClassName(), 'style' => 'display: none;'
|
||||
], $mml );
|
||||
$output .= $this->getFallbackImage();
|
||||
|
||||
if ( $svg ) {
|
||||
$mml_attribs = [
|
||||
'class' => $this->getClassName(),
|
||||
'style' => 'display: none;'
|
||||
];
|
||||
} else {
|
||||
$mml_attribs = [
|
||||
'class' => $mml_class,
|
||||
];
|
||||
}
|
||||
$output .= Html::rawElement( $element, $mml_attribs, $mml );
|
||||
if ( $svg ) {
|
||||
$output .= $this->getFallbackImage();
|
||||
}
|
||||
|
||||
if ( $hyperlink && $enableLinks ) {
|
||||
$output = Html::rawElement( 'a',
|
||||
|
|
|
@ -60,7 +60,7 @@ class MathNativeMML extends MathMathML {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getHtmlOutput(): string {
|
||||
public function getHtmlOutput( bool $svg = true ): string {
|
||||
return $this->getMathml();
|
||||
}
|
||||
|
||||
|
|
|
@ -143,9 +143,10 @@ abstract class MathRenderer {
|
|||
abstract public function render();
|
||||
|
||||
/**
|
||||
* @param bool $svg
|
||||
* @return string Html output that is embedded in the page
|
||||
*/
|
||||
abstract public function getHtmlOutput();
|
||||
abstract public function getHtmlOutput( bool $svg = true ): string;
|
||||
|
||||
/**
|
||||
* texvc error messages
|
||||
|
|
|
@ -36,9 +36,10 @@ class MathSource extends MathRenderer {
|
|||
/**
|
||||
* Renders TeX by outputting it to the browser in a span tag
|
||||
*
|
||||
* @param bool $svg
|
||||
* @return string span tag with TeX
|
||||
*/
|
||||
public function getHtmlOutput() {
|
||||
public function getHtmlOutput( bool $svg = true ): string {
|
||||
# No need to render or parse anything more!
|
||||
# New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
|
|
|
@ -200,6 +200,14 @@ class MathMathMLTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertStringNotContainsString( "data-qid", $out );
|
||||
}
|
||||
|
||||
public function testGetHtmlOutputNoSvg() {
|
||||
$math = new MathMathML( "a+b" );
|
||||
$out = $math->getHtmlOutput( false );
|
||||
$this->assertStringNotContainsString( "<svg", $out );
|
||||
$this->assertStringNotContainsString( "mwe-math-mathml-a11y", $out );
|
||||
$this->assertStringContainsString( "mwe-math-mathml-", $out );
|
||||
}
|
||||
|
||||
public function testEmpty() {
|
||||
// TODO: Once render returns status, we won't need TestingAccessWrapper anymore.
|
||||
$math = TestingAccessWrapper::newFromObject( new MathMathML( '' ) );
|
||||
|
|
|
@ -49,7 +49,7 @@ class ParserIntegrationTests extends MediaWikiIntegrationTestCase {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function getHtmlOutput() {
|
||||
public function getHtmlOutput( bool $svg = true ): string {
|
||||
return "<render>$this->mode:$this->tex</render>";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue