MDL-65394 filter: only do mathjax parsing on strings that need it

This commit is contained in:
Ryan Wyllie
2019-05-01 16:27:34 +08:00
parent 76fbbf7e7e
commit ebe3110dff
+7 -1
View File
@@ -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 = '<span class="nolink">' . $text . '</span>';
} 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