* (bug 34828) Fix MathJax initializer to operate on images as well as text form
Warning: this piggybacks on 'alt' text and can be broken if a manual alt text was specified on a <math> bit. Needs to be more nativey. Also cleaned up the conditional setup code since we're already only called when a <math> is present.
This commit is contained in:
parent
296b767c62
commit
d84a00a9ed
|
@ -23,27 +23,23 @@ MathJax.Extension.wiki2jax = {
|
|||
this.previewClass = MathJax.Hub.config.preRemoveClass;
|
||||
this.configured = true;
|
||||
}
|
||||
var span, i;
|
||||
if ((!element || element == document.body) && mathJax.span) { // dirty hack
|
||||
span = mathJax.span;
|
||||
i = mathJax.spanIndex;
|
||||
}
|
||||
else {
|
||||
if (typeof(element) === "string") {element = document.getElementById(element)}
|
||||
if (!element) {element = this.config.element || document.body}
|
||||
span = element.getElementsByTagName("span");
|
||||
i = span.length-1;
|
||||
}
|
||||
for (; i >= 0; i--)
|
||||
if (span[i].className === "tex") this.ConvertMath(span[i])
|
||||
var that = this;
|
||||
$('span.tex, img.tex', element || document).each(function(i, span) {
|
||||
that.ConvertMath(span);
|
||||
});
|
||||
},
|
||||
|
||||
ConvertMath: function (node) {
|
||||
var parent = node.parentNode,
|
||||
mode = parent.tagName === "DD" && parent.firstChild === parent.lastChild ? "; mode=display" : "",
|
||||
tex;
|
||||
if (node.nodeName == 'IMG') {
|
||||
tex = node.alt;
|
||||
} else {
|
||||
tex = node.innerHTML.substring(node.innerHTML[0]=='$',node.innerHTML.length-(node.innerHTML[node.innerHTML.length-1]=='$'));
|
||||
tex = tex.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/ /g," ");
|
||||
}
|
||||
|
||||
tex = tex.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/ /g," ");
|
||||
tex = tex.replace(/\\iiint([^!]*)!\\!\\!\\!\\!.*\\subset\\!\\supset/g,"\\iiint$1mkern-2.5em\\subset\\!\\supset").replace(/\\iint([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\subset\\!\\supset/g,"\\iint$1mkern-1.65em$2\\subset\\!\\!\\supset").replace(/\\int\\!\\!\\!(\\!)+\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!.*\\bigcirc(\\,)*/g,"\\iiint$3mkern-2.5em\\subset\\!\\supset").replace(/\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\bigcirc(\\,)*/g,"\\iint$2mkern-1.65em$3\\subset\\!\\!\\supset");
|
||||
if (mode === "") {
|
||||
tex = tex.replace(/ *\\scriptstyle(\W)/g,"\\textstyle$1").replace(/ *\\scriptscriptstyle(\W)/g,"\\scriptstyle$1");
|
||||
|
|
|
@ -44,26 +44,18 @@ mathJax.Load = function(element) {
|
|||
if (this.loaded)
|
||||
return true;
|
||||
|
||||
var span = element.getElementsByTagName("span"), i;
|
||||
for (i = span.length-1; i >= 0; i--) {
|
||||
if (span[i].className === "tex") {
|
||||
// this.span = span;
|
||||
// this.spanIndex = i;
|
||||
// create configuration element
|
||||
var config = 'mathJax.Config();';
|
||||
var script = document.createElement( 'script' );
|
||||
script.setAttribute( 'type', 'text/x-mathjax-config' );
|
||||
if ( window.opera ) script.innerHTML = config; else script.text = config;
|
||||
document.getElementsByTagName('head')[0].appendChild( script );
|
||||
|
||||
// create configuration element
|
||||
var config = 'mathJax.Config();';
|
||||
var script = document.createElement( 'script' );
|
||||
script.setAttribute( 'type', 'text/x-mathjax-config' );
|
||||
if ( window.opera ) script.innerHTML = config; else script.text = config;
|
||||
document.getElementsByTagName('head')[0].appendChild( script );
|
||||
// create startup element
|
||||
mediaWiki.loader.load('ext.math.mathjax');
|
||||
|
||||
// create startup element
|
||||
mediaWiki.loader.load('ext.math.mathjax');
|
||||
this.loaded = true;
|
||||
|
||||
this.loaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue