Merge branch 'MDL-55007-master' of https://github.com/dthies/moodle
authorDan Poltawski <dan@moodle.com>
Tue, 12 Jul 2016 08:20:15 +0000 (09:20 +0100)
committerDan Poltawski <dan@moodle.com>
Tue, 12 Jul 2016 08:20:15 +0000 (09:20 +0100)
filter/mathjaxloader/filter.php
lib/tests/externallib_test.php

index 3726c95..c5428c8 100644 (file)
@@ -163,7 +163,22 @@ class filter_mathjaxloader extends moodle_text_filter {
         }
         if ($hasinline || $hasdisplay || $hasextra) {
             $PAGE->requires->yui_module('moodle-filter_mathjaxloader-loader', 'M.filter_mathjaxloader.typeset');
-            return '<span class="nolink"><span class="filter_mathjaxloader_equation">' . $text . '</span></span>';
+            if ($hasextra) {
+                // If custom dilimeters are used, wrap whole text to prevent autolinking.
+                $text = '<span class="nolink">' + $text + '</span>';
+            } else {
+                if ($hasinline) {
+                    // If the default inline TeX delimiters \( \) are present, wrap each pair in nolink.
+                    $text = preg_replace('/\\\\\\([\S\s]*?\\\\\\)/u',
+                        '<span class="nolink">\0</span>', $text);
+                }
+                if ($hasdisplay) {
+                    // If default display TeX is used, wrap $$ $$ or \[ \] individually.
+                    $text = preg_replace('/\$\$[\S\s]*?\$\$|\\\\\\[[\S\s]*?\\\\\\]/u',
+                        '<span class="nolink">\0</span>', $text);
+                }
+            }
+            return '<span class="filter_mathjaxloader_equation">' . $text . '</span>';
         }
         return $text;
     }
index cda9bd3..01c6a47 100644 (file)
@@ -105,8 +105,8 @@ class core_externallib_testcase extends advanced_testcase {
 
         $test = '$$ \pi $$';
         $testformat = FORMAT_MARKDOWN;
-        $correct = array('<span class="nolink"><span class="filter_mathjaxloader_equation"><p>$$ \pi $$</p>
-</span></span>', FORMAT_HTML);
+        $correct = array('<span class="filter_mathjaxloader_equation"><p><span class="nolink">$$ \pi $$</span></p>
+</span>', FORMAT_HTML);
         $this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0), $correct);
 
         // Filters can be opted out from by the developer.