Fix for parentNode bug in IE

This commit is contained in:
Davide P. Cervone 2010-11-09 07:20:13 -05:00
parent 3dfd100a64
commit ba8a739531
3 changed files with 31 additions and 13 deletions

View File

@ -13,6 +13,6 @@
*/
MathJax.Unpack([
['MathJax.Extension.tex2jax','={version:"1.0",config:{element:null,','inlineMath',':[["$","$"],["\\\\(","\\\\)"]],','displayMath',':[["$$","$$"],["\\\\[","\\\\]"]],skipTags:["script","noscript","style","textarea","pre","code"],','ignoreClass',':"tex2jax_ignore",','processClass',':"tex2jax_process",','processEscapes',':false,','processEnvironments',':true,preview:"TeX"},','PreProcess',':function(','a){if(!','this.configured','){','MathJax.Hub.','Insert(','this.config',',(',19,'config.','tex2jax||{}));if(',21,'.Augment','){',19,'Insert(this,',21,27,')}','if(typeof(',21,'.previewTeX',')!=="undefined"&&!',21,36,'){',21,'.preview','="none"}',17,'=true}',34,'a)==="','string"){a=','document.','getElementById(a)}if(!a){a=',21,'.element||',49,'body}this.','createPatterns','();this.','scanElement','(a,a','.nextSibling',')},',55,':function(){var d=[],c,a,b=',21,';this.match={};','for(c=0,a=b.',2,'.length;c<a;c++){d.push(this.patternQuote(b.',2,'[c][0]));this.match[b.',2,'[c][0]]={mode:"",','end:b.',2,'[c][1],pattern:this.endPattern(b.',2,'[c][1])}}',65,4,67,4,69,4,'[c][0]]={','mode:"; mode=display",',72,4,74,4,76,'this.start','=','new RegExp','(d.sort(this.sortLength).join("|")+(b.',12,'?"|\\\\\\\\begin\\\\{([^}]*)\\\\}":"")+(b.',10,'?"|\\\\\\\\*\\\\\\\\\\\\$":""),"g");this.skipTags=',92,'("^("+b.skipTags.join("|")+")$","i");this.',6,'=new RegExp("(^| )("+b.',6,'+")( |$)");this.',8,101,8,'+")( |$)")},','patternQuote',15,'a){return ','a','.replace','(/([\\^$(){}+*?\\-|\\[\\]\\:\\\\])/g,"\\\\$1")},endPattern',15,110,92,'(this.',108,'(a)+"|\\\\\\\\.","g")},sortLength',15,'d,c){if(d.length!==c.length){return c.length-d.length}return(d==c?0:(d<c?-1:1))},',57,15,'c,b,f){var a,e,d;while(c&&c!=b){if(c','.nodeName.toLowerCase()==="#','text"){if(!f){c=this.scanText(c)}}else{a','=(typeof(c.','className',')==="undefined"?"":c.',128,');e',127,'tagName',129,133,');',34,'a)!=="',48,'String(a)}if','(c.firstChild','&&!a.match(/(^| )MathJax/)&&!this.skipTags.exec(e)){d=(f||this.',6,'.exec(a))&&!this.',8,'.exec(a);this.',57,141,',b,d)}}if(c){c=c',59,'}}},scanText',15,'b){if(b','.nodeValue',112,'(/\\s+/,"")==""){return b}var a,c;','this.search','={start:true};','this.pattern','=',90,';while(b){','this.pattern.lastIndex','=0;while(b&&b',125,'text"&&(a=',159,'.exec(b',154,'))){if(',157,'.start){b=this.startMatch(a,b)}else{b=this.endMatch(a,b)}}if(',157,'.matched','){','b=this.encloseMath(b',')}if(b){do{c=b;b=b',59,'}while(b&&(b','.nodeName','.toLowerCase()==="br"||b',125,'comment"));if(!b||b',180,'!=="#text"){return c}}}return b},startMatch',15,'b,c){var d=this.match[b[0]];if(d!=null){',157,'={end:d.end,mode:d.mode,','open:c,olen:','b[0].length',',opos:',163,'-',191,'};','this.switchPattern(','d.pattern)}else{if(b[0].substr(0,6)==="\\\\begin"){',157,'={end:"\\\\end{"+b[1]+"}",',84,190,'0,opos:',163,'-',191,',isBeginEnd:true};',197,'this.endPattern(',157,'.end))}else{var a=b[0].replace(/\\\\(.)/g,"$1");c',154,'=c',154,'.substr(','0,b.index)+a+c',154,215,'b.index+',191,');',163,'-=',191,'-a.length}}return c},endMatch',15,'a,b){if(a[0]==',157,'.end){',157,'.close=b;',157,'.cpos=',163,';',157,'.clen=(',157,'.isBeginEnd?0:a[0].length);',157,174,'=true;',176,');',197,90,')}return b},switchPattern',15,'a){a.lastIndex=',163,';',159,'=a;',157,'.start=(a===',90,')},encloseMath',15,'b){var a=',157,',f=a.close,e;if(a.cpos===f.length){f=f',59,'}else{f=f.splitText(a.cpos)}if(!f){e=f=','a.close.parentNode','.appendChild(document.createTextNode','(""))}if(b===a.close){b=f}a.close=f;var c=a.open.splitText(a.opos);if(a.open',154,'===""){a.open','.parentNode.removeChild(','a.open)}while(c',59,'&&c',59,'!==f){if(c',59,154,'!==null){if(c',59,180,'==="#comment"){c',154,'+=c',59,154,112,'(/^\\[CDATA\\[((.|\\n|\\r)*)\\]\\]$/,"$1")}else{c',154,'+=c',59,154,'}}else{c',154,'+=" "}c',269,'c',59,')}var d=c',154,215,'a.olen,c',154,'.length-a.olen-a.clen);c',269,'c);if(',21,42,'!=="none"){this.','createPreview','(a.mode,d',')}c=this.','createMathTag',309,');',157,'={};',163,'=0;if(e){e',269,'e)}return c},insertNode',15,259,157,';if(a.close&&',264,'){',264,'.insertBefore(b,a.','close)}else{if(a.open',59,'){a.open.parentNode',327,'open',59,')}else{a.open.parentNode.appendChild(b)}}},',308,15,'c,a){var b;if(',21,42,'==="TeX"){b=[this.filterTeX(a)]}else{if(',21,42,' instanceof Array){b=',21,42,'}}if(b){b=MathJax.HTML.Element("span",{',128,':',19,24,'preRemoveClass},b);','this.insertNode(','b)}},',311,15,'c,',259,49,'createElement("script");a.type="math/tex"+c;if(',19,'Browser.isMSIE){a.text=b}else{a',265,'(b))}',352,'a);return a},filterTeX',15,110,'a}};',19,'Register.PreProcessor(["',14,'",',0,']);MathJax.Ajax.loadComplete("[MathJax]/extensions/tex2jax.js");']
['MathJax.Extension.tex2jax','={version:"1.0.1",config:{element:null,','inlineMath',':[["$","$"],["\\\\(","\\\\)"]],','displayMath',':[["$$","$$"],["\\\\[","\\\\]"]],skipTags:["script","noscript","style","textarea","pre","code"],','ignoreClass',':"tex2jax_ignore",','processClass',':"tex2jax_process",','processEscapes',':false,','processEnvironments',':true,preview:"TeX"},','PreProcess',':function(','a){if(!','this.configured','){','MathJax.Hub.','Insert(','this.config',',(',19,'config.','tex2jax||{}));if(',21,'.Augment','){',19,'Insert(this,',21,27,')}','if(typeof(',21,'.previewTeX',')!=="undefined"&&!',21,36,'){',21,'.preview','="none"}',17,'=true}',34,'a)==="','string"){a=','document.','getElementById(a)}if(!a){a=',21,'.element||',49,'body}this.','createPatterns','();this.','scanElement','(a,a','.nextSibling',')},',55,':function(){var d=[],c,a,b=',21,';this.match={};','for(c=0,a=b.',2,'.length;c<a;c++){d.push(this.patternQuote(b.',2,'[c][0]));this.match[b.',2,'[c][0]]={mode:"",','end:b.',2,'[c][1],pattern:this.endPattern(b.',2,'[c][1])}}',65,4,67,4,69,4,'[c][0]]={','mode:"; mode=display",',72,4,74,4,76,'this.start','=','new RegExp','(d.sort(this.sortLength).join("|")+(b.',12,'?"|\\\\\\\\begin\\\\{([^}]*)\\\\}":"")+(b.',10,'?"|\\\\\\\\*\\\\\\\\\\\\$":""),"g");this.skipTags=',92,'("^("+b.skipTags.join("|")+")$","i");this.',6,'=new RegExp("(^| )("+b.',6,'+")( |$)");this.',8,101,8,'+")( |$)")},','patternQuote',15,'a){return ','a','.replace','(/([\\^$(){}+*?\\-|\\[\\]\\:\\\\])/g,"\\\\$1")},endPattern',15,110,92,'(this.',108,'(a)+"|\\\\\\\\.","g")},sortLength',15,'d,c){if(d.length!==c.length){return c.length-d.length}return(d==c?0:(d<c?-1:1))},',57,15,'c,b,f){var a,e,d;while(c&&c!=b){if(c','.nodeName.toLowerCase()==="#','text"){if(!f){c=this.scanText(c)}}else{a','=(typeof(c.','className',')==="undefined"?"":c.',128,');e',127,'tagName',129,133,');',34,'a)!=="',48,'String(a)}if','(c.firstChild','&&!a.match(/(^| )MathJax/)&&!this.skipTags.exec(e)){d=(f||this.',6,'.exec(a))&&!this.',8,'.exec(a);this.',57,141,',b,d)}}if(c){c=c',59,'}}},scanText',15,'b){if(b','.nodeValue',112,'(/\\s+/,"")==""){return b}var a,c;','this.search','={start:true};','this.pattern','=',90,';while(b){','this.pattern.lastIndex','=0;while(b&&b',125,'text"&&(a=',159,'.exec(b',154,'))){if(',157,'.start){b=this.startMatch(a,b)}else{b=this.endMatch(a,b)}}if(',157,'.matched','){','b=this.encloseMath(b',')}if(b){do{c=b;b=b',59,'}while(b&&(b','.nodeName','.toLowerCase()==="br"||b',125,'comment"));if(!b||b',180,'!=="#text"){return c}}}return b},startMatch',15,'b,c){var d=this.match[b[0]];if(d!=null){',157,'={end:d.end,mode:d.mode,','open:c,olen:','b[0].length',',opos:',163,'-',191,'};','this.switchPattern(','d.pattern)}else{if(b[0].substr(0,6)==="\\\\begin"){',157,'={end:"\\\\end{"+b[1]+"}",',84,190,'0,opos:',163,'-',191,',isBeginEnd:true};',197,'this.endPattern(',157,'.end))}else{var a=b[0].replace(/\\\\(.)/g,"$1");c',154,'=c',154,'.substr(','0,b.index)+a+c',154,215,'b.index+',191,');',163,'-=',191,'-a.length}}return c},endMatch',15,'a,b){if(a[0]==',157,'.end){',157,'.close=b;',157,'.cpos=',163,';',157,'.clen=(',157,'.isBeginEnd?0:a[0].length);',157,174,'=true;',176,');',197,90,')}return b},switchPattern',15,'a){a.lastIndex=',163,';',159,'=a;',157,'.start=(a===',90,')},encloseMath',15,'b){var a=',157,',f=a.close,e,c;if(a.cpos===f.length){f=f',59,'}else{f=f.splitText(a.cpos)}if(!f){e=f=MathJax.HTML.addText(','a.close.parentNode',',"")}if(b===a.close){b=f}a.close=f;c=(a.opos?a.open.splitText(a.opos):a.open);while(c',59,'&&c',59,'!==f){if(c',59,154,'!==null){if(c',59,180,'==="#comment"){c',154,'+=c',59,154,112,'(/^\\[CDATA\\[((.|\\n|\\r)*)\\]\\]$/,"$1")}else{c',154,'+=c',59,154,'}}else{c',154,'+=" "}c','.parentNode.removeChild(','c',59,')}var d=c',154,215,'a.olen,c',154,'.length-a.olen-a.clen);c',289,'c);if(',21,42,'!=="none"){this.','createPreview','(a.mode,d',')}c=this.','createMathTag',304,');',157,'={};',163,'=0;if(e){e',289,'e)}return c},insertNode',15,259,157,';',264,'.insertBefore(b,a.close)},',303,15,'c,a){var b;if(',21,42,'==="TeX"){b=[this.filterTeX(a)]}else{if(',21,42,' instanceof Array){b=',21,42,'}}if(b){b=MathJax.HTML.Element("span",{',128,':',19,24,'preRemoveClass},b);','this.insertNode(','b)}},',306,15,'c,',259,49,'createElement("script");a.type="math/tex"+c;if(',19,'Browser.isMSIE){a.text=b}else{a.appendChild(',49,'createTextNode(b))}',338,'a);return a},filterTeX',15,110,'a}};',19,'Register.PreProcessor(["',14,'",',0,']);MathJax.Ajax.loadComplete("[MathJax]/extensions/tex2jax.js");']
]);

View File

@ -24,7 +24,7 @@
*/
MathJax.Extension.tex2jax = {
version: "1.0",
version: "1.0.1",
config: {
element: null, // The ID of the element to be processed
// (defaults to full document)
@ -203,14 +203,13 @@ MathJax.Extension.tex2jax = {
},
encloseMath: function (element) {
var search = this.search, close = search.close, CLOSE;
var search = this.search, close = search.close, CLOSE, math;
if (search.cpos === close.length) {close = close.nextSibling}
else {close = close.splitText(search.cpos)}
if (!close) {CLOSE = close = search.close.parentNode.appendChild(document.createTextNode(""))}
if (!close) {CLOSE = close = MathJax.HTML.addText(search.close.parentNode,"")}
if (element === search.close) {element = close}
search.close = close;
var math = search.open.splitText(search.opos);
if (search.open.nodeValue === "" && search.open.parentNode) {search.open.parentNode.removeChild(search.open)}
math = (search.opos ? search.open.splitText(search.opos) : search.open);
while (math.nextSibling && math.nextSibling !== close) {
if (math.nextSibling.nodeValue !== null) {
if (math.nextSibling.nodeName === "#comment") {
@ -232,13 +231,7 @@ MathJax.Extension.tex2jax = {
insertNode: function (node) {
var search = this.search;
if (search.close && search.close.parentNode) {
search.close.parentNode.insertBefore(node,search.close);
} else if (search.open.nextSibling) {
search.open.parentNode.insertBefore(node,search.open.nextSibling);
} else {
search.open.parentNode.appendChild(node);
}
search.close.parentNode.insertBefore(node,search.close);
},
createPreview: function (mode,tex) {

25
test/tex2jax.html Normal file
View File

@ -0,0 +1,25 @@
<html>
<head>
<title>MathJax tex2jax Test</title>
<script src="../mathjax/unpacked/MathJax.js">
MathJax.Hub.Config({
jax: ["input/TeX","output/HTML-CSS"],
extensions: ["tex2jax.js"]
});
</script>
<style>
p {border: 1px solid black; background:#EEEEEE;}
</style>
</head>
<body>
<p>Text Before: \(x+1\)</p>
<p>\(x+1\) Text after</p>
<p>\(\text{no text}\)</p>
<p>Text Before: $$x+1$$</p>
<p>$$x+1$$ Text after</p>
<p>$$\text{no text}$$</p>
</body>
</html>