summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-12-01 20:40:25 +0100
committerDaniel Baumann <daniel@debian.org>2024-12-12 11:06:58 +0100
commit2de5419316750f93cc9c84ba94141deb58c31ed6 (patch)
treec722ca719d6a86bc4ae913fdc2bf02c5505175dd
parentAdding mathjax makefile. (diff)
downloaddokuwiki-plugins-extra-2de5419316750f93cc9c84ba94141deb58c31ed6.tar.xz
dokuwiki-plugins-extra-2de5419316750f93cc9c84ba94141deb58c31ed6.zip
Adding mathjax version 20211120 (fccaddf).
Signed-off-by: Daniel Baumann <daniel@debian.org>
-rw-r--r--plugins/55/mathjax/README28
-rw-r--r--plugins/55/mathjax/action/enable.php68
-rw-r--r--plugins/55/mathjax/conf/default.php19
-rw-r--r--plugins/55/mathjax/conf/metadata.php13
-rw-r--r--plugins/55/mathjax/lang/en/settings.php8
-rw-r--r--plugins/55/mathjax/lang/zh/settings.php6
-rw-r--r--plugins/55/mathjax/plugin.info.txt7
-rw-r--r--plugins/55/mathjax/syntax/protecttex.php161
8 files changed, 310 insertions, 0 deletions
diff --git a/plugins/55/mathjax/README b/plugins/55/mathjax/README
new file mode 100644
index 0000000..29f57ba
--- /dev/null
+++ b/plugins/55/mathjax/README
@@ -0,0 +1,28 @@
+MathJax Plugin for DokuWiki
+
+Enables MathJax parsing of TeX math expressions in wiki pages
+(See https://www.mathjax.org/)
+
+All documentation for this plugin can be found at
+https://www.dokuwiki.org/plugin:mathjax
+
+If you install this plugin manually, make sure it is installed in
+lib/plugins/mathjax/ - if the folder is named differently, it
+will not work!
+
+Please refer to https://www.dokuwiki.org/plugins for additional info
+on how to install plugins in DokuWiki.
+
+----
+Copyright (C) Mark Liffiton <liffiton@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; version 2 of the License
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+See the COPYING file in your DokuWiki folder for details
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:
diff --git a/plugins/55/mathjax/conf/default.php b/plugins/55/mathjax/conf/default.php
new file mode 100644
index 0000000..e56bbdf
--- /dev/null
+++ b/plugins/55/mathjax/conf/default.php
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Default settings for the mathjax plugin
+ *
+ * @author Mark Liffiton <liffiton@gmail.com>
+ */
+
+$conf['url'] = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS_CHTML.js';
+$conf['config'] = 'MathJax.Hub.Config({
+ tex2jax: {
+ inlineMath: [ ["$","$"], ["\\\\(","\\\\)"] ],
+ displayMath: [ ["$$","$$"], ["\\\\[","\\\\]"] ],
+ processEscapes: true
+ }
+});';
+$conf['configfile'] = '';
+$conf['asciimath'] = 0;
+$conf['mathtags'] = '';
+
diff --git a/plugins/55/mathjax/conf/metadata.php b/plugins/55/mathjax/conf/metadata.php
new file mode 100644
index 0000000..13a08a3
--- /dev/null
+++ b/plugins/55/mathjax/conf/metadata.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * Options for the mathjax plugin
+ *
+ * @author Mark Liffiton <liffiton@gmail.com>
+ */
+
+$meta['url'] = array('string');
+$meta['config'] = array('');
+$meta['configfile'] = array('string');
+$meta['asciimath'] = array('onoff');
+$meta['mathtags'] = array('string');
+
diff --git a/plugins/55/mathjax/lang/en/settings.php b/plugins/55/mathjax/lang/en/settings.php
new file mode 100644
index 0000000..fabb0c1
--- /dev/null
+++ b/plugins/55/mathjax/lang/en/settings.php
@@ -0,0 +1,8 @@
+<?php
+
+$lang['url'] = 'The URL from which MathJax will be loaded.';
+$lang['config'] = '(Optional) MathJax configuration; javascript code executed when MathJax loads. See https://docs.mathjax.org/en/latest/options/';
+$lang['configfile'] = '(Optional) One or more files containing MathJax configuration commands. Specify paths relative to the dokuwiki installation directory (e.g. conf/mathjax.js or data/pages/mathjaxconf.txt), and separate multiple files with semicolons.';
+$lang['asciimath'] = 'Turn this on if you use AsciiMath. This will ensure that `-delimited strings are left alone for MathJax to parse. (Incompatible with Markdown plugins.)';
+$lang['mathtags'] = '(Optional) HTML tags to treat as math for MathJax to parse. Specify each as the tag name without angle brackets, and separate multiple tags with commas. If using this option, the tags (with angle brackets) must be added to the MathJax configuration. E.g. "mytag, othertag" here would need something like the following in the MathJax configuration: inlineMath: [ ["&lt;mytag>", "&lt;/mytag>"], ["&lt;othertag>", "&lt;/othertag>"] ]';
+
diff --git a/plugins/55/mathjax/lang/zh/settings.php b/plugins/55/mathjax/lang/zh/settings.php
new file mode 100644
index 0000000..1bfc619
--- /dev/null
+++ b/plugins/55/mathjax/lang/zh/settings.php
@@ -0,0 +1,6 @@
+<?php
+
+$lang['url'] = '载入 MathJax 的网址。';
+$lang['config'] = '(可选的) MathJax 配置; MathJax 载入时执行的 javascript 代码。参见 http://docs.mathjax.org/en/latest/options/';
+$lang['configfile'] = '(可选的) 一个或多个包含 MathJax 配置命令的文件。指定相对于 dokuwiki 安装目录的路径(例如 conf/mathjax.js 或者 data/pages/mathjaxconf.txt),并用分号分隔多个文件。';
+
diff --git a/plugins/55/mathjax/plugin.info.txt b/plugins/55/mathjax/plugin.info.txt
new file mode 100644
index 0000000..4d0521d
--- /dev/null
+++ b/plugins/55/mathjax/plugin.info.txt
@@ -0,0 +1,7 @@
+base mathjax
+author Mark Liffiton
+email liffiton@gmail.com
+date 2021-11-20
+name MathJax plugin
+desc Enables MathJax (https://www.mathjax.org/) parsing of TeX math expressions in wiki pages
+url https://www.dokuwiki.org/plugin:mathjax
diff --git a/plugins/55/mathjax/syntax/protecttex.php b/plugins/55/mathjax/syntax/protecttex.php
new file mode 100644
index 0000000..7d1714c
--- /dev/null
+++ b/plugins/55/mathjax/syntax/protecttex.php
@@ -0,0 +1,161 @@
+<?php
+/**
+ * DokuWiki Plugin mathjax (Syntax 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();
+
+/**
+ * Class syntax_plugin_mathjax_protecttex
+ */
+class syntax_plugin_mathjax_protecttex extends DokuWiki_Syntax_Plugin {
+ # We need to grab any math before dokuwiki tries to parse it.
+ # Once it's 'claimed' by this plugin (type: protected), it won't be altered.
+
+ # Set of environments that this plugin will protect from Dokuwiki parsing
+ # * is escaped to work in regexp below
+ # Note: "math", "displaymath", and "flalign" environments seem to not be
+ # recognized by Mathjax... They will still be protected from Dokuwiki,
+ # but they will not be rendered by MathJax.
+ private static $ENVIRONMENTS = array(
+ "math",
+ "displaymath",
+ "equation",
+ "equation\*",
+ "eqnarray",
+ "eqnarray\*",
+ "align",
+ "align\*",
+ "flalign",
+ "flalign\*",
+ "alignat",
+ "alignat\*",
+ "multline",
+ "multline\*",
+ "gather",
+ "gather\*",
+ );
+
+ /**
+ * Syntax Type
+ *
+ * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
+ *
+ * @return string
+ */
+ public function getType() {
+ return 'protected';
+ }
+
+ /**
+ * Sort for applying this mode
+ *
+ * @return int
+ */
+ public function getSort() {
+ return 65;
+ }
+
+ /**
+ * regexp patterns adapted from jsMath plugin: https://www.dokuwiki.org/plugin:jsmath
+ *
+ * @param string $mode
+ */
+ public function connectTo($mode) {
+ $this->Lexer->addEntryPattern('(?<!\\\\)\$(?=[^\$][^\r\n]*?\$)',$mode,'plugin_mathjax_protecttex');
+ $this->Lexer->addEntryPattern('\$\$(?=.*?\$\$)',$mode,'plugin_mathjax_protecttex');
+ $this->Lexer->addEntryPattern('\\\\\((?=.*?\\\\\))',$mode,'plugin_mathjax_protecttex');
+ $this->Lexer->addEntryPattern('\\\\\[(?=.*?\\\\])',$mode,'plugin_mathjax_protecttex');
+ foreach (self::$ENVIRONMENTS as $env) {
+ $this->Lexer->addEntryPattern('\\\\begin{' . $env . '}(?=.*?\\\\end{' . $env . '})',$mode,'plugin_mathjax_protecttex');
+ }
+
+ if ($this->getConf('asciimath')) {
+ // Protect the default AsciiMath delimiter
+ $this->Lexer->addEntryPattern('`(?=.*?`)',$mode,'plugin_mathjax_protecttex');
+ }
+
+ // Protect specified tags, if any
+ $conf_mathtags = $this->getConf('mathtags');
+ $mathtags = explode(',', $conf_mathtags);
+ foreach ($mathtags as $tag) {
+ $tag = trim($tag);
+ if ($tag == "") { continue; }
+ $this->Lexer->addEntryPattern('<' . $tag . '.*?>(?=.*?</' . $tag . '>)',$mode,'plugin_mathjax_protecttex');
+ }
+ }
+ public function postConnect() {
+ $this->Lexer->addExitPattern('\$(?!\$)','plugin_mathjax_protecttex');
+ $this->Lexer->addExitPattern('\\\\\)','plugin_mathjax_protecttex');
+ $this->Lexer->addExitPattern('\\\\\]','plugin_mathjax_protecttex');
+ foreach (self::$ENVIRONMENTS as $env) {
+ $this->Lexer->addExitPattern('\\\\end{' . $env . '}','plugin_mathjax_protecttex');
+ }
+
+ if ($this->getConf('asciimath')) {
+ // Protect the default AsciiMath delimiter
+ $this->Lexer->addExitPattern('`','plugin_mathjax_protecttex');
+ }
+
+ // Protect specified tags, if any
+ $conf_mathtags = $this->getConf('mathtags');
+ $mathtags = explode(',', $conf_mathtags);
+ foreach ($mathtags as $tag) {
+ $tag = trim($tag);
+ if ($tag == "") { continue; }
+ $this->Lexer->addExitPattern('</' . $tag . '>','plugin_mathjax_protecttex');
+ }
+ }
+
+ /**
+ * Handler to prepare matched data for the rendering process
+ *
+ * This function can only pass data to render() via its return value - render()
+ * may be not be run during the object's current life.
+ *
+ * Usually you should only need the $match param.
+ *
+ * @param string $match The text matched by the patterns
+ * @param int $state The lexer state for the match
+ * @param int $pos The character position of the matched text
+ * @param Doku_Handler $handler The Doku_Handler object
+ * @return array Return an array with all data you want to use in render
+ */
+ public function handle($match, $state, $pos, Doku_Handler $handler){
+ // Just pass it through...
+ return $match;
+ }
+
+ /**
+ * Handles the actual output creation.
+ *
+ * @param $mode string output format being rendered
+ * @param $renderer Doku_Renderer the current renderer object
+ * @param $data array data created by handler()
+ * @return boolean rendered correctly?
+ */
+ public function render($mode, Doku_Renderer $renderer, $data) {
+ if ($mode == 'xhtml' || $mode == 'odt') {
+ /** @var Doku_Renderer_xhtml $renderer */
+
+ // Just pass it through, but escape xml entities...
+ $renderer->doc .= $renderer->_xmlEntities($data);
+ return true;
+ }
+ if ($mode == 'latexport') {
+ // Pass math expressions to latexport renderer
+ $renderer->mathjax_content($data);
+ return true;
+ }
+
+ // For all other modes, pass through unchanged.
+ $renderer->doc .= $data;
+ return true;
+ }
+}
+
+// vim:ts=4:sw=4:et: