Skip to content

Commit

Permalink
Replace local library by CDN library
Browse files Browse the repository at this point in the history
This was necessary since the library is loading other resources. As the loading
process in the extension is not designed for that, it was necessary to use the
library from a CDN.
  • Loading branch information
aledeg committed Mar 30, 2024
1 parent f0472a9 commit c3e8a59
Show file tree
Hide file tree
Showing 86 changed files with 11 additions and 2,596 deletions.
15 changes: 10 additions & 5 deletions extension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?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'));
Expand All @@ -9,22 +15,21 @@ public function init() {
private function loadMathjax() {
$config = 'mathjax-config.js';
Minz_View::appendScript($this->getFileUrl($config, 'js'));
$lib = 'mathjax/tex-chtml.js';
Minz_View::appendScript($this->getFileUrl($lib, 'js'));
Minz_View::appendScript(self::MATHJAX_URL);
}

public function sanitize($entry) {
$content = str_replace(array(
$content = str_replace([
'\\left⌊',
'\\right⌋',
'\\Complex',
'\\Reals'
), array(
], [
'\\left\\lfloor',
'\\right\\rfloor',
'\mathbb{C}',
'\mathbb{R}',
), $entry->content());
], $entry->content());

$entry->_content($content);

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "LaTeX support",
"author": "Alexis Degrugillier",
"description": "Add support for LaTeX notation rendering",
"version": "0.1.4",
"version": "0.1.5",
"entrypoint": "LatexSupport",
"type": "user"
}
1 change: 0 additions & 1 deletion static/mathjax-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// https://github.com/mathjax/MathJax/releases/tag/3.0.5
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
Expand Down
1 change: 0 additions & 1 deletion static/mathjax/a11y/assistive-mml.js

This file was deleted.

1 change: 0 additions & 1 deletion static/mathjax/a11y/complexity.js

This file was deleted.

1 change: 0 additions & 1 deletion static/mathjax/a11y/explorer.js

This file was deleted.

1 change: 0 additions & 1 deletion static/mathjax/a11y/semantic-enrich.js

This file was deleted.

1 change: 0 additions & 1 deletion static/mathjax/adaptors/liteDOM.js

This file was deleted.

1 change: 0 additions & 1 deletion static/mathjax/core.js

This file was deleted.

1 change: 0 additions & 1 deletion static/mathjax/input/asciimath.js

This file was deleted.

Loading

0 comments on commit c3e8a59

Please sign in to comment.