@cnblogs/markdown-it-presets 1.9.5 → 1.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/index.cjs +8 -5257
- package/dist/commonjs/math/index.cjs +2 -3
- package/dist/commonjs/presets/index.cjs +6 -5254
- package/dist/es2015/index.mjs +893 -3
- package/dist/es2015/math/index.mjs +210 -3
- package/dist/es2015/presets/index.mjs +681 -100
- package/dist/umd/mathRenderer.js +1 -1
- package/package.json +7 -7
- package/dist/es2015/index.mjs.map +0 -1
- package/dist/es2015/math/factory.mjs +0 -13
- package/dist/es2015/math/factory.mjs.map +0 -1
- package/dist/es2015/math/impl.mjs +0 -161
- package/dist/es2015/math/impl.mjs.map +0 -1
- package/dist/es2015/math/index.mjs.map +0 -1
- package/dist/es2015/math/model.mjs +0 -20
- package/dist/es2015/math/model.mjs.map +0 -1
- package/dist/es2015/presets/index.mjs.map +0 -1
- package/dist/es2015/presets/option.mjs +0 -27
- package/dist/es2015/presets/option.mjs.map +0 -1
- package/dist/es2015/presets/plugins/highlight-code-lines.plugin.mjs +0 -49
- package/dist/es2015/presets/plugins/highlight-code-lines.plugin.mjs.map +0 -1
- package/dist/es2015/presets/plugins/html-filter.plugin.mjs +0 -43
- package/dist/es2015/presets/plugins/html-filter.plugin.mjs.map +0 -1
- package/dist/es2015/presets/plugins/meta.mjs +0 -36
- package/dist/es2015/presets/plugins/meta.mjs.map +0 -1
- package/dist/es2015/presets/plugins/multiline-blockquote/multiline-blockquote.plugin.mjs +0 -11
- package/dist/es2015/presets/plugins/multiline-blockquote/multiline-blockquote.plugin.mjs.map +0 -1
- package/dist/es2015/presets/plugins/multiline-blockquote/multiline-blockquote.rule.mjs +0 -40
- package/dist/es2015/presets/plugins/multiline-blockquote/multiline-blockquote.rule.mjs.map +0 -1
- package/dist/es2015/presets/plugins/simple-math.plugin.mjs +0 -147
- package/dist/es2015/presets/plugins/simple-math.plugin.mjs.map +0 -1
- package/dist/es2015/presets/plugins/simple-mermaid.plugin.mjs +0 -17
- package/dist/es2015/presets/plugins/simple-mermaid.plugin.mjs.map +0 -1
- package/dist/es2015/presets/plugins/toc/index.mjs +0 -184
- package/dist/es2015/presets/plugins/toc/index.mjs.map +0 -1
- package/dist/es2015/presets/plugins/toc/slugify.mjs +0 -5
- package/dist/es2015/presets/plugins/toc/slugify.mjs.map +0 -1
- package/dist/es2015/presets/plugins/toc/toc-item.mjs +0 -2
- package/dist/es2015/presets/plugins/toc/toc-item.mjs.map +0 -1
- package/dist/es2015/presets/plugins/toc/toc-option.mjs +0 -15
- package/dist/es2015/presets/plugins/toc/toc-option.mjs.map +0 -1
- package/dist/es2015/presets/plugins/unique-custom-id.mjs +0 -27
- package/dist/es2015/presets/plugins/unique-custom-id.mjs.map +0 -1
package/dist/es2015/index.mjs
CHANGED
|
@@ -1,3 +1,893 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/presets/index.ts
|
|
19
|
+
import MarkdownIt from "markdown-it";
|
|
20
|
+
import hljs from "highlight.js";
|
|
21
|
+
import MarkdownItContainer from "markdown-it-container";
|
|
22
|
+
import MdAbbr from "markdown-it-abbr";
|
|
23
|
+
import MdDefList from "markdown-it-deflist";
|
|
24
|
+
import MdEmoji from "markdown-it-emoji";
|
|
25
|
+
import MdFootnote from "markdown-it-footnote";
|
|
26
|
+
import MdMark from "markdown-it-mark";
|
|
27
|
+
import MdSub from "markdown-it-sub";
|
|
28
|
+
import MdSup from "markdown-it-sup";
|
|
29
|
+
import MdAnchor from "markdown-it-anchor";
|
|
30
|
+
import LazyHeaders from "markdown-it-lazy-headers";
|
|
31
|
+
import InlineTokensIterator from "markdown-it-for-inline";
|
|
32
|
+
import MarkdownTaskLists from "markdown-it-task-lists";
|
|
33
|
+
import MarkdownItAttrs from "markdown-it-attrs";
|
|
34
|
+
|
|
35
|
+
// src/presets/plugins/simple-math.plugin.ts
|
|
36
|
+
function isValidDelimiter(state, pos) {
|
|
37
|
+
let max = state.posMax;
|
|
38
|
+
let canOpen = true;
|
|
39
|
+
let canClose = true;
|
|
40
|
+
let prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
41
|
+
let nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
42
|
+
if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
|
|
43
|
+
canClose = false;
|
|
44
|
+
}
|
|
45
|
+
if (nextChar === 32 || nextChar === 9) {
|
|
46
|
+
canOpen = false;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
canOpen,
|
|
50
|
+
canClose
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var mathInTable = (state) => {
|
|
54
|
+
const { src } = state;
|
|
55
|
+
const regex = /(\|.*\|)\n(\|\s*?-+:?\s*?)+\|\n(\|.*\|\n?)*?((\|.*?\$+.*\n?)+)/g;
|
|
56
|
+
const inlineMathRegex = /\$(.*?)\$/g;
|
|
57
|
+
state.src = src.replace(
|
|
58
|
+
regex,
|
|
59
|
+
(match, sub1, sub2, sub3, sub4) => match.replace(
|
|
60
|
+
sub4,
|
|
61
|
+
sub4.replace(inlineMathRegex, (match2, sub) => `$${sub.replace(/\\*?\|/g, "\\|")}$$`)
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
var mathInline = (state, silent) => {
|
|
67
|
+
let start, match, token, res, pos;
|
|
68
|
+
if (state.src[state.pos] !== "$") {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
res = isValidDelimiter(state, state.pos);
|
|
72
|
+
if (!res.canOpen) {
|
|
73
|
+
if (!silent) {
|
|
74
|
+
state.pending += "$";
|
|
75
|
+
}
|
|
76
|
+
state.pos += 1;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
start = state.pos + 1;
|
|
80
|
+
match = start;
|
|
81
|
+
while ((match = state.src.indexOf("$", match)) !== -1) {
|
|
82
|
+
pos = match - 1;
|
|
83
|
+
while (state.src[pos] === "\\") {
|
|
84
|
+
pos -= 1;
|
|
85
|
+
}
|
|
86
|
+
if ((match - pos) % 2 == 1) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
match += 1;
|
|
90
|
+
}
|
|
91
|
+
if (match === -1) {
|
|
92
|
+
if (!silent) {
|
|
93
|
+
state.pending += "$";
|
|
94
|
+
}
|
|
95
|
+
state.pos = start;
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (match - start === 0) {
|
|
99
|
+
if (!silent) {
|
|
100
|
+
state.pending += "$$";
|
|
101
|
+
}
|
|
102
|
+
state.pos = start + 1;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
res = isValidDelimiter(state, match);
|
|
106
|
+
if (!res.canClose) {
|
|
107
|
+
if (!silent) {
|
|
108
|
+
state.pending += "$";
|
|
109
|
+
}
|
|
110
|
+
state.pos = start;
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (!silent) {
|
|
114
|
+
token = state.push("math_inline", "math", 0);
|
|
115
|
+
token.markup = "$";
|
|
116
|
+
token.content = state.src.slice(start, match);
|
|
117
|
+
}
|
|
118
|
+
state.pos = match + 1;
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
121
|
+
var mathBlock = (state, start, end, silent) => {
|
|
122
|
+
let lastLine;
|
|
123
|
+
let next;
|
|
124
|
+
let lastPos;
|
|
125
|
+
let found = false;
|
|
126
|
+
let token;
|
|
127
|
+
let pos = state.bMarks[start] + state.tShift[start];
|
|
128
|
+
let max = state.eMarks[start];
|
|
129
|
+
if (pos + 2 > max) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (state.src[pos] !== "$" || state.src[pos + 1] !== "$") {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
pos += 2;
|
|
136
|
+
if (silent) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
let firstLine = state.src.slice(pos, max);
|
|
140
|
+
if (firstLine.trim().slice(-2) === "$$") {
|
|
141
|
+
firstLine = firstLine.trim().slice(0, -2);
|
|
142
|
+
found = true;
|
|
143
|
+
}
|
|
144
|
+
for (next = start; !found; ) {
|
|
145
|
+
next++;
|
|
146
|
+
if (next >= end) {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
pos = state.bMarks[next] + state.tShift[next];
|
|
150
|
+
max = state.eMarks[next];
|
|
151
|
+
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
155
|
+
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
156
|
+
lastLine = state.src.slice(pos, lastPos);
|
|
157
|
+
found = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
state.line = next + 1;
|
|
161
|
+
token = state.push("math_block", "math", 0);
|
|
162
|
+
token.block = true;
|
|
163
|
+
token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
|
|
164
|
+
token.map = [start, state.line];
|
|
165
|
+
token.markup = "$$";
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
168
|
+
var simpleMathPlugin = (md) => {
|
|
169
|
+
md.core.ruler.before("block", "math_in_table", mathInTable);
|
|
170
|
+
md.inline.ruler.after("escape", "math_inline", mathInline);
|
|
171
|
+
md.block.ruler.after("blockquote", "math_block", mathBlock, {
|
|
172
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
173
|
+
});
|
|
174
|
+
const simpleInlineRenderer = (tokens, idx) => {
|
|
175
|
+
return '<span class="math inline">\\(' + md.utils.escapeHtml(tokens[idx].content) + "\\)</span>";
|
|
176
|
+
};
|
|
177
|
+
const simpleBlockRenderer = (tokens, idx) => {
|
|
178
|
+
return '<p><div class="math display">\\[' + md.utils.escapeHtml(tokens[idx].content) + "\\]</div></p>";
|
|
179
|
+
};
|
|
180
|
+
md.renderer.rules.math_inline = simpleInlineRenderer;
|
|
181
|
+
md.renderer.rules.math_block = simpleBlockRenderer;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/presets/plugins/simple-mermaid.plugin.ts
|
|
185
|
+
function diagramPlugin(md, options) {
|
|
186
|
+
function getLangName(info) {
|
|
187
|
+
return info.split(/\s+/g)[0];
|
|
188
|
+
}
|
|
189
|
+
let defaultFenceRenderer = md.renderer.rules.fence;
|
|
190
|
+
function customFenceRenderer(tokens, idx, options2, env, slf) {
|
|
191
|
+
let token = tokens[idx];
|
|
192
|
+
let info = token.info.trim();
|
|
193
|
+
let langName = info ? getLangName(info) : "";
|
|
194
|
+
if (langName.toLowerCase() === "mermaid") {
|
|
195
|
+
return '<div class="mermaid">' + md.utils.escapeHtml(token.content) + "</div>";
|
|
196
|
+
}
|
|
197
|
+
return defaultFenceRenderer(tokens, idx, options2, env, slf);
|
|
198
|
+
}
|
|
199
|
+
md.renderer.rules.fence = customFenceRenderer;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/presets/plugins/html-filter.plugin.ts
|
|
203
|
+
var tagFilterRules = {
|
|
204
|
+
title: { rule: "escape" },
|
|
205
|
+
head: { rule: "escape" },
|
|
206
|
+
body: { rule: "escape" },
|
|
207
|
+
img: {
|
|
208
|
+
rule: "filterAttributes",
|
|
209
|
+
disabledAttributes: ["onerror"]
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var HtmlFilterPlugin = (md) => {
|
|
213
|
+
const defaultHtmlBlock = md.renderer.rules.html_block;
|
|
214
|
+
md.renderer.rules.html_block = (tokens, idx, options, env, self) => {
|
|
215
|
+
const token = tokens[idx];
|
|
216
|
+
if (token.type === "html_block" && !token.tag) {
|
|
217
|
+
let { content } = token;
|
|
218
|
+
for (let tagName in tagFilterRules) {
|
|
219
|
+
const rule = tagFilterRules[tagName];
|
|
220
|
+
const { rule: handleStrategy, disabledAttributes } = rule;
|
|
221
|
+
if (handleStrategy === "escape") {
|
|
222
|
+
const start = `<${tagName}>`;
|
|
223
|
+
const end = `</${tagName}>`;
|
|
224
|
+
const matchStart = content.replace(new RegExp("\n", "g"), "").startsWith(start);
|
|
225
|
+
const matchEnd = content.replace(new RegExp("\n", "g"), "").endsWith(end);
|
|
226
|
+
if (matchStart || matchEnd) {
|
|
227
|
+
content = md.utils.escapeHtml(content);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
} else if (handleStrategy === "filterAttributes" && disabledAttributes != null && disabledAttributes.length > 0) {
|
|
231
|
+
for (let attribute of disabledAttributes) {
|
|
232
|
+
content = content.replace(
|
|
233
|
+
new RegExp(`(<${tagName}.*? +)(${attribute}=)(.*?>)`, "ig"),
|
|
234
|
+
(match, p1, p2, p3) => p1 + "data-" + p2 + p3
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (content !== token.content)
|
|
240
|
+
return content;
|
|
241
|
+
}
|
|
242
|
+
return defaultHtmlBlock(tokens, idx, options, env, self);
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/presets/plugins/multiline-blockquote/multiline-blockquote.rule.ts
|
|
247
|
+
var MultilineBlockquoteRule = (state, startLine, endLine) => {
|
|
248
|
+
let nextLine, token;
|
|
249
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
250
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
let marker = state.src.charCodeAt(pos);
|
|
254
|
+
if (marker !== 62) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
let markerLength = state.skipChars(pos, marker) - pos;
|
|
258
|
+
if (markerLength !== 3)
|
|
259
|
+
return false;
|
|
260
|
+
if (state.src.charCodeAt(state.skipChars(
|
|
261
|
+
pos + markerLength,
|
|
262
|
+
32
|
|
263
|
+
/* ' ' */
|
|
264
|
+
)) !== 10) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
nextLine = startLine + 1;
|
|
268
|
+
while (nextLine < endLine) {
|
|
269
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
270
|
+
marker = state.src.charCodeAt(pos);
|
|
271
|
+
if (marker === 62 && (markerLength = state.skipChars(pos, marker) - pos) === 3) {
|
|
272
|
+
pos = state.skipChars(pos + markerLength, 32);
|
|
273
|
+
if (pos >= state.src.length || state.src.charCodeAt(pos) === 10)
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
nextLine++;
|
|
277
|
+
}
|
|
278
|
+
if (nextLine > endLine) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
token = state.push("multiline_blockquote_open", "blockquote", 1);
|
|
282
|
+
token.markup = ">>>";
|
|
283
|
+
token.map = [startLine, 0];
|
|
284
|
+
state.md.block.tokenize(state, startLine + 1, nextLine);
|
|
285
|
+
token = state.push("multiline_blockquote_close", "blockquote", -1);
|
|
286
|
+
token.map = [nextLine, 0];
|
|
287
|
+
state.line = nextLine + 1;
|
|
288
|
+
return true;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// src/presets/plugins/multiline-blockquote/multiline-blockquote.plugin.ts
|
|
292
|
+
var MultilineBlockquotePlugin = (md, options) => {
|
|
293
|
+
options != null ? options : options = {};
|
|
294
|
+
md.block.ruler.before("blockquote", "multiline_blockquote", (...args) => {
|
|
295
|
+
if (options.enable != null && !options.enable(md))
|
|
296
|
+
return false;
|
|
297
|
+
return MultilineBlockquoteRule.apply(void 0, args);
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// src/presets/option.ts
|
|
302
|
+
import GithubSlugger from "github-slugger";
|
|
303
|
+
var defaultTaskListsOption = {
|
|
304
|
+
enable: true,
|
|
305
|
+
label: true,
|
|
306
|
+
labelAfter: true
|
|
307
|
+
};
|
|
308
|
+
var defaultMarkdownItOption = {
|
|
309
|
+
codeHighlight: false,
|
|
310
|
+
math: false,
|
|
311
|
+
disableRules: [],
|
|
312
|
+
html: false,
|
|
313
|
+
taskListsOption: defaultTaskListsOption
|
|
314
|
+
};
|
|
315
|
+
var defaultLinkifyOptions = {
|
|
316
|
+
fuzzyEmail: false,
|
|
317
|
+
fuzzyLink: false,
|
|
318
|
+
fuzzyLinkUseHttps: true
|
|
319
|
+
};
|
|
320
|
+
var anchorOption = {
|
|
321
|
+
level: 1,
|
|
322
|
+
slugify(str) {
|
|
323
|
+
const result = new GithubSlugger().slug(str);
|
|
324
|
+
return result === "" ? "_" : result;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/presets/plugins/toc/slugify.ts
|
|
329
|
+
var slugify = function(s) {
|
|
330
|
+
return encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, "-"));
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// src/presets/plugins/toc/toc-option.ts
|
|
334
|
+
var defaultTocOption = {
|
|
335
|
+
includeLevel: [1, 2, 3, 4, 5, 6],
|
|
336
|
+
containerClass: "toc",
|
|
337
|
+
slugify,
|
|
338
|
+
markerPattern: /\[TOC]/im,
|
|
339
|
+
listType: "ul",
|
|
340
|
+
format: (content) => content.replace(/<\/?a.*?>/g, ""),
|
|
341
|
+
forceFullToc: false,
|
|
342
|
+
containerHeaderHtml: `<div class="toc-container-header">\u76EE\u5F55</div>`,
|
|
343
|
+
containerFooterHtml: void 0,
|
|
344
|
+
transformLink: void 0
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/presets/plugins/toc/index.ts
|
|
348
|
+
var defaults = defaultTocOption;
|
|
349
|
+
var findHeadlineElements = (levels, tokens, options, md, env) => {
|
|
350
|
+
const headings = [];
|
|
351
|
+
let currentHeading = null;
|
|
352
|
+
tokens.forEach((token) => {
|
|
353
|
+
if (token.type === "heading_open") {
|
|
354
|
+
const id = findExistingIdAttr(token);
|
|
355
|
+
const level = parseInt(token.tag.toLowerCase().replace("h", ""), 10);
|
|
356
|
+
if (levels.indexOf(level) >= 0) {
|
|
357
|
+
currentHeading = {
|
|
358
|
+
level,
|
|
359
|
+
textContent: null,
|
|
360
|
+
anchor: id || null,
|
|
361
|
+
markdownContent: null
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
} else if (currentHeading && token.type === "inline") {
|
|
365
|
+
const textContent = token.children.filter((childToken) => childToken.type === "text" || childToken.type === "code_inline").reduce((acc, t) => acc + t.content, "");
|
|
366
|
+
currentHeading.textContent = textContent;
|
|
367
|
+
currentHeading.markdownContent = md.renderer.renderInline(token.children, options, env);
|
|
368
|
+
if (!currentHeading.anchor) {
|
|
369
|
+
currentHeading.anchor = options.slugify(textContent, token.content);
|
|
370
|
+
}
|
|
371
|
+
} else if (token.type === "heading_close") {
|
|
372
|
+
if (currentHeading) {
|
|
373
|
+
headings.push(currentHeading);
|
|
374
|
+
}
|
|
375
|
+
currentHeading = null;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
return headings;
|
|
379
|
+
};
|
|
380
|
+
var findExistingIdAttr = (token) => {
|
|
381
|
+
if (token && token.attrs && token.attrs.length > 0) {
|
|
382
|
+
const idAttr = token.attrs.find((attr) => {
|
|
383
|
+
if (Array.isArray(attr) && attr.length >= 2) {
|
|
384
|
+
return attr[0] === "id";
|
|
385
|
+
}
|
|
386
|
+
return false;
|
|
387
|
+
});
|
|
388
|
+
if (idAttr && Array.isArray(idAttr) && idAttr.length >= 2) {
|
|
389
|
+
const [, val] = idAttr;
|
|
390
|
+
return val;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
394
|
+
};
|
|
395
|
+
function getMinLevel(headlineItems) {
|
|
396
|
+
return Math.min(...headlineItems.map((item) => item.level));
|
|
397
|
+
}
|
|
398
|
+
var addListItem = (level, text, anchor, rootNode) => {
|
|
399
|
+
const listItem = {
|
|
400
|
+
level,
|
|
401
|
+
text,
|
|
402
|
+
anchor,
|
|
403
|
+
children: [],
|
|
404
|
+
parent: rootNode
|
|
405
|
+
};
|
|
406
|
+
rootNode.children.push(listItem);
|
|
407
|
+
return listItem;
|
|
408
|
+
};
|
|
409
|
+
var flatHeadlineItemsToNestedTree = (headlineItems) => {
|
|
410
|
+
const toc = {
|
|
411
|
+
level: getMinLevel(headlineItems) - 1,
|
|
412
|
+
anchor: null,
|
|
413
|
+
text: null,
|
|
414
|
+
children: [],
|
|
415
|
+
parent: null
|
|
416
|
+
};
|
|
417
|
+
let currentRootNode = toc;
|
|
418
|
+
let prevListItem = currentRootNode;
|
|
419
|
+
headlineItems.forEach((headlineItem) => {
|
|
420
|
+
if (headlineItem.level > prevListItem.level) {
|
|
421
|
+
Array.from({ length: headlineItem.level - prevListItem.level }).forEach((_) => {
|
|
422
|
+
currentRootNode = prevListItem;
|
|
423
|
+
prevListItem = addListItem(headlineItem.level, null, null, currentRootNode);
|
|
424
|
+
});
|
|
425
|
+
prevListItem.text = headlineItem.markdownContent;
|
|
426
|
+
prevListItem.anchor = headlineItem.anchor;
|
|
427
|
+
} else if (headlineItem.level === prevListItem.level) {
|
|
428
|
+
prevListItem = addListItem(
|
|
429
|
+
headlineItem.level,
|
|
430
|
+
headlineItem.markdownContent,
|
|
431
|
+
headlineItem.anchor,
|
|
432
|
+
currentRootNode
|
|
433
|
+
);
|
|
434
|
+
} else if (headlineItem.level < prevListItem.level) {
|
|
435
|
+
for (let i = 0; i < prevListItem.level - headlineItem.level; i++) {
|
|
436
|
+
currentRootNode = currentRootNode.parent;
|
|
437
|
+
}
|
|
438
|
+
prevListItem = addListItem(
|
|
439
|
+
headlineItem.level,
|
|
440
|
+
headlineItem.markdownContent,
|
|
441
|
+
headlineItem.anchor,
|
|
442
|
+
currentRootNode
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
return toc;
|
|
447
|
+
};
|
|
448
|
+
var tocItemToHtml = (tocItem, options, md) => {
|
|
449
|
+
return "<" + options.listType + ">" + tocItem.children.map((childItem) => {
|
|
450
|
+
let li = "<li>";
|
|
451
|
+
let anchor = childItem.anchor;
|
|
452
|
+
if (options && options.transformLink) {
|
|
453
|
+
anchor = options.transformLink(anchor);
|
|
454
|
+
}
|
|
455
|
+
let text = childItem.text ? options.format(childItem.text, md, anchor) : null;
|
|
456
|
+
li += anchor ? `<a href="#${anchor}">${text}</a>` : text || "";
|
|
457
|
+
return li + (childItem.children.length > 0 ? tocItemToHtml(childItem, options, md) : "") + "</li>";
|
|
458
|
+
}).join("") + "</" + options.listType + ">";
|
|
459
|
+
};
|
|
460
|
+
var plugin = (md, o) => {
|
|
461
|
+
const options = Object.assign({}, defaults, o);
|
|
462
|
+
const tocRegexp = options.markerPattern;
|
|
463
|
+
let gState;
|
|
464
|
+
const toc = (state, silent) => {
|
|
465
|
+
let token;
|
|
466
|
+
let match;
|
|
467
|
+
if (state.src.charCodeAt(state.pos) !== 91) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
if (silent) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
match = tocRegexp.exec(state.src.substr(state.pos));
|
|
474
|
+
match = !match ? [] : match.filter(function(m) {
|
|
475
|
+
return m;
|
|
476
|
+
});
|
|
477
|
+
if (match.length < 1) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
token = state.push("toc_open", "toc", 1);
|
|
481
|
+
token.markup = "[[toc]]";
|
|
482
|
+
token = state.push("toc_body", "", 0);
|
|
483
|
+
token = state.push("toc_close", "toc", -1);
|
|
484
|
+
const newline = state.src.indexOf("\n", state.pos);
|
|
485
|
+
if (newline !== -1) {
|
|
486
|
+
state.pos = newline;
|
|
487
|
+
} else {
|
|
488
|
+
state.pos = state.pos + state.posMax + 1;
|
|
489
|
+
}
|
|
490
|
+
return true;
|
|
491
|
+
};
|
|
492
|
+
md.renderer.rules.toc_open = (tokens, index) => {
|
|
493
|
+
let tocOpenHtml = '<div class="' + options.containerClass + '">';
|
|
494
|
+
if (options.containerHeaderHtml) {
|
|
495
|
+
tocOpenHtml += options.containerHeaderHtml;
|
|
496
|
+
}
|
|
497
|
+
return tocOpenHtml;
|
|
498
|
+
};
|
|
499
|
+
md.renderer.rules.toc_close = (tokens, index) => {
|
|
500
|
+
let tocFooterHtml = "";
|
|
501
|
+
if (options.containerFooterHtml) {
|
|
502
|
+
tocFooterHtml = options.containerFooterHtml;
|
|
503
|
+
}
|
|
504
|
+
return tocFooterHtml + "</div>";
|
|
505
|
+
};
|
|
506
|
+
md.renderer.rules.toc_body = (tokens, index, opt, env) => {
|
|
507
|
+
if (options.forceFullToc) {
|
|
508
|
+
throw "forceFullToc was removed in version 0.5.0. For more information, see https://github.com/Oktavilla/markdown-it-table-of-contents/pull/41";
|
|
509
|
+
} else {
|
|
510
|
+
const headlineItems = findHeadlineElements(options.includeLevel, gState.tokens, options, md, env);
|
|
511
|
+
const toc2 = flatHeadlineItemsToNestedTree(headlineItems);
|
|
512
|
+
return tocItemToHtml(toc2, options, md);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
md.core.ruler.push("grab_state", (state) => {
|
|
516
|
+
gState = state;
|
|
517
|
+
return true;
|
|
518
|
+
});
|
|
519
|
+
md.inline.ruler.after("emphasis", "toc", toc);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/presets/plugins/highlight-code-lines.plugin.ts
|
|
523
|
+
var LineNumbersRegex = /{([\d,\s-]+)}/;
|
|
524
|
+
var LineNumberAttrRegex = /^([\d,\s-]+)/;
|
|
525
|
+
var highlightCodeLines = (md, { enable } = {}) => {
|
|
526
|
+
const fence = md.renderer.rules.fence;
|
|
527
|
+
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
|
528
|
+
const token = tokens[idx];
|
|
529
|
+
if (enable != null && !enable(md) || token.attrs == null || token.attrs.some(([attr]) => LineNumberAttrRegex.test(attr)) === false) {
|
|
530
|
+
return fence(tokens, idx, options, env, self);
|
|
531
|
+
}
|
|
532
|
+
let highlightedLines = [];
|
|
533
|
+
try {
|
|
534
|
+
highlightedLines = Array.from(
|
|
535
|
+
new Set(
|
|
536
|
+
token.attrs.map(([attr]) => attr.split(",").map((x) => x.trim())).flat().filter((attr) => attr != null && attr.length > 0 && LineNumberAttrRegex.test(attr)).map((v) => {
|
|
537
|
+
let [start, end] = v.split(/\s*?-\s*?/).map((v2) => parseInt(v2.trim(), 10));
|
|
538
|
+
start = start > 0 ? start : 1;
|
|
539
|
+
end = end > start ? end : start;
|
|
540
|
+
const paddedArr = new Array((start > end ? start - end : end - start) + 1).fill(0);
|
|
541
|
+
paddedArr.forEach((_, idx2) => {
|
|
542
|
+
paddedArr[idx2] = start + idx2;
|
|
543
|
+
});
|
|
544
|
+
return paddedArr;
|
|
545
|
+
}).flat()
|
|
546
|
+
)
|
|
547
|
+
);
|
|
548
|
+
} catch (ex) {
|
|
549
|
+
console.warn(ex);
|
|
550
|
+
}
|
|
551
|
+
const langName = token.info.replace(LineNumbersRegex, "").trim();
|
|
552
|
+
let code = md.utils.escapeHtml(token.content);
|
|
553
|
+
code = options.highlight ? options.highlight(code, langName, "") : code;
|
|
554
|
+
const tmpToken = Object.assign(token, {
|
|
555
|
+
attrs: [
|
|
556
|
+
["class", langName ? `language-${langName}` : ""],
|
|
557
|
+
highlightedLines && highlightedLines.length > 0 ? ["data-lines-highlight", `[${highlightedLines.join(",")}]`] : []
|
|
558
|
+
]
|
|
559
|
+
});
|
|
560
|
+
const attrs = self.renderAttrs(tmpToken);
|
|
561
|
+
return `<pre${attrs}><code${attrs}>${code.trim()}</code></pre>`;
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// src/presets/plugins/meta.ts
|
|
566
|
+
var meta = (state, startLine, endLine, silent) => {
|
|
567
|
+
if (startLine !== 0 || state.blkIndent !== 0) {
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
if (state.tShift[startLine] < 0) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
if (!state.getLines(startLine, startLine + 1, 0, false).match(/^---$/)) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
let line = startLine;
|
|
577
|
+
let matchedEndLine = -1;
|
|
578
|
+
while (line < endLine) {
|
|
579
|
+
line++;
|
|
580
|
+
const str = state.getLines(line, line + 1, 0, false);
|
|
581
|
+
if (str.match(/^---$/)) {
|
|
582
|
+
matchedEndLine = line;
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
if (state.tShift[line] < 0) {
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (matchedEndLine > -1) {
|
|
590
|
+
state.line = matchedEndLine + 1;
|
|
591
|
+
const token = state.push("fence", "code", 0);
|
|
592
|
+
token.content = state.getLines(startLine + 1, matchedEndLine, 0, true);
|
|
593
|
+
token.map = [startLine, matchedEndLine];
|
|
594
|
+
token.info = "yml";
|
|
595
|
+
token.markup = "---";
|
|
596
|
+
token.attrPush(["data-yaml-metadata", ""]);
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
return false;
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/presets/plugins/unique-custom-id.ts
|
|
603
|
+
var attrPluginName = "curly_attributes";
|
|
604
|
+
var uniqueCustomIdAttr = (state) => {
|
|
605
|
+
const { tokens } = state;
|
|
606
|
+
let map;
|
|
607
|
+
tokens.filter((x) => !!x.attrGet("id")).forEach((token) => {
|
|
608
|
+
map != null ? map : map = {};
|
|
609
|
+
const idAttrValue = token.attrGet("id");
|
|
610
|
+
if (map.hasOwnProperty(idAttrValue)) {
|
|
611
|
+
const count = map[idAttrValue];
|
|
612
|
+
token.attrSet("id", `${idAttrValue}-${count}`);
|
|
613
|
+
map[idAttrValue] = count + 1;
|
|
614
|
+
} else {
|
|
615
|
+
map[idAttrValue] = 1;
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
map = void 0;
|
|
619
|
+
};
|
|
620
|
+
var plugin2 = (md, opt) => {
|
|
621
|
+
if (md.core.ruler.getRules("").some((x) => x.name === attrPluginName) != null) {
|
|
622
|
+
md.core.ruler.after(attrPluginName, "unique_custom_id_attribute", uniqueCustomIdAttr, opt);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
// src/presets/index.ts
|
|
627
|
+
var mdUtils = new MarkdownIt().utils;
|
|
628
|
+
var defaultCodeHighlight = (str, lang) => {
|
|
629
|
+
if (lang && hljs.getLanguage(lang)) {
|
|
630
|
+
try {
|
|
631
|
+
const result = hljs.highlight(lang, str, true);
|
|
632
|
+
return `<pre class="hljs"><code data-lang="${result.language}">${result.value}</code></pre>`;
|
|
633
|
+
} catch (e) {
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return `<pre class="hljs"><code>${mdUtils.escapeHtml(str)}</code></pre>`;
|
|
637
|
+
};
|
|
638
|
+
var addLinkAttributes = [
|
|
639
|
+
InlineTokensIterator,
|
|
640
|
+
"url_new_win",
|
|
641
|
+
"link_open",
|
|
642
|
+
(tokens, idx) => {
|
|
643
|
+
const token = tokens[idx];
|
|
644
|
+
const href = token.attrGet("href");
|
|
645
|
+
if (!href) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
if (!href.startsWith("#")) {
|
|
649
|
+
token.attrPush(["target", "_blank"]);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
];
|
|
653
|
+
var markdownItFactory = ({
|
|
654
|
+
html,
|
|
655
|
+
codeHighlight,
|
|
656
|
+
taskListsOption,
|
|
657
|
+
math,
|
|
658
|
+
disableRules,
|
|
659
|
+
linkify: linkifyOption
|
|
660
|
+
} = defaultMarkdownItOption) => {
|
|
661
|
+
const mdOpt = {
|
|
662
|
+
html,
|
|
663
|
+
breaks: true,
|
|
664
|
+
linkify: true
|
|
665
|
+
};
|
|
666
|
+
taskListsOption != null ? taskListsOption : taskListsOption = defaultTaskListsOption;
|
|
667
|
+
linkifyOption = Object.assign({}, defaultLinkifyOptions, linkifyOption != null ? linkifyOption : defaultLinkifyOptions);
|
|
668
|
+
if (codeHighlight) {
|
|
669
|
+
mdOpt.highlight = defaultCodeHighlight;
|
|
670
|
+
}
|
|
671
|
+
const md = new MarkdownIt(mdOpt).use(MarkdownItContainer).use(diagramPlugin).use(MarkdownItAttrs, { allowedAttributes: ["id", "class", LineNumberAttrRegex], disableParagraphBlock: true }).use(MdAnchor, anchorOption).use(plugin2).use(plugin).use(MdAbbr).use(MdDefList).use(MdEmoji).use(MdFootnote).use(MdMark).use(MdSub).use(MdSup).use(highlightCodeLines).use(LazyHeaders).use(MarkdownTaskLists, taskListsOption).use(HtmlFilterPlugin).use(...addLinkAttributes).use(MultilineBlockquotePlugin);
|
|
672
|
+
md.block.ruler.before("hr", "meta", meta);
|
|
673
|
+
if (math) {
|
|
674
|
+
md.use(simpleMathPlugin);
|
|
675
|
+
}
|
|
676
|
+
if (disableRules && disableRules.length > 0) {
|
|
677
|
+
md.disable(disableRules);
|
|
678
|
+
}
|
|
679
|
+
const { normalize: defaultNormalize } = md.linkify.set(linkifyOption);
|
|
680
|
+
if (linkifyOption.fuzzyLink && linkifyOption.fuzzyLinkUseHttps) {
|
|
681
|
+
md.linkify.normalize = (match) => {
|
|
682
|
+
if (!match.schema) {
|
|
683
|
+
match.url = `https://${match.url}`;
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
defaultNormalize(match);
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
return md;
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// src/math/model.ts
|
|
693
|
+
var MathEngine = /* @__PURE__ */ ((MathEngine2) => {
|
|
694
|
+
MathEngine2[MathEngine2["MathJax2"] = 0] = "MathJax2";
|
|
695
|
+
MathEngine2[MathEngine2["MathJax3"] = 1] = "MathJax3";
|
|
696
|
+
return MathEngine2;
|
|
697
|
+
})(MathEngine || {});
|
|
698
|
+
var defaultConfig = {
|
|
699
|
+
[0 /* MathJax2 */]: {
|
|
700
|
+
entryScript: "https://mathjax.cnblogs.com/2_7_5/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured&v=20200504",
|
|
701
|
+
document: window.document,
|
|
702
|
+
engine: 0 /* MathJax2 */,
|
|
703
|
+
isEnabled: true
|
|
704
|
+
},
|
|
705
|
+
[1 /* MathJax3 */]: {
|
|
706
|
+
entryScript: "https://mathjax.cnblogs.com/3_2_1/es5/tex-mml-chtml.js",
|
|
707
|
+
document: window.document,
|
|
708
|
+
engine: 1 /* MathJax3 */,
|
|
709
|
+
isEnabled: true
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// src/math/impl.ts
|
|
714
|
+
import { loadScript } from "@cnblogs/load-script-css";
|
|
715
|
+
var Mathjax2Renderer = class {
|
|
716
|
+
constructor() {
|
|
717
|
+
this._defaultConfig = defaultConfig[0 /* MathJax2 */];
|
|
718
|
+
this._defaultMathJaxConfig = {
|
|
719
|
+
tex2jax: {
|
|
720
|
+
inlineMath: [
|
|
721
|
+
["$", "$"],
|
|
722
|
+
["\\(", "\\)"]
|
|
723
|
+
],
|
|
724
|
+
processClass: "math",
|
|
725
|
+
processEscapes: true
|
|
726
|
+
},
|
|
727
|
+
TeX: {
|
|
728
|
+
equationNumbers: {
|
|
729
|
+
autoNumber: "AMS",
|
|
730
|
+
useLabelIds: true
|
|
731
|
+
},
|
|
732
|
+
extensions: ["extpfeil.js", "mediawiki-texvc.js"],
|
|
733
|
+
Macros: { bm: "\\boldsymbol" }
|
|
734
|
+
},
|
|
735
|
+
"HTML-CSS": { linebreaks: { automatic: true } },
|
|
736
|
+
SVG: { linebreaks: { automatic: true } },
|
|
737
|
+
skipStartupTypeset: true
|
|
738
|
+
};
|
|
739
|
+
this._config = this._defaultConfig;
|
|
740
|
+
}
|
|
741
|
+
get _global() {
|
|
742
|
+
var _a;
|
|
743
|
+
return (_a = this._config.document.defaultView) != null ? _a : window;
|
|
744
|
+
}
|
|
745
|
+
render(container, callback) {
|
|
746
|
+
if (!this._config.isEnabled)
|
|
747
|
+
return Promise.resolve();
|
|
748
|
+
return this.init().then((mathjax) => {
|
|
749
|
+
if (!mathjax)
|
|
750
|
+
return;
|
|
751
|
+
const { onRendered } = this._config;
|
|
752
|
+
mathjax.Hub.Queue(["Typeset", mathjax.Hub, container]);
|
|
753
|
+
if (onRendered != null) {
|
|
754
|
+
mathjax.Hub.Queue(() => onRendered(mathjax));
|
|
755
|
+
}
|
|
756
|
+
if (callback) {
|
|
757
|
+
mathjax.Hub.Queue(callback);
|
|
758
|
+
}
|
|
759
|
+
}).catch(console.warn);
|
|
760
|
+
}
|
|
761
|
+
config(value) {
|
|
762
|
+
this._config = Object.assign({}, this._defaultConfig, value);
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
init() {
|
|
766
|
+
if (this._initTask)
|
|
767
|
+
return this._initTask;
|
|
768
|
+
const { entryScript, tapMathJaxConfig, document } = this._config;
|
|
769
|
+
return this._initTask = loadScript({
|
|
770
|
+
src: entryScript,
|
|
771
|
+
id: "mathjax",
|
|
772
|
+
timeoutSeconds: 10,
|
|
773
|
+
appendTo: document.head
|
|
774
|
+
}).then(() => {
|
|
775
|
+
var _a;
|
|
776
|
+
const { MathJax } = this._global;
|
|
777
|
+
if (MathJax) {
|
|
778
|
+
MathJax.Hub.Config(
|
|
779
|
+
(_a = tapMathJaxConfig == null ? void 0 : tapMathJaxConfig.call(
|
|
780
|
+
void 0,
|
|
781
|
+
Object.assign({}, this._defaultMathJaxConfig)
|
|
782
|
+
)) != null ? _a : __spreadValues({}, this._defaultMathJaxConfig)
|
|
783
|
+
);
|
|
784
|
+
MathJax.Hub.Configured();
|
|
785
|
+
return MathJax;
|
|
786
|
+
}
|
|
787
|
+
}).catch(() => this._initTask = void 0);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
var MathJax3Renderer = class {
|
|
791
|
+
constructor() {
|
|
792
|
+
this._defaultConfig = defaultConfig[1 /* MathJax3 */];
|
|
793
|
+
this._defaultMathJaxConfig = {
|
|
794
|
+
tex: {
|
|
795
|
+
inlineMath: [
|
|
796
|
+
["$", "$"],
|
|
797
|
+
["\\(", "\\)"]
|
|
798
|
+
],
|
|
799
|
+
processEscapes: true,
|
|
800
|
+
tags: "ams",
|
|
801
|
+
useLabelIds: true,
|
|
802
|
+
macros: {
|
|
803
|
+
bm: "\\boldsymbol"
|
|
804
|
+
},
|
|
805
|
+
packages: { "[+]": ["noerrors", "extpfeil"] }
|
|
806
|
+
},
|
|
807
|
+
options: {
|
|
808
|
+
processHtmlClass: "math",
|
|
809
|
+
ignoreHtmlClass: "tex2jax_ignore"
|
|
810
|
+
},
|
|
811
|
+
loader: {
|
|
812
|
+
load: ["[tex]/noerrors", "[tex]/extpfeil"]
|
|
813
|
+
},
|
|
814
|
+
startup: {
|
|
815
|
+
typeset: false
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
this._config = this._defaultConfig;
|
|
819
|
+
}
|
|
820
|
+
config(value) {
|
|
821
|
+
this._config = Object.assign({}, this._defaultConfig, value);
|
|
822
|
+
return this;
|
|
823
|
+
}
|
|
824
|
+
render(container, callback) {
|
|
825
|
+
if (!this._config.isEnabled)
|
|
826
|
+
return Promise.resolve();
|
|
827
|
+
return this.init().then((mathjax) => {
|
|
828
|
+
mathjax ? mathjax.startup.promise = mathjax.startup.promise.then(
|
|
829
|
+
() => mathjax.typesetPromise([container]).then(() => {
|
|
830
|
+
var _a;
|
|
831
|
+
try {
|
|
832
|
+
(_a = this._config.onRendered) == null ? void 0 : _a.call(void 0, mathjax);
|
|
833
|
+
} catch (e) {
|
|
834
|
+
console.error(e);
|
|
835
|
+
}
|
|
836
|
+
try {
|
|
837
|
+
callback == null ? void 0 : callback.call(void 0);
|
|
838
|
+
} catch (e) {
|
|
839
|
+
console.error(e);
|
|
840
|
+
}
|
|
841
|
+
})
|
|
842
|
+
) : void 0;
|
|
843
|
+
}).catch(console.warn);
|
|
844
|
+
}
|
|
845
|
+
init() {
|
|
846
|
+
var _a;
|
|
847
|
+
return ((_a = this._initTask) != null ? _a : this._initTask = new Promise((resolve, reject) => {
|
|
848
|
+
var _a2, _b;
|
|
849
|
+
const { entryScript, tapMathJaxConfig, document: _document } = this._config;
|
|
850
|
+
const _window = (_a2 = _document.defaultView) != null ? _a2 : window;
|
|
851
|
+
_window.MathJax = (_b = tapMathJaxConfig == null ? void 0 : tapMathJaxConfig.call(void 0, __spreadValues({}, this._defaultMathJaxConfig))) != null ? _b : __spreadValues({}, this._defaultMathJaxConfig);
|
|
852
|
+
if (!_window.MathJax.startup) {
|
|
853
|
+
_window.MathJax.startup = {};
|
|
854
|
+
}
|
|
855
|
+
_window.MathJax.startup.ready = () => {
|
|
856
|
+
var _a3, _b2;
|
|
857
|
+
(_b2 = (_a3 = _window.MathJax) == null ? void 0 : _a3.startup) == null ? void 0 : _b2.defaultReady();
|
|
858
|
+
resolve(_window.MathJax);
|
|
859
|
+
};
|
|
860
|
+
loadScript({
|
|
861
|
+
src: entryScript,
|
|
862
|
+
id: "mathjax",
|
|
863
|
+
executionStrategy: "defer",
|
|
864
|
+
appendTo: _window.document.head
|
|
865
|
+
}).catch(reject);
|
|
866
|
+
})).catch(() => this._initTask = void 0);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
// src/math/factory.ts
|
|
871
|
+
var createMathJaxRenderer = (rendererConfig) => {
|
|
872
|
+
switch (rendererConfig.engine) {
|
|
873
|
+
case 0 /* MathJax2 */:
|
|
874
|
+
return new Mathjax2Renderer().config(rendererConfig);
|
|
875
|
+
case 1 /* MathJax3 */:
|
|
876
|
+
return new MathJax3Renderer().config(rendererConfig);
|
|
877
|
+
default:
|
|
878
|
+
throw Error("Renderer unavailable");
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
export {
|
|
882
|
+
highlightCodeLines as HighlightCodeLinesPlugin,
|
|
883
|
+
MarkdownIt,
|
|
884
|
+
MathEngine,
|
|
885
|
+
MultilineBlockquotePlugin,
|
|
886
|
+
MultilineBlockquoteRule,
|
|
887
|
+
anchorOption,
|
|
888
|
+
createMathJaxRenderer,
|
|
889
|
+
defaultLinkifyOptions,
|
|
890
|
+
defaultMarkdownItOption,
|
|
891
|
+
defaultTaskListsOption,
|
|
892
|
+
markdownItFactory
|
|
893
|
+
};
|