From 894e20395d3a91d8a015c7f631c6d27e765dd315 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 4 Apr 2014 11:18:54 +0800 Subject: [PATCH] MDL-43856 MathJax: Add a setting for additional delimiters to support e.g. ASCIIMATH --- filter/mathjaxloader/filter.php | 11 ++++++++++- .../mathjaxloader/lang/en/filter_mathjaxloader.php | 12 ++++++------ filter/mathjaxloader/settings.php | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/filter/mathjaxloader/filter.php b/filter/mathjaxloader/filter.php index 6c1be05ca28..ba13211d5fe 100644 --- a/filter/mathjaxloader/filter.php +++ b/filter/mathjaxloader/filter.php @@ -133,6 +133,7 @@ class filter_mathjaxloader extends moodle_text_filter { */ public function filter($text, array $options = array()) { $legacy = get_config('filter_mathjaxloader', 'texfiltercompatibility'); + $extradelimiters = explode(',', get_config('filter_mathjaxloader', 'additionaldelimiters')); if ($legacy) { // This replaces any of the tex filter maths delimiters with the default for inline maths in MathJAX "\( blah \)". // E.g. " blah ". @@ -151,7 +152,15 @@ class filter_mathjaxloader extends moodle_text_filter { $hasdisplay = (strpos($text, '$$') !== false) || (strpos($text, '\\[') !== false && strpos($text, '\\]') !== false); - if ($hasinline || $hasdisplay) { + $hasextra = false; + + foreach ($extradelimiters as $extra) { + if ($extra && strpos($text, $extra) !== false) { + $hasextra = true; + break; + } + } + if ($hasinline || $hasdisplay || $hasextra) { // Only call init if there is at least one equation on the page. $this->lazy_init(); return '' . $text . ''; diff --git a/filter/mathjaxloader/lang/en/filter_mathjaxloader.php b/filter/mathjaxloader/lang/en/filter_mathjaxloader.php index c19a4bffd1e..8ba35837d25 100644 --- a/filter/mathjaxloader/lang/en/filter_mathjaxloader.php +++ b/filter/mathjaxloader/lang/en/filter_mathjaxloader.php @@ -15,18 +15,18 @@ // along with Moodle. If not, see . /** - * Strings for component 'filter_mathjax', language 'en'. + * Strings for component 'filter_mathjaxloader', language 'en'. * - * Note: use filter/mathjax/cli/update_lang_files.php script to import strings from upstream JS lang files. - * - * @package filter_mathjax + * @package filter_mathjaxloader * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -//== Custom Moodle strings that are not part of upstream MathJax == $string['filtername'] = 'MathJax'; +$string['additionaldelimiters'] = 'Additional equation delimiters'; +$string['additionaldelimiters_help'] = 'MathJax filter parses text for equations contained within delimiter characters. + +The list of recognised delimiter characters can be added to here (e.g. AsciiMath uses `). Delimiters can contain multiple characters and multiple delimiters can be separated with commas.'; $string['httpurl'] = 'HTTP MathJax URL'; $string['httpurl_help'] = 'Full URL to MathJax library. Used when the page is loaded via http.'; $string['httpsurl'] = 'HTTPS MathJax URL'; diff --git a/filter/mathjaxloader/settings.php b/filter/mathjaxloader/settings.php index 6656d9c15b3..deeb9751e1f 100644 --- a/filter/mathjaxloader/settings.php +++ b/filter/mathjaxloader/settings.php @@ -76,4 +76,11 @@ MathJax.Hub.Config({ $settings->add($item); + $item = new admin_setting_configtext('filter_mathjaxloader/additionaldelimiters', + new lang_string('additionaldelimiters', 'filter_mathjaxloader'), + new lang_string('additionaldelimiters_help', 'filter_mathjaxloader'), + '', + PARAM_RAW); + $settings->add($item); + }