Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
16 / 18
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
MathSource
88.89% covered (warning)
88.89%
16 / 18
50.00% covered (danger)
50.00%
2 / 4
5.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHtmlOutput
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
2.00
 getMathTableName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 render
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
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
13namespace MediaWiki\Extension\Math;
14
15use LogicException;
16use 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 */
26class 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     * @return string span tag with TeX
40     */
41    public function getHtmlOutput() {
42        # No need to render or parse anything more!
43        # New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
44        if ( $this->getMathStyle() == 'display' ) {
45            $class = 'mwe-math-fallback-source-display';
46        } else {
47            $class = 'mwe-math-fallback-source-inline';
48        }
49        return Html::element( 'span',
50            $this->getAttributes(
51                'span',
52                [
53                    // the former class name was 'tex'
54                    // for backwards compatibility we keep this classname T348938
55                    'class' => $class . ' tex',
56                    'dir' => 'ltr'
57                ]
58            ),
59            '$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
60        );
61    }
62
63    /**
64     * @throws LogicException always
65     * @return never
66     */
67    protected function getMathTableName() {
68        throw new LogicException( 'in math source mode no database caching should happen' );
69    }
70
71    /**
72     * No rendering required in plain text mode
73     * @return bool
74     */
75    public function render() {
76        // assume unchanged to avoid unnecessary database access
77        $this->changed = false;
78        return true;
79    }
80}