(bug 35188) Do not poison the tex formula with markup

We move the block/inline styling (aka display vs textstyle) markup into
a filter used just before rendering. This way the 'used' formula will
not suddenly contain styling information that wasn't part of the
original formula.

Change-Id: Ie0c308c31d38581e556dc73109879c7a3d365121
This commit is contained in:
nageh 2012-09-07 16:58:18 +02:00 committed by TheDJ
parent 7b2b7301e0
commit b08fbbbe38

View file

@ -20,6 +20,7 @@ MathJax.Extension.wiki2jax = {
if (this.config.Augment) {MathJax.Hub.Insert(this,this.config.Augment)}
this.previewClass = MathJax.Hub.config.preRemoveClass;
this.setupPrefilter();
this.configured = true;
}
var that = this;
@ -28,6 +29,16 @@ MathJax.Extension.wiki2jax = {
});
},
setupPrefilter: function() { // used to fix a number of common wiki math hacks
MathJax.Hub.Register.StartupHook("TeX Jax Ready", function() {
MathJax.InputJax.TeX.prefilterHooks.Add( function(data) {
data.math = data.math.replace(/^\s*\\scriptstyle(\W)/,"\\textstyle$1").replace(/^\s*\\scriptscriptstyle(\W)/,"\\scriptstyle$1");
if (data.script.type.match(/(;|\s|\n)mode\s*=\s*display-nobreak(;|\s|\n|$)/) != null)
data.math = "\\displaystyle " + data.math;
});
});
},
ConvertMath: function (node) {
var parent = node.parentNode,
mode = parent.tagName === "DD" && parent.childNodes.length === 1 ? "; mode=display" : "",
@ -40,10 +51,8 @@ MathJax.Extension.wiki2jax = {
}
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");
if (parent.firstChild === node) tex = "\\displaystyle "+tex;
}
if (mode === "" && parent.firstChild === node) mode = "; mode=display-nobreak";
var script = document.createElement("script");
script.type = "math/tex" + mode;