|
29 | 29 | MathJax.Extension.mml2jax = {
|
30 | 30 | version: "2.2",
|
31 | 31 | config: {
|
32 |
| - preview: "alttext" // Use the <math> element's alttext as the |
| 32 | + preview: "mathml" // Use the <math> element as the |
33 | 33 | // preview. Set to "none" for no preview,
|
| 34 | + // set to "alttext" to use the alttext attribute |
| 35 | + // of the <math> element, set to "altimg" to use |
| 36 | + // an image described by the altimg* attributes |
34 | 37 | // or set to an array specifying an HTML snippet
|
35 | 38 | // to use a fixed preview for all math
|
36 | 39 |
|
@@ -181,13 +184,35 @@ MathJax.Extension.mml2jax = {
|
181 | 184 | createPreview: function (math,script) {
|
182 | 185 | var preview = this.config.preview;
|
183 | 186 | if (preview === "none") return;
|
184 |
| - if (preview === "alttext") { |
185 |
| - var text = math.getAttribute("alttext"); |
186 |
| - if (text != null) {preview = [this.filterPreview(text)]} else {preview = null} |
187 |
| - } |
| 187 | + var isNodePreview = false; |
| 188 | + if (preview === "mathml") { |
| 189 | + isNodePreview = true; |
| 190 | + // mathml preview does not work with IE < 9, so fallback to alttext. |
| 191 | + if (this.MathTagBug) {preview = "alttext"} else {preview = math} |
| 192 | + } |
| 193 | + if (preview === "alttext" || preview === "altimg") { |
| 194 | + isNodePreview = true; |
| 195 | + var alttext = this.filterPreview(math.getAttribute("alttext")); |
| 196 | + if (preview === "alttext") { |
| 197 | + if (alttext != null) {preview = MathJax.HTML.TextNode(alttext)} else {preview = null} |
| 198 | + } else { |
| 199 | + var src = math.getAttribute("altimg"); |
| 200 | + if (src != null) { |
| 201 | + // FIXME: use altimg-valign when display="inline"? |
| 202 | + var style = {width: math.getAttribute("altimg-width"), height: math.getAttribute("altimg-height")}; |
| 203 | + preview = MathJax.HTML.Element("img",{src:src,alt:alttext,style:style}); |
| 204 | + } else {preview = null} |
| 205 | + } |
| 206 | + } |
188 | 207 | if (preview) {
|
189 |
| - preview = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview); |
190 |
| - script.parentNode.insertBefore(preview,script); |
| 208 | + var span; |
| 209 | + if (isNodePreview) { |
| 210 | + span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass}); |
| 211 | + span.appendChild(preview); |
| 212 | + } else { |
| 213 | + span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview); |
| 214 | + } |
| 215 | + script.parentNode.insertBefore(span,script); |
191 | 216 | }
|
192 | 217 | },
|
193 | 218 |
|
|
0 commit comments