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