From 850f736aa7f8cd08ce2b01b1b47dafa00edc15c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Fri, 30 Aug 2013 11:27:12 +0200 Subject: [PATCH 1/4] Add preview=mathml,altimg to the mml2jax preprocessor. #557 --- unpacked/extensions/mml2jax.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/unpacked/extensions/mml2jax.js b/unpacked/extensions/mml2jax.js index b946f7332..097f550f2 100644 --- a/unpacked/extensions/mml2jax.js +++ b/unpacked/extensions/mml2jax.js @@ -181,13 +181,24 @@ 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} - } + if (preview === "mathml") {preview = math} + else if (preview === "alttext" || preview === "altimg") { + 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 = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass}); + span.appendChild(preview); + script.parentNode.insertBefore(span,script); } }, From e3914df18780bdb586fc828c01f5f775e5661a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Mon, 9 Sep 2013 14:57:54 +0200 Subject: [PATCH 2/4] Set the default mml2jax preview to "mathml". #557 --- unpacked/config/default.js | 15 +++++++++------ unpacked/extensions/mml2jax.js | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/unpacked/config/default.js b/unpacked/config/default.js index f016855ea..cc96375ab 100644 --- a/unpacked/config/default.js +++ b/unpacked/config/default.js @@ -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 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 tag as the preview (until it is processed by MathJax). + // Set to "alttext", to use the 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 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" }, diff --git a/unpacked/extensions/mml2jax.js b/unpacked/extensions/mml2jax.js index 097f550f2..c16192280 100644 --- a/unpacked/extensions/mml2jax.js +++ b/unpacked/extensions/mml2jax.js @@ -29,8 +29,11 @@ MathJax.Extension.mml2jax = { version: "2.2", config: { - preview: "alttext" // Use the element's alttext as the + preview: "mathml" // Use the element as the // preview. Set to "none" for no preview, + // set to "alttext" to use the alttext attribute + // of the 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 From 3922f0c07cf340e6a038babc84fd0ac021ab433b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Wed, 11 Sep 2013 12:16:50 +0200 Subject: [PATCH 3/4] Disallow mathml preview on IE < 9. #557 --- unpacked/extensions/mml2jax.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/unpacked/extensions/mml2jax.js b/unpacked/extensions/mml2jax.js index c16192280..943897031 100644 --- a/unpacked/extensions/mml2jax.js +++ b/unpacked/extensions/mml2jax.js @@ -184,8 +184,11 @@ MathJax.Extension.mml2jax = { createPreview: function (math,script) { var preview = this.config.preview; if (preview === "none") return; - if (preview === "mathml") {preview = math} - else if (preview === "alttext" || preview === "altimg") { + if (preview === "mathml") { + // 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") { var alttext = this.filterPreview(math.getAttribute("alttext")); if (preview === "alttext") { if (alttext != null) {preview = MathJax.HTML.TextNode(alttext)} else {preview = null} From 6e442e36bda22f7924c5f25189b9bc6e0c55a469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Tue, 17 Sep 2013 14:19:59 +0200 Subject: [PATCH 4/4] Fix regression with HTML snippet preview. #557 --- unpacked/extensions/mml2jax.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/unpacked/extensions/mml2jax.js b/unpacked/extensions/mml2jax.js index 943897031..fe8ed4f32 100644 --- a/unpacked/extensions/mml2jax.js +++ b/unpacked/extensions/mml2jax.js @@ -184,11 +184,14 @@ MathJax.Extension.mml2jax = { createPreview: function (math,script) { var preview = this.config.preview; if (preview === "none") return; + 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} @@ -202,8 +205,13 @@ MathJax.Extension.mml2jax = { } } if (preview) { - var span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass}); - span.appendChild(preview); + 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); } },