Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.89% |
16 / 18 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
MathSource | |
88.89% |
16 / 18 |
|
50.00% |
2 / 4 |
5.03 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getHtmlOutput | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
2.00 | |||
getMathTableName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
render | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * MediaWiki math extension |
4 | * |
5 | * @copyright 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz and other MediaWiki |
6 | * contributors |
7 | * @license GPL-2.0-or-later |
8 | * |
9 | * Contains everything related to <math> </math> parsing |
10 | * @file |
11 | */ |
12 | |
13 | namespace MediaWiki\Extension\Math; |
14 | |
15 | use LogicException; |
16 | use MediaWiki\Html\Html; |
17 | |
18 | /** |
19 | * Takes LaTeX fragments and outputs the source directly to the browser |
20 | * |
21 | * @author Tomasz Wegrzanowski |
22 | * @author Brion Vibber |
23 | * @author Moritz Schubotz |
24 | * @ingroup Parser |
25 | */ |
26 | class MathSource extends MathRenderer { |
27 | /** |
28 | * @param string $tex |
29 | * @param array $params |
30 | */ |
31 | public function __construct( $tex = '', $params = [] ) { |
32 | parent::__construct( $tex, $params ); |
33 | $this->setMode( MathConfig::MODE_SOURCE ); |
34 | } |
35 | |
36 | /** |
37 | * Renders TeX by outputting it to the browser in a span tag |
38 | * |
39 | * @param bool $svg |
40 | * @return string span tag with TeX |
41 | */ |
42 | public function getHtmlOutput( bool $svg = true ): string { |
43 | # No need to render or parse anything more! |
44 | # New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818) |
45 | if ( $this->getMathStyle() == 'display' ) { |
46 | $class = 'mwe-math-fallback-source-display'; |
47 | } else { |
48 | $class = 'mwe-math-fallback-source-inline'; |
49 | } |
50 | return Html::element( 'span', |
51 | $this->getAttributes( |
52 | 'span', |
53 | [ |
54 | // the former class name was 'tex' |
55 | // for backwards compatibility we keep this classname T348938 |
56 | 'class' => $class . ' tex', |
57 | 'dir' => 'ltr' |
58 | ] |
59 | ), |
60 | '$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $' |
61 | ); |
62 | } |
63 | |
64 | /** |
65 | * @throws LogicException always |
66 | * @return never |
67 | */ |
68 | protected function getMathTableName() { |
69 | throw new LogicException( 'in math source mode no database caching should happen' ); |
70 | } |
71 | |
72 | /** |
73 | * No rendering required in plain text mode |
74 | * @return bool |
75 | */ |
76 | public function render() { |
77 | // assume unchanged to avoid unnecessary database access |
78 | $this->changed = false; |
79 | return true; |
80 | } |
81 | } |