2012-10-27 14:30:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* MediaWiki math extension
|
|
|
|
*
|
2018-04-13 14:18:16 +00:00
|
|
|
* @copyright 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz and other MediaWiki
|
|
|
|
* contributors
|
|
|
|
* @license GPL-2.0-or-later
|
2012-10-27 14:30:50 +00:00
|
|
|
*
|
|
|
|
* Contains everything related to <math> </math> parsing
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
2021-04-07 22:22:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use Html;
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Takes LaTeX fragments and outputs the source directly to the browser
|
|
|
|
*
|
|
|
|
* @author Tomasz Wegrzanowski
|
|
|
|
* @author Brion Vibber
|
|
|
|
* @author Moritz Schubotz
|
|
|
|
* @ingroup Parser
|
|
|
|
*/
|
|
|
|
class MathSource extends MathRenderer {
|
2014-10-11 14:04:18 +00:00
|
|
|
/**
|
|
|
|
* @param string $tex
|
|
|
|
* @param array $params
|
|
|
|
*/
|
2018-11-02 17:52:06 +00:00
|
|
|
public function __construct( $tex = '', $params = [] ) {
|
2014-10-11 14:04:18 +00:00
|
|
|
parent::__construct( $tex, $params );
|
2021-08-11 18:15:35 +00:00
|
|
|
$this->setMode( MathConfig::MODE_SOURCE );
|
2014-10-11 14:04:18 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Renders TeX by outputting it to the browser in a span tag
|
|
|
|
*
|
|
|
|
* @return string span tag with TeX
|
|
|
|
*/
|
2018-11-02 17:52:06 +00:00
|
|
|
public function getHtmlOutput() {
|
2012-10-27 14:30:50 +00:00
|
|
|
# No need to render or parse anything more!
|
|
|
|
# New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
|
2015-07-22 22:10:46 +00:00
|
|
|
if ( $this->getMathStyle() == 'display' ) {
|
2014-03-17 06:14:02 +00:00
|
|
|
$class = 'mwe-math-fallback-source-display';
|
|
|
|
} else {
|
|
|
|
$class = 'mwe-math-fallback-source-inline';
|
|
|
|
}
|
2018-04-23 13:34:35 +00:00
|
|
|
return Html::element( 'span',
|
2012-10-27 14:30:50 +00:00
|
|
|
$this->getAttributes(
|
|
|
|
'span',
|
2016-04-12 20:53:25 +00:00
|
|
|
[
|
2014-03-17 06:14:02 +00:00
|
|
|
// the former class name was 'tex'
|
|
|
|
// for backwards compatibility we keep this classname
|
2018-09-05 22:34:15 +00:00
|
|
|
'class' => $class . ' tex',
|
2012-10-27 14:30:50 +00:00
|
|
|
'dir' => 'ltr'
|
2016-04-12 20:53:25 +00:00
|
|
|
]
|
2012-10-27 14:30:50 +00:00
|
|
|
),
|
2013-04-25 17:07:25 +00:00
|
|
|
'$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
|
2012-10-27 14:30:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:22:49 +00:00
|
|
|
/**
|
|
|
|
* @throws Exception always
|
2021-09-08 19:45:48 +00:00
|
|
|
* @return never
|
2021-02-18 13:22:49 +00:00
|
|
|
*/
|
2014-05-27 04:46:53 +00:00
|
|
|
protected function getMathTableName() {
|
2015-09-21 16:14:01 +00:00
|
|
|
throw new Exception( 'in math source mode no database caching should happen' );
|
2014-05-27 04:46:53 +00:00
|
|
|
}
|
2014-06-05 21:06:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* No rendering required in plain text mode
|
2017-07-26 20:43:39 +00:00
|
|
|
* @return bool
|
2014-06-05 21:06:43 +00:00
|
|
|
*/
|
2018-11-02 17:52:06 +00:00
|
|
|
public function render() {
|
2014-06-05 21:06:43 +00:00
|
|
|
// assume unchanged to avoid unnecessary database access
|
|
|
|
$this->changed = false;
|
|
|
|
return true;
|
2014-06-05 21:06:43 +00:00
|
|
|
}
|
2012-10-27 14:30:50 +00:00
|
|
|
}
|