-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.php
38 lines (31 loc) · 998 Bytes
/
extension.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
<?php
class LatexSupportExtension extends Minz_Extension {
private const MATHJAX_URL = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
protected array $csp_policies = [
'default-src' => 'https://cdn.jsdelivr.net',
];
public function init() {
$this->loadMathjax();
$this->registerHook('entry_before_display', array($this, 'sanitize'));
}
private function loadMathjax() {
$config = 'mathjax-config.js';
Minz_View::appendScript($this->getFileUrl($config, 'js'));
Minz_View::appendScript(self::MATHJAX_URL);
}
public function sanitize($entry) {
$content = str_replace([
'\\left⌊',
'\\right⌋',
'\\Complex',
'\\Reals'
], [
'\\left\\lfloor',
'\\right\\rfloor',
'\mathbb{C}',
'\mathbb{R}',
], $entry->content());
$entry->_content($content);
return $entry;
}
}