MDL-43856 MathJax: Add a setting for additional delimiters to support e.g. ASCIIMATH
This commit is contained in:
@@ -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. "<tex.*> blah </tex>".
|
||||
@@ -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 '<span class="nolink"><span class="filter_mathjaxloader_equation">' . $text . '</span></span>';
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user