@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,127 +1,726 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.HighlightCodeLinesPlugin = exports.MarkdownIt = exports.markdownItFactory = exports.MultilineBlockquoteRule = exports.MultilineBlockquotePlugin = void 0;
21
- const markdown_it_1 = __importDefault(require("markdown-it"));
22
- exports.MarkdownIt = markdown_it_1.default;
23
- const highlight_js_1 = __importDefault(require("highlight.js"));
24
- const markdown_it_container_1 = __importDefault(require("markdown-it-container"));
25
- const markdown_it_abbr_1 = __importDefault(require("markdown-it-abbr"));
26
- const markdown_it_deflist_1 = __importDefault(require("markdown-it-deflist"));
27
- const markdown_it_emoji_1 = __importDefault(require("markdown-it-emoji"));
28
- const markdown_it_footnote_1 = __importDefault(require("markdown-it-footnote"));
29
- const markdown_it_mark_1 = __importDefault(require("markdown-it-mark"));
30
- const markdown_it_sub_1 = __importDefault(require("markdown-it-sub"));
31
- const markdown_it_sup_1 = __importDefault(require("markdown-it-sup"));
32
- const markdown_it_anchor_1 = __importDefault(require("markdown-it-anchor"));
33
- const markdown_it_lazy_headers_1 = __importDefault(require("markdown-it-lazy-headers"));
34
- const markdown_it_for_inline_1 = __importDefault(require("markdown-it-for-inline"));
35
- const markdown_it_task_lists_1 = __importDefault(require("markdown-it-task-lists"));
36
- const markdown_it_attrs_1 = __importDefault(require("markdown-it-attrs"));
37
- const simple_math_plugin_1 = require("./plugins/simple-math.plugin");
38
- const simple_mermaid_plugin_1 = require("./plugins/simple-mermaid.plugin");
39
- const html_filter_plugin_1 = require("./plugins/html-filter.plugin");
40
- const multiline_blockquote_plugin_1 = require("./plugins/multiline-blockquote/multiline-blockquote.plugin");
41
- Object.defineProperty(exports, "MultilineBlockquotePlugin", { enumerable: true, get: function () { return multiline_blockquote_plugin_1.MultilineBlockquotePlugin; } });
42
- Object.defineProperty(exports, "MultilineBlockquoteRule", { enumerable: true, get: function () { return multiline_blockquote_plugin_1.MultilineBlockquoteRule; } });
43
- const option_1 = require("./option");
44
- const toc_1 = require("./plugins/toc");
45
- const highlight_code_lines_plugin_1 = require("./plugins/highlight-code-lines.plugin");
46
- Object.defineProperty(exports, "HighlightCodeLinesPlugin", { enumerable: true, get: function () { return highlight_code_lines_plugin_1.HighlightCodeLinesPlugin; } });
47
- const meta_1 = require("./plugins/meta");
48
- const unique_custom_id_1 = require("./plugins/unique-custom-id");
49
- const mdUtils = new markdown_it_1.default().utils;
50
- const defaultCodeHighlight = (str, lang) => {
51
- if (lang && highlight_js_1.default.getLanguage(lang)) {
52
- try {
53
- const result = highlight_js_1.default.highlight(lang, str, true);
54
- return `<pre class="hljs"><code data-lang="${result.language}">${result.value}</code></pre>`;
55
- }
56
- catch (_a) { }
57
- }
58
- return `<pre class="hljs"><code>${mdUtils.escapeHtml(str)}</code></pre>`;
59
- };
60
- const addLinkAttributes = [
61
- markdown_it_for_inline_1.default,
62
- 'url_new_win',
63
- 'link_open',
64
- (tokens, idx) => {
65
- const token = tokens[idx];
66
- const href = token.attrGet('href');
67
- if (!href) {
68
- return;
69
- }
70
- if (!href.startsWith('#')) {
71
- token.attrPush(['target', '_blank']);
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/presets/index.ts
30
+ var presets_exports = {};
31
+ __export(presets_exports, {
32
+ HighlightCodeLinesPlugin: () => highlightCodeLines,
33
+ MarkdownIt: () => import_markdown_it.default,
34
+ MultilineBlockquotePlugin: () => MultilineBlockquotePlugin,
35
+ MultilineBlockquoteRule: () => MultilineBlockquoteRule,
36
+ anchorOption: () => anchorOption,
37
+ defaultLinkifyOptions: () => defaultLinkifyOptions,
38
+ defaultMarkdownItOption: () => defaultMarkdownItOption,
39
+ defaultTaskListsOption: () => defaultTaskListsOption,
40
+ markdownItFactory: () => markdownItFactory
41
+ });
42
+ module.exports = __toCommonJS(presets_exports);
43
+ var import_markdown_it = __toESM(require("markdown-it"), 1);
44
+ var import_highlight = __toESM(require("highlight.js"), 1);
45
+ var import_markdown_it_container = __toESM(require("markdown-it-container"), 1);
46
+ var import_markdown_it_abbr = __toESM(require("markdown-it-abbr"), 1);
47
+ var import_markdown_it_deflist = __toESM(require("markdown-it-deflist"), 1);
48
+ var import_markdown_it_emoji = __toESM(require("markdown-it-emoji"), 1);
49
+ var import_markdown_it_footnote = __toESM(require("markdown-it-footnote"), 1);
50
+ var import_markdown_it_mark = __toESM(require("markdown-it-mark"), 1);
51
+ var import_markdown_it_sub = __toESM(require("markdown-it-sub"), 1);
52
+ var import_markdown_it_sup = __toESM(require("markdown-it-sup"), 1);
53
+ var import_markdown_it_anchor = __toESM(require("markdown-it-anchor"), 1);
54
+ var import_markdown_it_lazy_headers = __toESM(require("markdown-it-lazy-headers"), 1);
55
+ var import_markdown_it_for_inline = __toESM(require("markdown-it-for-inline"), 1);
56
+ var import_markdown_it_task_lists = __toESM(require("markdown-it-task-lists"), 1);
57
+ var import_markdown_it_attrs = __toESM(require("markdown-it-attrs"), 1);
58
+
59
+ // src/presets/plugins/simple-math.plugin.ts
60
+ function isValidDelimiter(state, pos) {
61
+ let max = state.posMax;
62
+ let canOpen = true;
63
+ let canClose = true;
64
+ let prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
65
+ let nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
66
+ if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
67
+ canClose = false;
68
+ }
69
+ if (nextChar === 32 || nextChar === 9) {
70
+ canOpen = false;
71
+ }
72
+ return {
73
+ canOpen,
74
+ canClose
75
+ };
76
+ }
77
+ var mathInTable = (state) => {
78
+ const { src } = state;
79
+ const regex = /(\|.*\|)\n(\|\s*?-+:?\s*?)+\|\n(\|.*\|\n?)*?((\|.*?\$+.*\n?)+)/g;
80
+ const inlineMathRegex = /\$(.*?)\$/g;
81
+ state.src = src.replace(
82
+ regex,
83
+ (match, sub1, sub2, sub3, sub4) => match.replace(
84
+ sub4,
85
+ sub4.replace(inlineMathRegex, (match2, sub) => `$${sub.replace(/\\*?\|/g, "\\|")}$$`)
86
+ )
87
+ );
88
+ return true;
89
+ };
90
+ var mathInline = (state, silent) => {
91
+ let start, match, token, res, pos;
92
+ if (state.src[state.pos] !== "$") {
93
+ return false;
94
+ }
95
+ res = isValidDelimiter(state, state.pos);
96
+ if (!res.canOpen) {
97
+ if (!silent) {
98
+ state.pending += "$";
99
+ }
100
+ state.pos += 1;
101
+ return true;
102
+ }
103
+ start = state.pos + 1;
104
+ match = start;
105
+ while ((match = state.src.indexOf("$", match)) !== -1) {
106
+ pos = match - 1;
107
+ while (state.src[pos] === "\\") {
108
+ pos -= 1;
109
+ }
110
+ if ((match - pos) % 2 == 1) {
111
+ break;
112
+ }
113
+ match += 1;
114
+ }
115
+ if (match === -1) {
116
+ if (!silent) {
117
+ state.pending += "$";
118
+ }
119
+ state.pos = start;
120
+ return true;
121
+ }
122
+ if (match - start === 0) {
123
+ if (!silent) {
124
+ state.pending += "$$";
125
+ }
126
+ state.pos = start + 1;
127
+ return true;
128
+ }
129
+ res = isValidDelimiter(state, match);
130
+ if (!res.canClose) {
131
+ if (!silent) {
132
+ state.pending += "$";
133
+ }
134
+ state.pos = start;
135
+ return true;
136
+ }
137
+ if (!silent) {
138
+ token = state.push("math_inline", "math", 0);
139
+ token.markup = "$";
140
+ token.content = state.src.slice(start, match);
141
+ }
142
+ state.pos = match + 1;
143
+ return true;
144
+ };
145
+ var mathBlock = (state, start, end, silent) => {
146
+ let lastLine;
147
+ let next;
148
+ let lastPos;
149
+ let found = false;
150
+ let token;
151
+ let pos = state.bMarks[start] + state.tShift[start];
152
+ let max = state.eMarks[start];
153
+ if (pos + 2 > max) {
154
+ return false;
155
+ }
156
+ if (state.src[pos] !== "$" || state.src[pos + 1] !== "$") {
157
+ return false;
158
+ }
159
+ pos += 2;
160
+ if (silent) {
161
+ return true;
162
+ }
163
+ let firstLine = state.src.slice(pos, max);
164
+ if (firstLine.trim().slice(-2) === "$$") {
165
+ firstLine = firstLine.trim().slice(0, -2);
166
+ found = true;
167
+ }
168
+ for (next = start; !found; ) {
169
+ next++;
170
+ if (next >= end) {
171
+ break;
172
+ }
173
+ pos = state.bMarks[next] + state.tShift[next];
174
+ max = state.eMarks[next];
175
+ if (pos < max && state.tShift[next] < state.blkIndent) {
176
+ break;
177
+ }
178
+ if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
179
+ lastPos = state.src.slice(0, max).lastIndexOf("$$");
180
+ lastLine = state.src.slice(pos, lastPos);
181
+ found = true;
182
+ }
183
+ }
184
+ state.line = next + 1;
185
+ token = state.push("math_block", "math", 0);
186
+ token.block = true;
187
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
188
+ token.map = [start, state.line];
189
+ token.markup = "$$";
190
+ return true;
191
+ };
192
+ var simpleMathPlugin = (md) => {
193
+ md.core.ruler.before("block", "math_in_table", mathInTable);
194
+ md.inline.ruler.after("escape", "math_inline", mathInline);
195
+ md.block.ruler.after("blockquote", "math_block", mathBlock, {
196
+ alt: ["paragraph", "reference", "blockquote", "list"]
197
+ });
198
+ const simpleInlineRenderer = (tokens, idx) => {
199
+ return '<span class="math inline">\\(' + md.utils.escapeHtml(tokens[idx].content) + "\\)</span>";
200
+ };
201
+ const simpleBlockRenderer = (tokens, idx) => {
202
+ return '<p><div class="math display">\\[' + md.utils.escapeHtml(tokens[idx].content) + "\\]</div></p>";
203
+ };
204
+ md.renderer.rules.math_inline = simpleInlineRenderer;
205
+ md.renderer.rules.math_block = simpleBlockRenderer;
206
+ };
207
+
208
+ // src/presets/plugins/simple-mermaid.plugin.ts
209
+ function diagramPlugin(md, options) {
210
+ function getLangName(info) {
211
+ return info.split(/\s+/g)[0];
212
+ }
213
+ let defaultFenceRenderer = md.renderer.rules.fence;
214
+ function customFenceRenderer(tokens, idx, options2, env, slf) {
215
+ let token = tokens[idx];
216
+ let info = token.info.trim();
217
+ let langName = info ? getLangName(info) : "";
218
+ if (langName.toLowerCase() === "mermaid") {
219
+ return '<div class="mermaid">' + md.utils.escapeHtml(token.content) + "</div>";
220
+ }
221
+ return defaultFenceRenderer(tokens, idx, options2, env, slf);
222
+ }
223
+ md.renderer.rules.fence = customFenceRenderer;
224
+ }
225
+
226
+ // src/presets/plugins/html-filter.plugin.ts
227
+ var tagFilterRules = {
228
+ title: { rule: "escape" },
229
+ head: { rule: "escape" },
230
+ body: { rule: "escape" },
231
+ img: {
232
+ rule: "filterAttributes",
233
+ disabledAttributes: ["onerror"]
234
+ }
235
+ };
236
+ var HtmlFilterPlugin = (md) => {
237
+ const defaultHtmlBlock = md.renderer.rules.html_block;
238
+ md.renderer.rules.html_block = (tokens, idx, options, env, self) => {
239
+ const token = tokens[idx];
240
+ if (token.type === "html_block" && !token.tag) {
241
+ let { content } = token;
242
+ for (let tagName in tagFilterRules) {
243
+ const rule = tagFilterRules[tagName];
244
+ const { rule: handleStrategy, disabledAttributes } = rule;
245
+ if (handleStrategy === "escape") {
246
+ const start = `<${tagName}>`;
247
+ const end = `</${tagName}>`;
248
+ const matchStart = content.replace(new RegExp("\n", "g"), "").startsWith(start);
249
+ const matchEnd = content.replace(new RegExp("\n", "g"), "").endsWith(end);
250
+ if (matchStart || matchEnd) {
251
+ content = md.utils.escapeHtml(content);
252
+ break;
253
+ }
254
+ } else if (handleStrategy === "filterAttributes" && disabledAttributes != null && disabledAttributes.length > 0) {
255
+ for (let attribute of disabledAttributes) {
256
+ content = content.replace(
257
+ new RegExp(`(<${tagName}.*? +)(${attribute}=)(.*?>)`, "ig"),
258
+ (match, p1, p2, p3) => p1 + "data-" + p2 + p3
259
+ );
260
+ }
72
261
  }
73
- },
262
+ }
263
+ if (content !== token.content)
264
+ return content;
265
+ }
266
+ return defaultHtmlBlock(tokens, idx, options, env, self);
267
+ };
268
+ };
269
+
270
+ // src/presets/plugins/multiline-blockquote/multiline-blockquote.rule.ts
271
+ var MultilineBlockquoteRule = (state, startLine, endLine) => {
272
+ let nextLine, token;
273
+ let pos = state.bMarks[startLine] + state.tShift[startLine];
274
+ if (state.sCount[startLine] - state.blkIndent >= 4) {
275
+ return false;
276
+ }
277
+ let marker = state.src.charCodeAt(pos);
278
+ if (marker !== 62) {
279
+ return false;
280
+ }
281
+ let markerLength = state.skipChars(pos, marker) - pos;
282
+ if (markerLength !== 3)
283
+ return false;
284
+ if (state.src.charCodeAt(state.skipChars(
285
+ pos + markerLength,
286
+ 32
287
+ /* ' ' */
288
+ )) !== 10) {
289
+ return false;
290
+ }
291
+ nextLine = startLine + 1;
292
+ while (nextLine < endLine) {
293
+ pos = state.bMarks[nextLine] + state.tShift[nextLine];
294
+ marker = state.src.charCodeAt(pos);
295
+ if (marker === 62 && (markerLength = state.skipChars(pos, marker) - pos) === 3) {
296
+ pos = state.skipChars(pos + markerLength, 32);
297
+ if (pos >= state.src.length || state.src.charCodeAt(pos) === 10)
298
+ break;
299
+ }
300
+ nextLine++;
301
+ }
302
+ if (nextLine > endLine) {
303
+ return false;
304
+ }
305
+ token = state.push("multiline_blockquote_open", "blockquote", 1);
306
+ token.markup = ">>>";
307
+ token.map = [startLine, 0];
308
+ state.md.block.tokenize(state, startLine + 1, nextLine);
309
+ token = state.push("multiline_blockquote_close", "blockquote", -1);
310
+ token.map = [nextLine, 0];
311
+ state.line = nextLine + 1;
312
+ return true;
313
+ };
314
+
315
+ // src/presets/plugins/multiline-blockquote/multiline-blockquote.plugin.ts
316
+ var MultilineBlockquotePlugin = (md, options) => {
317
+ options != null ? options : options = {};
318
+ md.block.ruler.before("blockquote", "multiline_blockquote", (...args) => {
319
+ if (options.enable != null && !options.enable(md))
320
+ return false;
321
+ return MultilineBlockquoteRule.apply(void 0, args);
322
+ });
323
+ };
324
+
325
+ // src/presets/option.ts
326
+ var import_github_slugger = __toESM(require("github-slugger"), 1);
327
+ var defaultTaskListsOption = {
328
+ enable: true,
329
+ label: true,
330
+ labelAfter: true
331
+ };
332
+ var defaultMarkdownItOption = {
333
+ codeHighlight: false,
334
+ math: false,
335
+ disableRules: [],
336
+ html: false,
337
+ taskListsOption: defaultTaskListsOption
338
+ };
339
+ var defaultLinkifyOptions = {
340
+ fuzzyEmail: false,
341
+ fuzzyLink: false,
342
+ fuzzyLinkUseHttps: true
343
+ };
344
+ var anchorOption = {
345
+ level: 1,
346
+ slugify(str) {
347
+ const result = new import_github_slugger.default().slug(str);
348
+ return result === "" ? "_" : result;
349
+ }
350
+ };
351
+
352
+ // src/presets/plugins/toc/slugify.ts
353
+ var slugify = function(s) {
354
+ return encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, "-"));
355
+ };
356
+
357
+ // src/presets/plugins/toc/toc-option.ts
358
+ var defaultTocOption = {
359
+ includeLevel: [1, 2, 3, 4, 5, 6],
360
+ containerClass: "toc",
361
+ slugify,
362
+ markerPattern: /\[TOC]/im,
363
+ listType: "ul",
364
+ format: (content) => content.replace(/<\/?a.*?>/g, ""),
365
+ forceFullToc: false,
366
+ containerHeaderHtml: `<div class="toc-container-header">\u76EE\u5F55</div>`,
367
+ containerFooterHtml: void 0,
368
+ transformLink: void 0
369
+ };
370
+
371
+ // src/presets/plugins/toc/index.ts
372
+ var defaults = defaultTocOption;
373
+ var findHeadlineElements = (levels, tokens, options, md, env) => {
374
+ const headings = [];
375
+ let currentHeading = null;
376
+ tokens.forEach((token) => {
377
+ if (token.type === "heading_open") {
378
+ const id = findExistingIdAttr(token);
379
+ const level = parseInt(token.tag.toLowerCase().replace("h", ""), 10);
380
+ if (levels.indexOf(level) >= 0) {
381
+ currentHeading = {
382
+ level,
383
+ textContent: null,
384
+ anchor: id || null,
385
+ markdownContent: null
386
+ };
387
+ }
388
+ } else if (currentHeading && token.type === "inline") {
389
+ const textContent = token.children.filter((childToken) => childToken.type === "text" || childToken.type === "code_inline").reduce((acc, t) => acc + t.content, "");
390
+ currentHeading.textContent = textContent;
391
+ currentHeading.markdownContent = md.renderer.renderInline(token.children, options, env);
392
+ if (!currentHeading.anchor) {
393
+ currentHeading.anchor = options.slugify(textContent, token.content);
394
+ }
395
+ } else if (token.type === "heading_close") {
396
+ if (currentHeading) {
397
+ headings.push(currentHeading);
398
+ }
399
+ currentHeading = null;
400
+ }
401
+ });
402
+ return headings;
403
+ };
404
+ var findExistingIdAttr = (token) => {
405
+ if (token && token.attrs && token.attrs.length > 0) {
406
+ const idAttr = token.attrs.find((attr) => {
407
+ if (Array.isArray(attr) && attr.length >= 2) {
408
+ return attr[0] === "id";
409
+ }
410
+ return false;
411
+ });
412
+ if (idAttr && Array.isArray(idAttr) && idAttr.length >= 2) {
413
+ const [, val] = idAttr;
414
+ return val;
415
+ }
416
+ }
417
+ return null;
418
+ };
419
+ function getMinLevel(headlineItems) {
420
+ return Math.min(...headlineItems.map((item) => item.level));
421
+ }
422
+ var addListItem = (level, text, anchor, rootNode) => {
423
+ const listItem = {
424
+ level,
425
+ text,
426
+ anchor,
427
+ children: [],
428
+ parent: rootNode
429
+ };
430
+ rootNode.children.push(listItem);
431
+ return listItem;
432
+ };
433
+ var flatHeadlineItemsToNestedTree = (headlineItems) => {
434
+ const toc = {
435
+ level: getMinLevel(headlineItems) - 1,
436
+ anchor: null,
437
+ text: null,
438
+ children: [],
439
+ parent: null
440
+ };
441
+ let currentRootNode = toc;
442
+ let prevListItem = currentRootNode;
443
+ headlineItems.forEach((headlineItem) => {
444
+ if (headlineItem.level > prevListItem.level) {
445
+ Array.from({ length: headlineItem.level - prevListItem.level }).forEach((_) => {
446
+ currentRootNode = prevListItem;
447
+ prevListItem = addListItem(headlineItem.level, null, null, currentRootNode);
448
+ });
449
+ prevListItem.text = headlineItem.markdownContent;
450
+ prevListItem.anchor = headlineItem.anchor;
451
+ } else if (headlineItem.level === prevListItem.level) {
452
+ prevListItem = addListItem(
453
+ headlineItem.level,
454
+ headlineItem.markdownContent,
455
+ headlineItem.anchor,
456
+ currentRootNode
457
+ );
458
+ } else if (headlineItem.level < prevListItem.level) {
459
+ for (let i = 0; i < prevListItem.level - headlineItem.level; i++) {
460
+ currentRootNode = currentRootNode.parent;
461
+ }
462
+ prevListItem = addListItem(
463
+ headlineItem.level,
464
+ headlineItem.markdownContent,
465
+ headlineItem.anchor,
466
+ currentRootNode
467
+ );
468
+ }
469
+ });
470
+ return toc;
471
+ };
472
+ var tocItemToHtml = (tocItem, options, md) => {
473
+ return "<" + options.listType + ">" + tocItem.children.map((childItem) => {
474
+ let li = "<li>";
475
+ let anchor = childItem.anchor;
476
+ if (options && options.transformLink) {
477
+ anchor = options.transformLink(anchor);
478
+ }
479
+ let text = childItem.text ? options.format(childItem.text, md, anchor) : null;
480
+ li += anchor ? `<a href="#${anchor}">${text}</a>` : text || "";
481
+ return li + (childItem.children.length > 0 ? tocItemToHtml(childItem, options, md) : "") + "</li>";
482
+ }).join("") + "</" + options.listType + ">";
483
+ };
484
+ var plugin = (md, o) => {
485
+ const options = Object.assign({}, defaults, o);
486
+ const tocRegexp = options.markerPattern;
487
+ let gState;
488
+ const toc = (state, silent) => {
489
+ let token;
490
+ let match;
491
+ if (state.src.charCodeAt(state.pos) !== 91) {
492
+ return false;
493
+ }
494
+ if (silent) {
495
+ return false;
496
+ }
497
+ match = tocRegexp.exec(state.src.substr(state.pos));
498
+ match = !match ? [] : match.filter(function(m) {
499
+ return m;
500
+ });
501
+ if (match.length < 1) {
502
+ return false;
503
+ }
504
+ token = state.push("toc_open", "toc", 1);
505
+ token.markup = "[[toc]]";
506
+ token = state.push("toc_body", "", 0);
507
+ token = state.push("toc_close", "toc", -1);
508
+ const newline = state.src.indexOf("\n", state.pos);
509
+ if (newline !== -1) {
510
+ state.pos = newline;
511
+ } else {
512
+ state.pos = state.pos + state.posMax + 1;
513
+ }
514
+ return true;
515
+ };
516
+ md.renderer.rules.toc_open = (tokens, index) => {
517
+ let tocOpenHtml = '<div class="' + options.containerClass + '">';
518
+ if (options.containerHeaderHtml) {
519
+ tocOpenHtml += options.containerHeaderHtml;
520
+ }
521
+ return tocOpenHtml;
522
+ };
523
+ md.renderer.rules.toc_close = (tokens, index) => {
524
+ let tocFooterHtml = "";
525
+ if (options.containerFooterHtml) {
526
+ tocFooterHtml = options.containerFooterHtml;
527
+ }
528
+ return tocFooterHtml + "</div>";
529
+ };
530
+ md.renderer.rules.toc_body = (tokens, index, opt, env) => {
531
+ if (options.forceFullToc) {
532
+ throw "forceFullToc was removed in version 0.5.0. For more information, see https://github.com/Oktavilla/markdown-it-table-of-contents/pull/41";
533
+ } else {
534
+ const headlineItems = findHeadlineElements(options.includeLevel, gState.tokens, options, md, env);
535
+ const toc2 = flatHeadlineItemsToNestedTree(headlineItems);
536
+ return tocItemToHtml(toc2, options, md);
537
+ }
538
+ };
539
+ md.core.ruler.push("grab_state", (state) => {
540
+ gState = state;
541
+ return true;
542
+ });
543
+ md.inline.ruler.after("emphasis", "toc", toc);
544
+ };
545
+
546
+ // src/presets/plugins/highlight-code-lines.plugin.ts
547
+ var LineNumbersRegex = /{([\d,\s-]+)}/;
548
+ var LineNumberAttrRegex = /^([\d,\s-]+)/;
549
+ var highlightCodeLines = (md, { enable } = {}) => {
550
+ const fence = md.renderer.rules.fence;
551
+ md.renderer.rules.fence = (tokens, idx, options, env, self) => {
552
+ const token = tokens[idx];
553
+ if (enable != null && !enable(md) || token.attrs == null || token.attrs.some(([attr]) => LineNumberAttrRegex.test(attr)) === false) {
554
+ return fence(tokens, idx, options, env, self);
555
+ }
556
+ let highlightedLines = [];
557
+ try {
558
+ highlightedLines = Array.from(
559
+ new Set(
560
+ token.attrs.map(([attr]) => attr.split(",").map((x) => x.trim())).flat().filter((attr) => attr != null && attr.length > 0 && LineNumberAttrRegex.test(attr)).map((v) => {
561
+ let [start, end] = v.split(/\s*?-\s*?/).map((v2) => parseInt(v2.trim(), 10));
562
+ start = start > 0 ? start : 1;
563
+ end = end > start ? end : start;
564
+ const paddedArr = new Array((start > end ? start - end : end - start) + 1).fill(0);
565
+ paddedArr.forEach((_, idx2) => {
566
+ paddedArr[idx2] = start + idx2;
567
+ });
568
+ return paddedArr;
569
+ }).flat()
570
+ )
571
+ );
572
+ } catch (ex) {
573
+ console.warn(ex);
574
+ }
575
+ const langName = token.info.replace(LineNumbersRegex, "").trim();
576
+ let code = md.utils.escapeHtml(token.content);
577
+ code = options.highlight ? options.highlight(code, langName, "") : code;
578
+ const tmpToken = Object.assign(token, {
579
+ attrs: [
580
+ ["class", langName ? `language-${langName}` : ""],
581
+ highlightedLines && highlightedLines.length > 0 ? ["data-lines-highlight", `[${highlightedLines.join(",")}]`] : []
582
+ ]
583
+ });
584
+ const attrs = self.renderAttrs(tmpToken);
585
+ return `<pre${attrs}><code${attrs}>${code.trim()}</code></pre>`;
586
+ };
587
+ };
588
+
589
+ // src/presets/plugins/meta.ts
590
+ var meta = (state, startLine, endLine, silent) => {
591
+ if (startLine !== 0 || state.blkIndent !== 0) {
592
+ return false;
593
+ }
594
+ if (state.tShift[startLine] < 0) {
595
+ return false;
596
+ }
597
+ if (!state.getLines(startLine, startLine + 1, 0, false).match(/^---$/)) {
598
+ return false;
599
+ }
600
+ let line = startLine;
601
+ let matchedEndLine = -1;
602
+ while (line < endLine) {
603
+ line++;
604
+ const str = state.getLines(line, line + 1, 0, false);
605
+ if (str.match(/^---$/)) {
606
+ matchedEndLine = line;
607
+ break;
608
+ }
609
+ if (state.tShift[line] < 0) {
610
+ break;
611
+ }
612
+ }
613
+ if (matchedEndLine > -1) {
614
+ state.line = matchedEndLine + 1;
615
+ const token = state.push("fence", "code", 0);
616
+ token.content = state.getLines(startLine + 1, matchedEndLine, 0, true);
617
+ token.map = [startLine, matchedEndLine];
618
+ token.info = "yml";
619
+ token.markup = "---";
620
+ token.attrPush(["data-yaml-metadata", ""]);
621
+ return true;
622
+ }
623
+ return false;
624
+ };
625
+
626
+ // src/presets/plugins/unique-custom-id.ts
627
+ var attrPluginName = "curly_attributes";
628
+ var uniqueCustomIdAttr = (state) => {
629
+ const { tokens } = state;
630
+ let map;
631
+ tokens.filter((x) => !!x.attrGet("id")).forEach((token) => {
632
+ map != null ? map : map = {};
633
+ const idAttrValue = token.attrGet("id");
634
+ if (map.hasOwnProperty(idAttrValue)) {
635
+ const count = map[idAttrValue];
636
+ token.attrSet("id", `${idAttrValue}-${count}`);
637
+ map[idAttrValue] = count + 1;
638
+ } else {
639
+ map[idAttrValue] = 1;
640
+ }
641
+ });
642
+ map = void 0;
643
+ };
644
+ var plugin2 = (md, opt) => {
645
+ if (md.core.ruler.getRules("").some((x) => x.name === attrPluginName) != null) {
646
+ md.core.ruler.after(attrPluginName, "unique_custom_id_attribute", uniqueCustomIdAttr, opt);
647
+ }
648
+ };
649
+
650
+ // src/presets/index.ts
651
+ var mdUtils = new import_markdown_it.default().utils;
652
+ var defaultCodeHighlight = (str, lang) => {
653
+ if (lang && import_highlight.default.getLanguage(lang)) {
654
+ try {
655
+ const result = import_highlight.default.highlight(lang, str, true);
656
+ return `<pre class="hljs"><code data-lang="${result.language}">${result.value}</code></pre>`;
657
+ } catch (e) {
658
+ }
659
+ }
660
+ return `<pre class="hljs"><code>${mdUtils.escapeHtml(str)}</code></pre>`;
661
+ };
662
+ var addLinkAttributes = [
663
+ import_markdown_it_for_inline.default,
664
+ "url_new_win",
665
+ "link_open",
666
+ (tokens, idx) => {
667
+ const token = tokens[idx];
668
+ const href = token.attrGet("href");
669
+ if (!href) {
670
+ return;
671
+ }
672
+ if (!href.startsWith("#")) {
673
+ token.attrPush(["target", "_blank"]);
674
+ }
675
+ }
74
676
  ];
75
- const markdownItFactory = ({ html, codeHighlight, taskListsOption, math, disableRules, linkify: linkifyOption, } = option_1.defaultMarkdownItOption) => {
76
- const mdOpt = {
77
- html: html,
78
- breaks: true,
79
- linkify: true,
677
+ var markdownItFactory = ({
678
+ html,
679
+ codeHighlight,
680
+ taskListsOption,
681
+ math,
682
+ disableRules,
683
+ linkify: linkifyOption
684
+ } = defaultMarkdownItOption) => {
685
+ const mdOpt = {
686
+ html,
687
+ breaks: true,
688
+ linkify: true
689
+ };
690
+ taskListsOption != null ? taskListsOption : taskListsOption = defaultTaskListsOption;
691
+ linkifyOption = Object.assign({}, defaultLinkifyOptions, linkifyOption != null ? linkifyOption : defaultLinkifyOptions);
692
+ if (codeHighlight) {
693
+ mdOpt.highlight = defaultCodeHighlight;
694
+ }
695
+ 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);
696
+ md.block.ruler.before("hr", "meta", meta);
697
+ if (math) {
698
+ md.use(simpleMathPlugin);
699
+ }
700
+ if (disableRules && disableRules.length > 0) {
701
+ md.disable(disableRules);
702
+ }
703
+ const { normalize: defaultNormalize } = md.linkify.set(linkifyOption);
704
+ if (linkifyOption.fuzzyLink && linkifyOption.fuzzyLinkUseHttps) {
705
+ md.linkify.normalize = (match) => {
706
+ if (!match.schema) {
707
+ match.url = `https://${match.url}`;
708
+ return;
709
+ }
710
+ defaultNormalize(match);
80
711
  };
81
- taskListsOption !== null && taskListsOption !== void 0 ? taskListsOption : (taskListsOption = option_1.defaultTaskListsOption);
82
- linkifyOption = Object.assign({}, option_1.defaultLinkifyOptions, linkifyOption !== null && linkifyOption !== void 0 ? linkifyOption : option_1.defaultLinkifyOptions);
83
- if (codeHighlight) {
84
- mdOpt.highlight = defaultCodeHighlight;
85
- }
86
- const md = new markdown_it_1.default(mdOpt)
87
- .use(markdown_it_container_1.default)
88
- .use(simple_mermaid_plugin_1.diagramPlugin)
89
- .use(markdown_it_attrs_1.default, { allowedAttributes: ['id', 'class', highlight_code_lines_plugin_1.LineNumberAttrRegex], disableParagraphBlock: true })
90
- .use(markdown_it_anchor_1.default, option_1.anchorOption)
91
- .use(unique_custom_id_1.UniqueCustomIdAttrs)
92
- .use(toc_1.TocPlugin)
93
- .use(markdown_it_abbr_1.default)
94
- .use(markdown_it_deflist_1.default)
95
- .use(markdown_it_emoji_1.default)
96
- .use(markdown_it_footnote_1.default)
97
- .use(markdown_it_mark_1.default)
98
- .use(markdown_it_sub_1.default)
99
- .use(markdown_it_sup_1.default)
100
- .use(highlight_code_lines_plugin_1.HighlightCodeLinesPlugin)
101
- .use(markdown_it_lazy_headers_1.default)
102
- .use(markdown_it_task_lists_1.default, taskListsOption)
103
- .use(html_filter_plugin_1.HtmlFilterPlugin)
104
- .use(...addLinkAttributes)
105
- .use(multiline_blockquote_plugin_1.MultilineBlockquotePlugin);
106
- md.block.ruler.before('hr', 'meta', meta_1.meta);
107
- if (math) {
108
- md.use(simple_math_plugin_1.simpleMathPlugin);
109
- }
110
- if (disableRules && disableRules.length > 0) {
111
- md.disable(disableRules);
112
- }
113
- const { normalize: defaultNormalize } = md.linkify.set(linkifyOption);
114
- if (linkifyOption.fuzzyLink && linkifyOption.fuzzyLinkUseHttps) {
115
- md.linkify.normalize = ((match) => {
116
- if (!match.schema) {
117
- match.url = `https://${match.url}`;
118
- return;
119
- }
120
- defaultNormalize(match);
121
- });
122
- }
123
- return md;
124
- };
125
- exports.markdownItFactory = markdownItFactory;
126
- __exportStar(require("./option"), exports);
127
- //# sourceMappingURL=index.js.map
712
+ }
713
+ return md;
714
+ };
715
+ // Annotate the CommonJS export names for ESM import in node:
716
+ 0 && (module.exports = {
717
+ HighlightCodeLinesPlugin,
718
+ MarkdownIt,
719
+ MultilineBlockquotePlugin,
720
+ MultilineBlockquoteRule,
721
+ anchorOption,
722
+ defaultLinkifyOptions,
723
+ defaultMarkdownItOption,
724
+ defaultTaskListsOption,
725
+ markdownItFactory
726
+ });