-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMathHooks.php
47 lines (30 loc) · 1.38 KB
/
DMathHooks.php
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
<?php
if (!defined('MEDIAWIKI')){
die();
}
class DMathParse {
static function onParserFirstCallSetup(Parser $parser) {
if(!ExtensionRegistry::getInstance()->isLoaded('Math')) {
die("The DMath extension requires the Math extension, please include it.");
}
$parser->setHook('dmath', 'DMathParse::dmathTagHook' );
$parser->setHook('math', 'DMathParse::mathTagHook' );
}
function dmathTagHook( $content, $attributes, $parser ) {
$attributes['display'] = 'block';
if ( array_key_exists( 'type', $attributes ) ) {
$tag = $attributes['type'];
$content = ' \\begin{'.$tag.'} '.$content.'\\end{'.$tag.'}';
}
$text = MathHooks::mathTagHook( $content, $attributes, $parser );
$text[0] = Html::rawElement ('div', array( 'class' => 'math-wrapper' ), $text[0] );
return $text;
}
function mathTagHook( $content, $attributes, $parser ) {
$text = MathHooks::mathTagHook($content, $attributes, $parser);
// the MathHooks::mathTagHooks function returns a array with some attributes, but we only want to change the text, which is at [0].
$text[0] = Html::rawElement( 'span', array( 'class' => 'math-wrapper' ), $text[0] );
return $text;
}
}
?>