Handle empty delimiter patterns, and don't scan the page if there is nothing to look for (resolves issue #174)
This commit is contained in:
parent
7d11c17c89
commit
8930ef853e
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MathJax.Extension.tex2jax = {
|
MathJax.Extension.tex2jax = {
|
||||||
version: "1.1.4",
|
version: "1.1.5",
|
||||||
config: {
|
config: {
|
||||||
inlineMath: [ // The start/stop pairs for in-line math
|
inlineMath: [ // The start/stop pairs for in-line math
|
||||||
// ['$','$'], // (comment out any you don't want, or add your own, but
|
// ['$','$'], // (comment out any you don't want, or add your own, but
|
||||||
|
@ -74,12 +74,11 @@ MathJax.Extension.tex2jax = {
|
||||||
}
|
}
|
||||||
if (typeof(element) === "string") {element = document.getElementById(element)}
|
if (typeof(element) === "string") {element = document.getElementById(element)}
|
||||||
if (!element) {element = document.body}
|
if (!element) {element = document.body}
|
||||||
this.createPatterns();
|
if (this.createPatterns()) {this.scanElement(element,element.nextSibling)}
|
||||||
this.scanElement(element,element.nextSibling);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
createPatterns: function () {
|
createPatterns: function () {
|
||||||
var starts = [], i, m, config = this.config;
|
var starts = [], parts = [], i, m, config = this.config;
|
||||||
this.match = {};
|
this.match = {};
|
||||||
for (i = 0, m = config.inlineMath.length; i < m; i++) {
|
for (i = 0, m = config.inlineMath.length; i < m; i++) {
|
||||||
starts.push(this.patternQuote(config.inlineMath[i][0]));
|
starts.push(this.patternQuote(config.inlineMath[i][0]));
|
||||||
|
@ -97,15 +96,15 @@ MathJax.Extension.tex2jax = {
|
||||||
pattern: this.endPattern(config.displayMath[i][1])
|
pattern: this.endPattern(config.displayMath[i][1])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
this.start = new RegExp(
|
if (starts.length) {parts.push(starts.sort(this.sortLEngth).join("|"))}
|
||||||
starts.sort(this.sortLength).join("|") +
|
if (config.processEnvironments) {parts.push("\\\\begin\\{([^}]*)\\}")}
|
||||||
(config.processEnvironments ? "|\\\\begin\\{([^}]*)\\}" : "") +
|
if (config.processEscapes) {parts.push("\\\\*\\\\\\\$")}
|
||||||
(config.processEscapes ? "|\\\\*\\\\\\\$" : "") +
|
if (config.processRefs) {parts.push("\\\\(eq)?ref\\{[^}]*\\}")}
|
||||||
(config.processRefs ? "|\\\\(eq)?ref\\{[^}]*\\}" : ""), "g"
|
this.start = new RegExp(parts.join("|"),"g");
|
||||||
);
|
|
||||||
this.skipTags = new RegExp("^("+config.skipTags.join("|")+")$","i");
|
this.skipTags = new RegExp("^("+config.skipTags.join("|")+")$","i");
|
||||||
this.ignoreClass = new RegExp("(^| )("+config.ignoreClass+")( |$)");
|
this.ignoreClass = new RegExp("(^| )("+config.ignoreClass+")( |$)");
|
||||||
this.processClass = new RegExp("(^| )("+config.processClass+")( |$)");
|
this.processClass = new RegExp("(^| )("+config.processClass+")( |$)");
|
||||||
|
return (parts.length > 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
patternQuote: function (s) {return s.replace(/([\^$(){}+*?\-|\[\]\:\\])/g,'\\$1')},
|
patternQuote: function (s) {return s.replace(/([\^$(){}+*?\-|\[\]\:\\])/g,'\\$1')},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user