Add <wbr> as ignored tag, and change to a list of ones to ignore. Cache the math.nextSibling node. Remove msieNewlineBug and fold that into the ignoreTags hash. Resolves issue #1087.

This commit is contained in:
Davide P. Cervone 2016-07-05 21:06:31 -04:00
parent 7523687f4c
commit 92e1ce90b5

View File

@ -72,6 +72,15 @@ MathJax.Extension.tex2jax = {
}, },
//
// Tags to ignore when searching for TeX in the page
//
ignoreTags: {
br: (MathJax.Hub.Browser.isMSIE && document.documentMode < 9 ? "\n" : " "),
wbr: "",
"#comment": ""
},
PreProcess: function (element) { PreProcess: function (element) {
if (!this.configured) { if (!this.configured) {
this.config = MathJax.Hub.CombineConfig("tex2jax",this.config); this.config = MathJax.Hub.CombineConfig("tex2jax",this.config);
@ -164,8 +173,7 @@ MathJax.Extension.tex2jax = {
if (this.search.matched) {element = this.encloseMath(element)} if (this.search.matched) {element = this.encloseMath(element)}
if (element) { if (element) {
do {prev = element; element = element.nextSibling} do {prev = element; element = element.nextSibling}
while (element && (element.nodeName.toLowerCase() === 'br' || while (element && this.ignoreTags[element.nodeName.toLowerCase()] != null);
element.nodeName.toLowerCase() === '#comment'));
if (!element || element.nodeName !== '#text') if (!element || element.nodeName !== '#text')
{return (this.search.close ? this.prevEndMatch() : prev)} {return (this.search.close ? this.prevEndMatch() : prev)}
} }
@ -242,25 +250,24 @@ MathJax.Extension.tex2jax = {
}, },
encloseMath: function (element) { encloseMath: function (element) {
var search = this.search, close = search.close, CLOSE, math; var search = this.search, close = search.close, CLOSE, math, next;
if (search.cpos === close.length) {close = close.nextSibling} if (search.cpos === close.length) {close = close.nextSibling}
else {close = close.splitText(search.cpos)} else {close = close.splitText(search.cpos)}
if (!close) {CLOSE = close = MathJax.HTML.addText(search.close.parentNode,"")} if (!close) {CLOSE = close = MathJax.HTML.addText(search.close.parentNode,"")}
search.close = close; search.close = close;
math = (search.opos ? search.open.splitText(search.opos) : search.open); math = (search.opos ? search.open.splitText(search.opos) : search.open);
while (math.nextSibling && math.nextSibling !== close) { while ((next = math.nextSibling) && next !== close) {
if (math.nextSibling.nodeValue !== null) { if (next.nodeValue !== null) {
if (math.nextSibling.nodeName === "#comment") { if (next.nodeName === "#comment") {
math.nodeValue += math.nextSibling.nodeValue.replace(/^\[CDATA\[((.|\n|\r)*)\]\]$/,"$1"); math.nodeValue += next.nodeValue.replace(/^\[CDATA\[((.|\n|\r)*)\]\]$/,"$1");
} else { } else {
math.nodeValue += math.nextSibling.nodeValue; math.nodeValue += next.nodeValue;
} }
} else if (this.msieNewlineBug) { } else{
math.nodeValue += (math.nextSibling.nodeName.toLowerCase() === "br" ? "\n" : " "); var ignore = this.ignoreTags[next.nodeName.toLowerCase()];
} else { math.nodeValue += (ignore == null ? " " : ignore);
math.nodeValue += " ";
} }
math.parentNode.removeChild(math.nextSibling); math.parentNode.removeChild(next);
} }
var TeX = math.nodeValue.substr(search.olen,math.nodeValue.length-search.olen-search.clen); var TeX = math.nodeValue.substr(search.olen,math.nodeValue.length-search.olen-search.clen);
math.parentNode.removeChild(math); math.parentNode.removeChild(math);
@ -294,9 +301,7 @@ MathJax.Extension.tex2jax = {
return script; return script;
}, },
filterPreview: function (tex) {return tex}, filterPreview: function (tex) {return tex}
msieNewlineBug: (MathJax.Hub.Browser.isMSIE && document.documentMode < 9)
}; };