From a55291e2b354642ca9749f4f2dd68c344a5b21e2 Mon Sep 17 00:00:00 2001 From: Elke Kreim <elke.kreim@hs-hannover.de> Date: Fri, 31 May 2024 13:56:34 +0200 Subject: [PATCH] Fix remote url for MathJax Use local MathJax configured in filter_mathjaxloader --- vle_specific.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/vle_specific.php b/vle_specific.php index 24953878d..516a56f25 100644 --- a/vle_specific.php +++ b/vle_specific.php @@ -189,8 +189,27 @@ function stack_cors_link(string $filename): string { * Gets the URL used for MathJax, might be VLE local. */ function stack_get_mathjax_url(): string { - // TODO: figure out how to support VLE local with CORS. - return 'https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML'; + // HSH patch - 2024.05.31: Elke Kreim - elke.kreim@hs-hannover.de + // include fix https://github.com/maths/moodle-qtype_stack/pull/1194/files + // to use local installation of MathHax configured in plugin filter_mathjaxloader + $mathjaxconfigurl = get_config('filter_mathjaxloader', 'httpsurl'); + if ($mathjaxconfigurl) { + $questionpos = strpos($mathjaxconfigurl, '?'); + if ($questionpos !== false) { + $querystring = substr($mathjaxconfigurl, $questionpos + 1); + $urlstring = substr($mathjaxconfigurl, 0, $questionpos); + parse_str($querystring, $queryparams); + $queryparams = array_merge(['config' => 'TeX-AMS-MML_HTMLorMML'], $queryparams); + $querystring = http_build_query($queryparams, null, '&', PHP_QUERY_RFC3986); + $url = $urlstring . '?' . $querystring; + } else { + $url = $mathjaxconfigurl . '?config=TeX-AMS-MML_HTMLorMML'; + } + + return $url; + } else { + return 'https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML'; + } } /* -- GitLab