MDL-43856 MathJax: Improvements to the MathJax filter

* Remove all traces of mathjax from the atto equation editor - it is filter agnostic
* Add a M.core.event module for core events that can be published/subscribed to by plugins (loose coupling)
* Add a FILTER_CONTENT_UPDATED event so plugins can tell the filter system when nodes are added to the page
* Implement a listener for this event in the MathJax filter
* Fire this event from the equation editor and from the glossary filter
* Add a nolink tag to the mathjax filter, so equations will not be processed by the other filters
* Add a smarter throttle function to the equation editor preview updates (Y.throttle is dumb)
This commit is contained in:
Damyon Wiese
2014-04-03 14:36:36 +08:00
parent 289ed254a7
commit cc90cedc85
26 changed files with 656 additions and 240 deletions
+20 -5
View File
@@ -132,14 +132,29 @@ class filter_mathjaxloader extends moodle_text_filter {
* @param array $options The filter options.
*/
public function filter($text, array $options = array()) {
// This replaces <tex> blah </tex> syntax with [tex] blah [/tex] syntax
// because MathJax cannot handle html tags as delimiters.
$legacy = get_config('filter_mathjaxloader', 'texfiltercompatibility');
if ($legacy) {
// This replaces any of the tex filter maths delimiters with the default for inline maths in MathJAX "\( blah \)".
// <tex.*> blah </tex>
$text = preg_replace('|<(/?) *tex( [^>]*)?>|u', '[\1tex]', $text);
// [tex.*] blah [/tex]
$text = str_replace('[tex]', '\\(', $text);
$text = str_replace('[/tex]', '\\)', $text);
// $$ blah $$
$text = preg_replace('|\$\$[\S\s]\$\$|u', '\\(\1\\)', $text);
// \[ blah \]
$text = str_replace('\\[', '\\(', $text);
$text = str_replace('\\]', '\\)', $text);
}
$text = preg_replace('|<(/?) *tex( [^>]*)?>|u', '[\1tex]', $text);
if (strpos($text, '$$') !== false || strpos($text, '\\[') !== false || strpos($text, '[tex]') !== false) {
$hasinline = strpos($text, '\\(') !== false && strpos($text, '\\)') !== false;
$hasdisplay = (strpos($text, '$$') !== false) ||
(strpos($text, '\\[') !== false && strpos($text, '\\]') !== false);
if ($hasinline || $hasdisplay) {
// Only call init if there is at least one equation on the page.
$this->lazy_init();
return '<span class="filter_mathjaxloader_equation">' . $text . '</span>';
return '<span class="nolink"><span class="filter_mathjaxloader_equation">' . $text . '</span></span>';
}
return $text;
}