From ebe3110dff7c0db96d7e654f267b8de96f240dc7 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 15 Apr 2019 13:02:41 +0800 Subject: [PATCH] MDL-65394 filter: only do mathjax parsing on strings that need it --- filter/mathjaxloader/filter.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/filter/mathjaxloader/filter.php b/filter/mathjaxloader/filter.php index 0906e18fb49..9fab93b9e79 100644 --- a/filter/mathjaxloader/filter.php +++ b/filter/mathjaxloader/filter.php @@ -140,7 +140,13 @@ class filter_mathjaxloader extends moodle_text_filter { if ($hasextra) { // If custom dilimeters are used, wrap whole text to prevent autolinking. $text = '' . $text . ''; - } else { + } else if (preg_match('/\\\\[[(]/', $text) || preg_match('/\$\$/', $text)) { + // Only parse the text if there are mathjax symbols in it. The recognized + // math environments are \[ \] and $$ $$ for display mathematics and \( \) + // for inline mathematics. + // Note: 2 separate regexes seems to perform better here than using a single + // regex with groupings. + // Wrap display and inline math environments in nolink spans. // Do not wrap nested environments, i.e., if inline math is nested // inside display math, only the outer display math is wrapped in