diff options
author | Daniel Baumann <daniel@debian.org> | 2024-12-01 21:17:14 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-01 22:11:34 +0100 |
commit | cca09e0d7e47b50638809b79c1cb4f17652f986a (patch) | |
tree | 465f90f043f2408e42593b28074678acf37c5771 /plugins/55/mathjax/action/enable.php | |
parent | Initial commit. (diff) | |
download | dokuwiki-plugins-extra-cca09e0d7e47b50638809b79c1cb4f17652f986a.tar.xz dokuwiki-plugins-extra-cca09e0d7e47b50638809b79c1cb4f17652f986a.zip |
Adding upstream version 20241201.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'plugins/55/mathjax/action/enable.php')
-rw-r--r-- | plugins/55/mathjax/action/enable.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/plugins/55/mathjax/action/enable.php b/plugins/55/mathjax/action/enable.php new file mode 100644 index 0000000..5063a5f --- /dev/null +++ b/plugins/55/mathjax/action/enable.php @@ -0,0 +1,68 @@ +<?php +/** + * DokuWiki Plugin mathjax (Action Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Mark Liffiton <liffiton@gmail.com> + */ + +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); + +/** + * Add scripts via an event handler + */ +class action_plugin_mathjax_enable extends DokuWiki_Action_Plugin { + + /** + * Registers our handler for the TPL_METAHEADER_OUTPUT event + */ + public function register(Doku_Event_Handler $controller) { + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output'); + } + + /** + * Add <script> blocks to the headers: + * - One to load MathJax and one to configure it + * - Also add one block per configfile, if any are specified + * See https://docs.mathjax.org/en/latest/configuration.html#using-in-line-configuration-options + * + * @param Doku_Event $event + * @param $param + */ + public function handle_tpl_metaheader_output(Doku_Event &$event, $param) { + // Create main config block + $event->data['script'][] = array( + 'type' => 'text/x-mathjax-config', + '_data' => $this->getConf('config'), + ); + + // Include config files, if any specified + $configfiles = $this->getConf('configfile'); + $files = explode(';', $configfiles); + foreach ($files as $f) { + $f = trim($f); + if ($f == "" or !is_readable($f)) { + continue; + } + $contents = file_get_contents(DOKU_INC . $f); + if ($contents) { + $event->data['script'][] = array( + 'type' => 'text/x-mathjax-config', + '_data' => "\n// " . $f . "\n" . $contents, + ); + } + } + + // Load MathJax itself + $event->data['script'][] = array( + 'type' => 'text/javascript', + 'charset' => 'utf-8', + 'src' => $this->getConf('url'), + '_data' => '', + ); + } + +} + +// vim:ts=4:sw=4:et: |