Merge pull request #577 from fred-wang/issue557

Issue557
This commit is contained in:
Frédéric Wang 2013-09-17 11:25:54 -07:00
commit 4ec3192904
2 changed files with 41 additions and 13 deletions

View File

@ -432,12 +432,15 @@ MathJax.Hub.Config({
//
// Controls whether mml2jax inserts MathJax_Preview spans to make a
// preview available, and what preview to use, whrn it locates
// mathematics on the page. The default is "alttext", which means use
// the <math> tag's alttext attribute as the preview (until it is
// processed by MathJax), if the tag has one. Set to "none" to
// preview available, and what preview to use, when it locates
// mathematics on the page. The default is "mathml" which means use
// the <math> tag as the preview (until it is processed by MathJax).
// Set to "alttext", to use the <math> tag's alttext attribute as the
// preview, if the tag has one. Set to "none" to
// prevent the previews from being inserted (the math will simply
// disappear until it is typeset). Set to an array containing the
// disappear until it is typeset). Set to "altimg" to use an image
// described by the altimg* attributes of the <math> element.
// Set to an array containing the
// description of an HTML snippet in order to use the same preview for
// all equations on the page (e.g., you could have it say "[math]" or
// load an image).
@ -445,7 +448,7 @@ MathJax.Hub.Config({
// E.g., preview: ["[math]"],
// or preview: [["img",{src: "http://myserver.com/images/mypic.jpg"}]]
//
preview: "alttext"
preview: "mathml"
},

View File

@ -29,8 +29,11 @@
MathJax.Extension.mml2jax = {
version: "2.2",
config: {
preview: "alttext" // Use the <math> element's alttext as the
preview: "mathml" // Use the <math> element as the
// preview. Set to "none" for no preview,
// set to "alttext" to use the alttext attribute
// of the <math> element, set to "altimg" to use
// an image described by the altimg* attributes
// or set to an array specifying an HTML snippet
// to use a fixed preview for all math
@ -181,13 +184,35 @@ MathJax.Extension.mml2jax = {
createPreview: function (math,script) {
var preview = this.config.preview;
if (preview === "none") return;
if (preview === "alttext") {
var text = math.getAttribute("alttext");
if (text != null) {preview = [this.filterPreview(text)]} else {preview = null}
}
var isNodePreview = false;
if (preview === "mathml") {
isNodePreview = true;
// mathml preview does not work with IE < 9, so fallback to alttext.
if (this.MathTagBug) {preview = "alttext"} else {preview = math}
}
if (preview === "alttext" || preview === "altimg") {
isNodePreview = true;
var alttext = this.filterPreview(math.getAttribute("alttext"));
if (preview === "alttext") {
if (alttext != null) {preview = MathJax.HTML.TextNode(alttext)} else {preview = null}
} else {
var src = math.getAttribute("altimg");
if (src != null) {
// FIXME: use altimg-valign when display="inline"?
var style = {width: math.getAttribute("altimg-width"), height: math.getAttribute("altimg-height")};
preview = MathJax.HTML.Element("img",{src:src,alt:alttext,style:style});
} else {preview = null}
}
}
if (preview) {
preview = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview);
script.parentNode.insertBefore(preview,script);
var span;
if (isNodePreview) {
span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});
span.appendChild(preview);
} else {
span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview);
}
script.parentNode.insertBefore(span,script);
}
},