1
1
/**
2
- * markjax v1.0.5
2
+ * markjax v1.1.0
3
3
* Copyright CodeAssign
4
4
* @link http://markjax.codeassign.com/
5
5
* @license Apache-2.0
6
6
*/
7
7
/**
8
- * markjax v1.0.5
8
+ * markjax v1.1.0
9
9
* Copyright CodeAssign
10
10
* @link http://markjax.codeassign.com/
11
11
* @license Apache-2.0
12
12
*/
13
13
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markjax = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
14
14
(function () {
15
- var katex = document.createElement("link");
16
- katex.rel = "stylesheet";
17
- katex.href = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css";
18
- document.getElementsByTagName("head")[0].appendChild(katex);
19
-
20
- var highlight = document.createElement("link");
21
- highlight.rel = "stylesheet";
22
- highlight.href = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css";
23
- document.getElementsByTagName("head")[0].appendChild(highlight);
15
+ var head = document.getElementsByTagName("head")[0];
16
+
17
+ var mathjaxConfig = document.createElement("script");
18
+ mathjaxConfig.type = "text/x-mathjax-config";
19
+ mathjaxConfig[(window.opera ? "innerHTML" : "text")] =
20
+ "MathJax.Hub.Config({" +
21
+ " showProcessingMessages: false," +
22
+ " messageStyle: \"none\"," +
23
+ " skipStartupTypeset: false," +
24
+ " tex2jax: {" +
25
+ " inlineMath: [['$','$']]," +
26
+ " displayMath: [['$$', '$$']]," +
27
+ " ignoreClass: \".*\"," +
28
+ " processClass: \"mathjax\"" +
29
+ " }," +
30
+ " TeX: {" +
31
+ " equationNumbers: {" +
32
+ " autoNumber: \"AMS\"" +
33
+ " }" +
34
+ " }" +
35
+ "});";
36
+ head.appendChild(mathjaxConfig);
37
+
38
+ var mathjax = document.createElement("script");
39
+ mathjax.type = "text/javascript";
40
+ mathjax.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
41
+ head.appendChild(mathjax);
42
+
43
+ var katex = document.createElement("link");
44
+ katex.rel = "stylesheet";
45
+ katex.href = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css";
46
+ head.appendChild(katex);
47
+
48
+ var highlight = document.createElement("link");
49
+ highlight.rel = "stylesheet";
50
+ highlight.href = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css";
51
+ head.appendChild(highlight);
24
52
})();
25
53
26
54
var marked = require("marked");
27
55
var katex = require("katex");
28
- var highlight = require("highlight.js")
56
+ var highlight = require("highlight.js");
57
+ var memoMath = {};
29
58
30
59
function EscapeTex(text) {
31
60
var re = /(`+)(\s*)([\s\S]*?[^`])(\s*)(\1)(?!`)/g;
@@ -163,6 +192,10 @@ function splitWithDelimiters(text, delimiters) {
163
192
return data;
164
193
}
165
194
195
+ function remember(key, element) {
196
+ memoMath[key] = element.innerHTML;
197
+ }
198
+
166
199
function renderMathInText(text, delimiters) {
167
200
var data = splitWithDelimiters(text, delimiters);
168
201
@@ -182,15 +215,26 @@ function renderMathInText(text, delimiters) {
182
215
if (!(e instanceof katex.ParseError)) {
183
216
throw e;
184
217
}
185
- console.error(
186
- "KaTeX auto-render: Failed to parse `" + data[i].data +
187
- "` with ",
188
- e
189
- );
190
- fragment.appendChild(document.createTextNode(data[i].rawData));
191
- continue;
218
+
219
+ span.innerHTML = data[i].rawData;
220
+ span.classList.add("mathjax");
221
+
222
+ var style = data[i].display ? "$$" : "$";
223
+ var trimmedData = data[i].data.trim();
224
+ if (trimmedData[trimmedData.length - 1] === '\\') {
225
+ trimmedData += " ";
226
+ }
227
+ var rawData = style + trimmedData + style;
228
+
229
+ if (memoMath[rawData] === undefined) {
230
+ MathJax.Hub.Queue(["Typeset", MathJax.Hub, span]);
231
+ MathJax.Hub.Queue([remember, rawData, span]);
232
+ } else {
233
+ span.innerHTML = memoMath[rawData];
234
+ }
235
+ } finally {
236
+ fragment.appendChild(span);
192
237
}
193
- fragment.appendChild(span);
194
238
}
195
239
}
196
240
@@ -231,7 +275,7 @@ function renderMathInElement(elem) {
231
275
renderElem(elem, defaultOptions.delimiters, defaultOptions.ignoredTags);
232
276
}
233
277
234
- function markjax(text, markedOptions = {}) {
278
+ function markjax(text, element, markedOptions = {}) {
235
279
if (markedOptions["breaks"] === undefined) {
236
280
markedOptions["breaks"] = true;
237
281
}
@@ -265,8 +309,8 @@ function markjax(text, markedOptions = {}) {
265
309
}
266
310
}
267
311
268
- renderMathInElement( node);
269
- return node.innerHTML ;
312
+ element.innerHTML = node.innerHTML;
313
+ renderMathInElement(element) ;
270
314
}
271
315
272
316
module.exports = markjax;
0 commit comments