File: MathSource.php

package info (click to toggle)
mediawiki-math 2%3A3.0.0%2Bgit20160613-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,744 kB
  • ctags: 1,344
  • sloc: php: 3,465; ml: 2,334; xml: 144; makefile: 138; sql: 86; ruby: 28; perl: 8
file content (70 lines) | stat: -rw-r--r-- 1,733 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
 * MediaWiki math extension
 *
 * (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz and other MediaWiki contributors
 * GPLv2 license; info in main package.
 *
 * Contains everything related to <math> </math> parsing
 * @file
 */

/**
 * 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 {
	/**
	 * @param string $tex
	 * @param array $params
	 */
	function __construct( $tex = '', $params = [] ) {
		parent::__construct( $tex, $params );
		$this->setMode( 'source' );
	}

	/**
	 * Renders TeX by outputting it to the browser in a span tag
	 *
	 * @return string span tag with TeX
	 */
	function getHtmlOutput() {
		# 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' ) {
			$class = 'mwe-math-fallback-source-display';
		} else {
			$class = 'mwe-math-fallback-source-inline';
		}
		return Xml::element( 'span',
			$this->getAttributes(
				'span',
				[
					// the former class name was 'tex'
					// for backwards compatibility we keep this classname
					'class' => $class. ' tex',
					'dir' => 'ltr'
				]
			),
			'$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
		);
	}

	protected function getMathTableName() {
		throw new Exception( 'in math source mode no database caching should happen' );
	}

	/**
	 * No rendering required in plain text mode
	 * @return boolean
	 */
	function render() {
		// assume unchanged to avoid unnecessary database access
		$this->changed = false;
		return true;
	}
}