Skip to content

Commit 850f736

Browse files
committed
Add preview=mathml,altimg to the mml2jax preprocessor. #557
1 parent 86a908b commit 850f736

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

unpacked/extensions/mml2jax.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,24 @@ MathJax.Extension.mml2jax = {
181181
createPreview: function (math,script) {
182182
var preview = this.config.preview;
183183
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-
}
184+
if (preview === "mathml") {preview = math}
185+
else if (preview === "alttext" || preview === "altimg") {
186+
var alttext = this.filterPreview(math.getAttribute("alttext"));
187+
if (preview === "alttext") {
188+
if (alttext != null) {preview = MathJax.HTML.TextNode(alttext)} else {preview = null}
189+
} else {
190+
var src = math.getAttribute("altimg");
191+
if (src != null) {
192+
// FIXME: use altimg-valign when display="inline"?
193+
var style = {width: math.getAttribute("altimg-width"), height: math.getAttribute("altimg-height")};
194+
preview = MathJax.HTML.Element("img",{src:src,alt:alttext,style:style});
195+
} else {preview = null}
196+
}
197+
}
188198
if (preview) {
189-
preview = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview);
190-
script.parentNode.insertBefore(preview,script);
199+
var span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});
200+
span.appendChild(preview);
201+
script.parentNode.insertBefore(span,script);
191202
}
192203
},
193204

0 commit comments

Comments
 (0)