Fixes #391
This commit is contained in:
parent
3c384739ee
commit
a7877483b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,4 +4,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
stackedit.iml
|
||||||
public/res/bower-libs
|
public/res/bower-libs
|
||||||
|
@ -534,8 +534,7 @@ define([
|
|||||||
if(contentElt.lastChild === trailingLfNode && trailingLfNode.textContent.slice(-1) == '\n') {
|
if(contentElt.lastChild === trailingLfNode && trailingLfNode.textContent.slice(-1) == '\n') {
|
||||||
newTextContent = newTextContent.slice(0, -1);
|
newTextContent = newTextContent.slice(0, -1);
|
||||||
}
|
}
|
||||||
newTextContent = newTextContent.replace(/\r\n/g, '\n'); // DOS to Unix
|
newTextContent = newTextContent.replace(/\r\n?/g, '\n'); // Mac/DOS to Unix
|
||||||
newTextContent = newTextContent.replace(/\r/g, '\n'); // Mac to Unix
|
|
||||||
|
|
||||||
if(fileChanged === false) {
|
if(fileChanged === false) {
|
||||||
if(newTextContent == textContent) {
|
if(newTextContent == textContent) {
|
||||||
|
@ -1,169 +1,277 @@
|
|||||||
/*defines MathJax */
|
/*defines MathJax */
|
||||||
define([
|
define([
|
||||||
"utils",
|
"utils",
|
||||||
"classes/Extension",
|
"classes/Extension",
|
||||||
"text!html/mathJaxSettingsBlock.html",
|
"text!html/mathJaxSettingsBlock.html",
|
||||||
"mathjax"
|
"mathjax"
|
||||||
], function(utils, Extension, mathJaxSettingsBlockHTML) {
|
], function(utils, Extension, mathJaxSettingsBlockHTML) {
|
||||||
|
|
||||||
var mathJax = new Extension("mathJax", "MathJax", true);
|
var mathJax = new Extension("mathJax", "MathJax", true);
|
||||||
mathJax.settingsBlock = mathJaxSettingsBlockHTML;
|
mathJax.settingsBlock = mathJaxSettingsBlockHTML;
|
||||||
mathJax.defaultConfig = {
|
mathJax.defaultConfig = {
|
||||||
tex: "{}",
|
tex : "{}",
|
||||||
tex2jax: '{ inlineMath: [["$","$"],["\\\\\\\\(","\\\\\\\\)"]], displayMath: [["$$","$$"],["\\\\[","\\\\]"]], processEscapes: true }'
|
tex2jax: '{ inlineMath: [["$","$"],["\\\\\\\\(","\\\\\\\\)"]], displayMath: [["$$","$$"],["\\\\[","\\\\]"]], processEscapes: true }'
|
||||||
};
|
};
|
||||||
|
|
||||||
mathJax.onLoadSettings = function() {
|
mathJax.onLoadSettings = function() {
|
||||||
utils.setInputValue("#input-mathjax-config-tex", mathJax.config.tex);
|
utils.setInputValue("#input-mathjax-config-tex", mathJax.config.tex);
|
||||||
utils.setInputValue("#input-mathjax-config-tex2jax", mathJax.config.tex2jax);
|
utils.setInputValue("#input-mathjax-config-tex2jax", mathJax.config.tex2jax);
|
||||||
};
|
};
|
||||||
|
|
||||||
mathJax.onSaveSettings = function(newConfig, event) {
|
mathJax.onSaveSettings = function(newConfig, event) {
|
||||||
newConfig.tex = utils.getInputJsValue("#input-mathjax-config-tex", event);
|
newConfig.tex = utils.getInputJsValue("#input-mathjax-config-tex", event);
|
||||||
newConfig.tex2jax = utils.getInputJsValue("#input-mathjax-config-tex2jax", event);
|
newConfig.tex2jax = utils.getInputJsValue("#input-mathjax-config-tex2jax", event);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*jshint ignore:start */
|
/*jshint ignore:start */
|
||||||
mathJax.onPagedownConfigure = function(editorObject) {
|
mathJax.onPagedownConfigure = function(editorObject) {
|
||||||
t = document.getElementById("preview-contents");
|
preview = document.getElementById("preview-contents");
|
||||||
|
|
||||||
var converter = editorObject.getConverter();
|
var converter = editorObject.getConverter();
|
||||||
converter.hooks.chain("preConversion", p);
|
converter.hooks.chain("preConversion", removeMath);
|
||||||
converter.hooks.chain("postConversion", d);
|
converter.hooks.chain("postConversion", replaceMath);
|
||||||
};
|
};
|
||||||
|
|
||||||
var afterRefreshCallback;
|
var afterRefreshCallback;
|
||||||
mathJax.onAsyncPreview = function(callback) {
|
mathJax.onAsyncPreview = function(callback) {
|
||||||
afterRefreshCallback = callback;
|
afterRefreshCallback = callback;
|
||||||
j();
|
UpdateMJ();
|
||||||
};
|
};
|
||||||
|
|
||||||
// From math.stackexchange.com...
|
// From math.stackexchange.com...
|
||||||
|
|
||||||
function b(a, f, b) {
|
//
|
||||||
var c = k.slice(a, f + 1).join("").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
// The math is in blocks i through j, so
|
||||||
for (h.Browser.isMSIE && (c = c.replace(/(%[^\n]*)\n/g, "$1<br/>\n")); f > a; )
|
// collect it into one block and clear the others.
|
||||||
k[f] = "", f--;
|
// Replace &, <, and > by named entities.
|
||||||
k[a] = "@@" + m.length + "@@";
|
// For IE, put <br> at the ends of comments since IE removes \n.
|
||||||
b && (c = b(c));
|
// Clear the current math positions and store the index of the
|
||||||
m.push(c);
|
// math, then push the math string onto the storage array.
|
||||||
i = o = l = null
|
//
|
||||||
}
|
function processMath(i, j, unescape) {
|
||||||
function p(a) {
|
var block = blocks.slice(i, j + 1).join("")
|
||||||
i = o = l = null;
|
.replace(/&/g, "&")
|
||||||
m = [];
|
.replace(/</g, "<")
|
||||||
var f;
|
.replace(/>/g, ">");
|
||||||
/`/.test(a) ? (a = a.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function(a) {
|
for(HUB.Browser.isMSIE && (block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n")); j > i;)
|
||||||
return a.replace(/\$/g, "~D")
|
blocks[j] = "", j--;
|
||||||
}), f = function(a) {
|
blocks[i] = "@@" + math.length + "@@";
|
||||||
return a.replace(/~([TD])/g,
|
unescape && (block = unescape(block));
|
||||||
function(a, c) {
|
math.push(block);
|
||||||
return {T: "~",D: "$"}[c]
|
start = end = last = null;
|
||||||
})
|
}
|
||||||
}) : f = function(a) {
|
|
||||||
return a
|
|
||||||
};
|
|
||||||
k = r(a.replace(/\r\n?/g, "\n"), u);
|
|
||||||
for (var a = 1, d = k.length; a < d; a += 2) {
|
|
||||||
var c = k[a];
|
|
||||||
"@" === c.charAt(0) ? (k[a] = "@@" + m.length + "@@", m.push(c)) : i ? c === o ? n ? l = a : b(i, a, f) : c.match(/\n.*\n/) ? (l && (a = l, b(i, a, f)), i = o = l = null, n = 0) : "{" === c ? n++ : "}" === c && n && n-- : c === s || "$$" === c ? (i = a, o = c, n = 0) : "begin" === c.substr(1, 5) && (i = a, o = "\\end" + c.substr(6), n = 0)
|
|
||||||
}
|
|
||||||
l && b(i, l, f);
|
|
||||||
return f(k.join(""))
|
|
||||||
}
|
|
||||||
function d(a) {
|
|
||||||
a = a.replace(/@@(\d+)@@/g, function(a, b) {
|
|
||||||
return m[b]
|
|
||||||
});
|
|
||||||
m = null;
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
function e() {
|
|
||||||
q = !1;
|
|
||||||
h.cancelTypeset = !1;
|
|
||||||
h.Queue(["Typeset", h, t])
|
|
||||||
h.Queue(afterRefreshCallback); //benweet
|
|
||||||
}
|
|
||||||
function j() {
|
|
||||||
!q && /*benweet (we need to call our afterRefreshCallback) g &&*/ (q = !0, h.Cancel(), h.Queue(e))
|
|
||||||
}
|
|
||||||
var g = !1, q = !1, t = null, s = "$", k, i, o, l, n, m, h = MathJax.Hub;
|
|
||||||
h.Queue(function() {
|
|
||||||
g = !0;
|
|
||||||
h.processUpdateTime = 50;
|
|
||||||
h.Config({"HTML-CSS": {EqnChunk: 10,EqnChunkFactor: 1},SVG: {EqnChunk: 10,EqnChunkFactor: 1}})
|
|
||||||
});
|
|
||||||
/*benweet
|
|
||||||
Don't hash inline math $...$ (see https://github.com/benweet/stackedit/issues/136)
|
|
||||||
var u = /(\$\$?|\\(?:begin|end)\{[a-z]*\*?\}|\\[\\{}$]|[{}]|(?:\n\s*)+|@@\d+@@)/i, r;
|
|
||||||
*/
|
|
||||||
var u = /(\$\$|\\(?:begin|end)\{[a-z]*\*?\}|\\[\\{}$]|[{}]|(?:\n\s*)+|@@\d+@@)/i, r;
|
|
||||||
r = 3 === "aba".split(/(b)/).length ? function(a, f) {
|
|
||||||
return a.split(f)
|
|
||||||
} : function(a, f) {
|
|
||||||
var b = [], c;
|
|
||||||
if (!f.global) {
|
|
||||||
c = f.toString();
|
|
||||||
var d = "";
|
|
||||||
c = c.replace(/^\/(.*)\/([im]*)$/, function(a, c, b) {
|
|
||||||
d = b;
|
|
||||||
return c
|
|
||||||
});
|
|
||||||
f = RegExp(c, d + "g")
|
|
||||||
}
|
|
||||||
for (var e = f.lastIndex = 0; c = f.exec(a); )
|
|
||||||
b.push(a.substring(e, c.index)), b.push.apply(b, c.slice(1)), e = c.index + c[0].length;
|
|
||||||
b.push(a.substring(e));
|
|
||||||
return b
|
|
||||||
};
|
|
||||||
|
|
||||||
(function() {
|
function removeMath(text) {
|
||||||
var b = MathJax.Hub;
|
start = end = last = null;
|
||||||
if (!b.Cancel) {
|
math = [];
|
||||||
b.cancelTypeset = !1;
|
var unescape;
|
||||||
b.Register.StartupHook("HTML-CSS Jax Config", function() {
|
if(/`/.test(text)) {
|
||||||
var d = MathJax.OutputJax["HTML-CSS"], e = d.Translate;
|
text = text.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function(text) {
|
||||||
d.Augment({Translate: function(j, g) {
|
return text.replace(/\$/g, "~D")
|
||||||
if (b.cancelTypeset || g.cancelled)
|
});
|
||||||
throw Error("MathJax Canceled");
|
unescape = function(text) {
|
||||||
return e.call(d, j, g)
|
return text.replace(/~([TD])/g,
|
||||||
}})
|
function(match, n) {
|
||||||
});
|
return {T: "~", D: "$"}[n]
|
||||||
b.Register.StartupHook("SVG Jax Config", function() {
|
})
|
||||||
var d = MathJax.OutputJax.SVG, e = d.Translate;
|
};
|
||||||
d.Augment({Translate: function(j, g) {
|
} else {
|
||||||
if (b.cancelTypeset || g.cancelled)
|
unescape = function(text) {
|
||||||
throw Error("MathJax Canceled");
|
return text
|
||||||
return e.call(d,
|
};
|
||||||
j, g)
|
}
|
||||||
}})
|
blocks = split(text.replace(/\r\n?/g, "\n"), splitDelimiter);
|
||||||
});
|
for(var i = 1, m = blocks.length; i < m; i += 2) {
|
||||||
b.Register.StartupHook("TeX Jax Config", function() {
|
var block = blocks[i];
|
||||||
var d = MathJax.InputJax.TeX, e = d.Translate;
|
if("@" === block.charAt(0)) {
|
||||||
d.Augment({Translate: function(j, g) {
|
//
|
||||||
if (b.cancelTypeset || g.cancelled)
|
// Things that look like our math markers will get
|
||||||
throw Error("MathJax Canceled");
|
// stored and then retrieved along with the math.
|
||||||
return e.call(d, j, g)
|
//
|
||||||
}})
|
blocks[i] = "@@" + math.length + "@@";
|
||||||
});
|
math.push(block)
|
||||||
var p = b.processError;
|
} else if(start) {
|
||||||
b.processError = function(d, e, j) {
|
//
|
||||||
if ("MathJax Canceled" !== d.message)
|
// If we are in math, look for the end delimiter,
|
||||||
return p.call(b, d, e, j);
|
// but don't go past double line breaks, and
|
||||||
MathJax.Message.Clear(0, 0);
|
// and balance braces within the math.
|
||||||
e.jaxIDs = [];
|
//
|
||||||
e.jax = {};
|
if(end == inline && block.charAt(0) == '\n') {
|
||||||
e.scripts = [];
|
// This should fix #136 by ignoring inline maths that are actually multiline
|
||||||
e.i = e.j = 0;
|
start = end = last = null;
|
||||||
e.cancelled = !0;
|
} else if(block === end) {
|
||||||
return null
|
if(braces) {
|
||||||
};
|
last = i
|
||||||
b.Cancel = function() {
|
} else {
|
||||||
this.cancelTypeset = !0
|
processMath(start, i, unescape)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
})();
|
if(block.match(/\n.*\n/)) {
|
||||||
/*jshint ignore:end */
|
last && (i = last, processMath(start, i, unescape)), start = end = last = null, braces = 0
|
||||||
|
} else {
|
||||||
|
if("{" === block) {
|
||||||
|
braces++
|
||||||
|
} else {
|
||||||
|
"}" === block && braces && braces--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(block === inline || "$$" === block) {
|
||||||
|
start = i;
|
||||||
|
end = block;
|
||||||
|
braces = 0;
|
||||||
|
} else {
|
||||||
|
if("begin" === block.substr(1, 5)) {
|
||||||
|
start = i;
|
||||||
|
end = "\\end" + block.substr(6);
|
||||||
|
braces = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
last && processMath(start, last, unescape);
|
||||||
|
return unescape(blocks.join(""))
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Put back the math strings that were saved,
|
||||||
|
// and clear the math array (no need to keep it around).
|
||||||
|
//
|
||||||
|
function replaceMath(text) {
|
||||||
|
text = text.replace(/@@(\d+)@@/g, function(match, n) {
|
||||||
|
return math[n]
|
||||||
|
});
|
||||||
|
math = null;
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is run to restart MathJax after it has finished
|
||||||
|
// the previous run (that may have been canceled)
|
||||||
|
//
|
||||||
|
function RestartMJ() {
|
||||||
|
pending = false;
|
||||||
|
HUB.cancelTypeset = false;
|
||||||
|
HUB.Queue([
|
||||||
|
"Typeset",
|
||||||
|
HUB,
|
||||||
|
preview
|
||||||
|
]);
|
||||||
|
HUB.Queue(afterRefreshCallback); //benweet
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// When the preview changes, cancel MathJax and restart,
|
||||||
|
// if we haven't done that already.
|
||||||
|
//
|
||||||
|
function UpdateMJ() {
|
||||||
|
if(!pending /*benweet (we need to call our afterRefreshCallback) && ready */) {
|
||||||
|
pending = true;
|
||||||
|
HUB.Cancel();
|
||||||
|
HUB.Queue(RestartMJ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ready = false, pending = false, preview = null, inline = "$", blocks, start, end, last, braces, math, HUB = MathJax.Hub;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Runs after initial typeset
|
||||||
|
//
|
||||||
|
HUB.Queue(function() {
|
||||||
|
ready = true;
|
||||||
|
HUB.processUpdateTime = 50;
|
||||||
|
HUB.Config({"HTML-CSS": {EqnChunk: 10, EqnChunkFactor: 1}, SVG: {EqnChunk: 10, EqnChunkFactor: 1}})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*benweet
|
||||||
|
Don't hash inline math $...$ (see https://github.com/benweet/stackedit/issues/136)
|
||||||
|
var u = /(\$\$?|\\(?:begin|end)\{[a-z]*\*?\}|\\[\\{}$]|[{}]|(?:\n\s*)+|@@\d+@@)/i, r;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// The pattern for math delimiters and special symbols
|
||||||
|
// needed for searching for math in the page.
|
||||||
|
//
|
||||||
|
var splitDelimiter = /(\$\$?|\\(?:begin|end)\{[a-z]*\*?\}|\\[\\{}$]|[{}]|(?:\n\s*)+|@@\d+@@)/i;
|
||||||
|
var split;
|
||||||
|
|
||||||
|
if(3 === "aba".split(/(b)/).length) {
|
||||||
|
split = function(text, delimiter) {
|
||||||
|
return text.split(delimiter)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
split = function(text, delimiter) {
|
||||||
|
var b = [], c;
|
||||||
|
if(!delimiter.global) {
|
||||||
|
c = delimiter.toString();
|
||||||
|
var d = "";
|
||||||
|
c = c.replace(/^\/(.*)\/([im]*)$/, function(a, c, b) {
|
||||||
|
d = b;
|
||||||
|
return c
|
||||||
|
});
|
||||||
|
delimiter = RegExp(c, d + "g")
|
||||||
|
}
|
||||||
|
for(var e = delimiter.lastIndex = 0; c = delimiter.exec(text);) {
|
||||||
|
b.push(text.substring(e, c.index));
|
||||||
|
b.push.apply(b, c.slice(1));
|
||||||
|
e = c.index + c[0].length;
|
||||||
|
}
|
||||||
|
b.push(text.substring(e));
|
||||||
|
return b
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var HUB = MathJax.Hub;
|
||||||
|
if(!HUB.Cancel) {
|
||||||
|
HUB.cancelTypeset = !1;
|
||||||
|
HUB.Register.StartupHook("HTML-CSS Jax Config", function() {
|
||||||
|
var HTMLCSS = MathJax.OutputJax["HTML-CSS"], TRANSLATE = HTMLCSS.Translate;
|
||||||
|
HTMLCSS.Augment({Translate: function(script, state) {
|
||||||
|
if(HUB.cancelTypeset || state.cancelled)
|
||||||
|
throw Error("MathJax Canceled");
|
||||||
|
return TRANSLATE.call(HTMLCSS, script, state)
|
||||||
|
}})
|
||||||
|
});
|
||||||
|
HUB.Register.StartupHook("SVG Jax Config", function() {
|
||||||
|
var SVG = MathJax.OutputJax.SVG, TRANSLATE = SVG.Translate;
|
||||||
|
SVG.Augment({Translate: function(script, state) {
|
||||||
|
if(HUB.cancelTypeset || state.cancelled)
|
||||||
|
throw Error("MathJax Canceled");
|
||||||
|
return TRANSLATE.call(SVG,
|
||||||
|
script, state)
|
||||||
|
}})
|
||||||
|
});
|
||||||
|
HUB.Register.StartupHook("TeX Jax Config", function() {
|
||||||
|
var TEX = MathJax.InputJax.TeX, TRANSLATE = TEX.Translate;
|
||||||
|
TEX.Augment({Translate: function(script, state) {
|
||||||
|
if(HUB.cancelTypeset || state.cancelled)
|
||||||
|
throw Error("MathJax Canceled");
|
||||||
|
return TRANSLATE.call(TEX, script, state)
|
||||||
|
}})
|
||||||
|
});
|
||||||
|
var PROCESSERROR = HUB.processError;
|
||||||
|
HUB.processError = function(error, state, type) {
|
||||||
|
if("MathJax Canceled" !== error.message)
|
||||||
|
return PROCESSERROR.call(HUB, error, state, type);
|
||||||
|
MathJax.Message.Clear(0, 0);
|
||||||
|
state.jaxIDs = [];
|
||||||
|
state.jax = {};
|
||||||
|
state.scripts = [];
|
||||||
|
state.i = state.j = 0;
|
||||||
|
state.cancelled = true;
|
||||||
|
return null
|
||||||
|
};
|
||||||
|
HUB.Cancel = function() {
|
||||||
|
this.cancelTypeset = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
/*jshint ignore:end */
|
||||||
|
|
||||||
return mathJax;
|
return mathJax;
|
||||||
});
|
});
|
@ -36,7 +36,7 @@
|
|||||||
<a target="_blank" href="https://twitter.com/benweet">Benoit Schweblin</a><br />
|
<a target="_blank" href="https://twitter.com/benweet">Benoit Schweblin</a><br />
|
||||||
Pete Eigel (contributor)<br />
|
Pete Eigel (contributor)<br />
|
||||||
wiibaa (contributor)<br />
|
wiibaa (contributor)<br />
|
||||||
<a target="_blank" href="http://www.hugwebdesign.com/">Daniel Hug (contributor)</a><br />
|
<a target="_blank" href="http://www.hugwebdesign.com/">Daniel Hug</a> (contributor)<br />
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<dl>
|
<dl>
|
||||||
@ -60,8 +60,8 @@
|
|||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<p>
|
<p>
|
||||||
StackEdit <%= version %> – <a target="_blank" href="privacy_policy.html">Privacy Policy</a><br /> Copyright 2013 <a
|
StackEdit <%= version %> – <a target="_blank" href="privacy_policy.html">Privacy Policy</a><br /> Copyright 2013-2014 <a
|
||||||
target="_blank" href="http://www.benoitschweblin.com">Benoit
|
target="_blank" href="https://twitter.com/benweet">Benoit
|
||||||
Schweblin</a><br /> Licensed under an <a target="_blank"
|
Schweblin</a><br /> Licensed under an <a target="_blank"
|
||||||
href="http://www.apache.org/licenses/LICENSE-2.0">Apache
|
href="http://www.apache.org/licenses/LICENSE-2.0">Apache
|
||||||
License</a>
|
License</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user