@cnblogs/markdown-it-presets 1.9.10-beta4 → 1.9.11-beta
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 +683 -482
- package/dist/commonjs/presets/index.cjs +683 -482
- package/dist/es2015/presets/index.mjs +5 -5
- package/dist/es2015/presets/index.mjs.map +1 -1
- package/dist/es2015/presets/option.mjs.map +1 -1
- package/dist/es2015/presets/plugins/imsize/helpers/normalize_reference.mjs +4 -0
- package/dist/es2015/presets/plugins/imsize/helpers/normalize_reference.mjs.map +1 -0
- package/dist/es2015/presets/plugins/imsize/helpers/parse_image_size.mjs +51 -0
- package/dist/es2015/presets/plugins/imsize/helpers/parse_image_size.mjs.map +1 -0
- package/dist/es2015/presets/plugins/imsize/index.mjs +146 -0
- package/dist/es2015/presets/plugins/imsize/index.mjs.map +1 -0
- package/dist/es2015/presets/plugins/index.mjs +2 -0
- package/dist/es2015/presets/plugins/index.mjs.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/presets/index.d.ts +2 -1
- package/dist/umd/markdownItPresets.js +1 -1
- package/package.json +1 -1
|
@@ -56,272 +56,6 @@ var import_markdown_it_for_inline = __toESM(require("markdown-it-for-inline"), 1
|
|
|
56
56
|
var import_markdown_it_task_lists = __toESM(require("markdown-it-task-lists"), 1);
|
|
57
57
|
var import_markdown_it_attrs = __toESM(require("markdown-it-attrs"), 1);
|
|
58
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
|
-
}
|
|
261
|
-
}
|
|
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
59
|
// src/presets/option.ts
|
|
326
60
|
var import_github_slugger = __toESM(require("github-slugger"), 1);
|
|
327
61
|
var defaultTaskListsOption = {
|
|
@@ -400,257 +134,720 @@ var findHeadlineElements = (levels, tokens, options, md, env) => {
|
|
|
400
134
|
currentHeading = null;
|
|
401
135
|
}
|
|
402
136
|
});
|
|
403
|
-
return headings;
|
|
137
|
+
return headings;
|
|
138
|
+
};
|
|
139
|
+
var findExistingIdAttr = (token) => {
|
|
140
|
+
if (token && token.attrs && token.attrs.length > 0) {
|
|
141
|
+
const idAttr = token.attrs.find((attr) => {
|
|
142
|
+
if (Array.isArray(attr) && attr.length >= 2) {
|
|
143
|
+
return attr[0] === "id";
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
});
|
|
147
|
+
if (idAttr && Array.isArray(idAttr) && idAttr.length >= 2) {
|
|
148
|
+
const [, val] = idAttr;
|
|
149
|
+
return val;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
};
|
|
154
|
+
function getMinLevel(headlineItems) {
|
|
155
|
+
return Math.min(...headlineItems.map((item) => item.level));
|
|
156
|
+
}
|
|
157
|
+
var addListItem = (level, text, anchor, rootNode) => {
|
|
158
|
+
const listItem = {
|
|
159
|
+
level,
|
|
160
|
+
text,
|
|
161
|
+
anchor,
|
|
162
|
+
children: [],
|
|
163
|
+
parent: rootNode
|
|
164
|
+
};
|
|
165
|
+
rootNode.children.push(listItem);
|
|
166
|
+
return listItem;
|
|
167
|
+
};
|
|
168
|
+
var flatHeadlineItemsToNestedTree = (headlineItems) => {
|
|
169
|
+
const toc = {
|
|
170
|
+
level: getMinLevel(headlineItems) - 1,
|
|
171
|
+
anchor: null,
|
|
172
|
+
text: null,
|
|
173
|
+
children: [],
|
|
174
|
+
parent: null
|
|
175
|
+
};
|
|
176
|
+
let currentRootNode = toc;
|
|
177
|
+
let prevListItem = currentRootNode;
|
|
178
|
+
headlineItems.forEach((headlineItem) => {
|
|
179
|
+
if (headlineItem.level > prevListItem.level) {
|
|
180
|
+
Array.from({ length: headlineItem.level - prevListItem.level }).forEach((_) => {
|
|
181
|
+
currentRootNode = prevListItem;
|
|
182
|
+
prevListItem = addListItem(headlineItem.level, null, null, currentRootNode);
|
|
183
|
+
});
|
|
184
|
+
prevListItem.text = headlineItem.markdownContent;
|
|
185
|
+
prevListItem.anchor = headlineItem.anchor;
|
|
186
|
+
} else if (headlineItem.level === prevListItem.level) {
|
|
187
|
+
prevListItem = addListItem(
|
|
188
|
+
headlineItem.level,
|
|
189
|
+
headlineItem.markdownContent,
|
|
190
|
+
headlineItem.anchor,
|
|
191
|
+
currentRootNode
|
|
192
|
+
);
|
|
193
|
+
} else if (headlineItem.level < prevListItem.level) {
|
|
194
|
+
for (let i = 0; i < prevListItem.level - headlineItem.level; i++) {
|
|
195
|
+
currentRootNode = currentRootNode.parent;
|
|
196
|
+
}
|
|
197
|
+
prevListItem = addListItem(
|
|
198
|
+
headlineItem.level,
|
|
199
|
+
headlineItem.markdownContent,
|
|
200
|
+
headlineItem.anchor,
|
|
201
|
+
currentRootNode
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return toc;
|
|
206
|
+
};
|
|
207
|
+
var tocItemToHtml = (tocItem, options, md) => {
|
|
208
|
+
return "<" + options.listType + ">" + tocItem.children.map((childItem) => {
|
|
209
|
+
let li = "<li>";
|
|
210
|
+
let anchor = childItem.anchor;
|
|
211
|
+
if (options && options.transformLink) {
|
|
212
|
+
anchor = options.transformLink(anchor);
|
|
213
|
+
}
|
|
214
|
+
let text = childItem.text ? options.format(childItem.text, md, anchor) : null;
|
|
215
|
+
li += anchor ? `<a href="#${anchor}">${text}</a>` : text || "";
|
|
216
|
+
return li + (childItem.children.length > 0 ? tocItemToHtml(childItem, options, md) : "") + "</li>";
|
|
217
|
+
}).join("") + "</" + options.listType + ">";
|
|
218
|
+
};
|
|
219
|
+
var plugin = (md, o) => {
|
|
220
|
+
const options = Object.assign({}, defaults, o);
|
|
221
|
+
const tocRegexp = options.markerPattern;
|
|
222
|
+
let gState;
|
|
223
|
+
const toc = (state, silent) => {
|
|
224
|
+
let token;
|
|
225
|
+
let match;
|
|
226
|
+
if (state.src.charCodeAt(state.pos) !== 91) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
if (silent) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
match = tocRegexp.exec(state.src.substr(state.pos));
|
|
233
|
+
match = !match ? [] : match.filter(function(m) {
|
|
234
|
+
return m;
|
|
235
|
+
});
|
|
236
|
+
if (match.length < 1) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
token = state.push("toc_open", "toc", 1);
|
|
240
|
+
token.markup = "[[toc]]";
|
|
241
|
+
token = state.push("toc_body", "", 0);
|
|
242
|
+
token = state.push("toc_close", "toc", -1);
|
|
243
|
+
const newline = state.src.indexOf("\n", state.pos);
|
|
244
|
+
if (newline !== -1) {
|
|
245
|
+
state.pos = newline;
|
|
246
|
+
} else {
|
|
247
|
+
state.pos = state.pos + state.posMax + 1;
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
};
|
|
251
|
+
md.renderer.rules.toc_open = (tokens, index) => {
|
|
252
|
+
let tocOpenHtml = '<div class="' + options.containerClass + '">';
|
|
253
|
+
if (options.containerHeaderHtml) {
|
|
254
|
+
tocOpenHtml += options.containerHeaderHtml;
|
|
255
|
+
}
|
|
256
|
+
return tocOpenHtml;
|
|
257
|
+
};
|
|
258
|
+
md.renderer.rules.toc_close = (tokens, index) => {
|
|
259
|
+
let tocFooterHtml = "";
|
|
260
|
+
if (options.containerFooterHtml) {
|
|
261
|
+
tocFooterHtml = options.containerFooterHtml;
|
|
262
|
+
}
|
|
263
|
+
return tocFooterHtml + "</div>";
|
|
264
|
+
};
|
|
265
|
+
md.renderer.rules.toc_body = (tokens, index, opt, env) => {
|
|
266
|
+
if (options.forceFullToc) {
|
|
267
|
+
throw "forceFullToc was removed in version 0.5.0. For more information, see https://github.com/Oktavilla/markdown-it-table-of-contents/pull/41";
|
|
268
|
+
} else {
|
|
269
|
+
const headlineItems = findHeadlineElements(options.includeLevel, gState.tokens, options, md, env);
|
|
270
|
+
const toc2 = flatHeadlineItemsToNestedTree(headlineItems);
|
|
271
|
+
return tocItemToHtml(toc2, options, md);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
md.core.ruler.push("grab_state", (state) => {
|
|
275
|
+
gState = state;
|
|
276
|
+
return true;
|
|
277
|
+
});
|
|
278
|
+
md.inline.ruler.after("emphasis", "toc", toc);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// src/presets/plugins/highlight-code-lines.plugin.ts
|
|
282
|
+
var LineNumbersRegex = /{([\d,\s-]+)}/;
|
|
283
|
+
var LineNumberAttrRegex = /^([\d,\s-]+)/;
|
|
284
|
+
var highlightCodeLines = (md, { enable } = {}) => {
|
|
285
|
+
const fence = md.renderer.rules.fence;
|
|
286
|
+
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
|
287
|
+
const token = tokens[idx];
|
|
288
|
+
if (enable != null && !enable(md) || token.attrs == null || token.attrs.some(([attr]) => LineNumberAttrRegex.test(attr)) === false) {
|
|
289
|
+
return fence(tokens, idx, options, env, self);
|
|
290
|
+
}
|
|
291
|
+
let highlightedLines = [];
|
|
292
|
+
try {
|
|
293
|
+
highlightedLines = Array.from(
|
|
294
|
+
new Set(
|
|
295
|
+
token.attrs.map(([attr]) => attr.split(",").map((x) => x.trim())).flat().filter((attr) => attr != null && attr.length > 0 && LineNumberAttrRegex.test(attr)).map((v) => {
|
|
296
|
+
let [start, end] = v.split(/\s*?-\s*?/).map((v2) => parseInt(v2.trim(), 10));
|
|
297
|
+
start = start > 0 ? start : 1;
|
|
298
|
+
end = end > start ? end : start;
|
|
299
|
+
const paddedArr = new Array((start > end ? start - end : end - start) + 1).fill(0);
|
|
300
|
+
paddedArr.forEach((_, idx2) => {
|
|
301
|
+
paddedArr[idx2] = start + idx2;
|
|
302
|
+
});
|
|
303
|
+
return paddedArr;
|
|
304
|
+
}).flat()
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
} catch (ex) {
|
|
308
|
+
console.warn(ex);
|
|
309
|
+
}
|
|
310
|
+
const langName = token.info.replace(LineNumbersRegex, "").trim();
|
|
311
|
+
let code = md.utils.escapeHtml(token.content);
|
|
312
|
+
code = options.highlight ? options.highlight(code, langName, "") : code;
|
|
313
|
+
const tmpToken = Object.assign(token, {
|
|
314
|
+
attrs: [
|
|
315
|
+
["class", langName ? `language-${langName}` : ""],
|
|
316
|
+
highlightedLines && highlightedLines.length > 0 ? ["data-lines-highlight", `[${highlightedLines.join(",")}]`] : []
|
|
317
|
+
]
|
|
318
|
+
});
|
|
319
|
+
const attrs = self.renderAttrs(tmpToken);
|
|
320
|
+
return `<pre${attrs}><code${attrs}>${code.trim()}</code></pre>`;
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// src/presets/plugins/meta.ts
|
|
325
|
+
var MetaPlugin = (md, { show = true } = {}) => {
|
|
326
|
+
md.block.ruler.before("hr", "meta", (state, startLine, endLine, silent) => {
|
|
327
|
+
if (startLine !== 0 || state.blkIndent !== 0) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
if (state.tShift[startLine] < 0) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
if (!state.getLines(startLine, startLine + 1, 0, false).match(/^---$/)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
let line = startLine;
|
|
337
|
+
let matchedEndLine = -1;
|
|
338
|
+
while (line < endLine) {
|
|
339
|
+
line++;
|
|
340
|
+
const str = state.getLines(line, line + 1, 0, false);
|
|
341
|
+
if (str.match(/^---$/)) {
|
|
342
|
+
matchedEndLine = line;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
if (state.tShift[line] < 0) {
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (matchedEndLine > -1) {
|
|
350
|
+
state.line = matchedEndLine + 1;
|
|
351
|
+
if (show) {
|
|
352
|
+
const token = state.push("fence", "code", 0);
|
|
353
|
+
token.content = state.getLines(startLine + 1, matchedEndLine, 0, true);
|
|
354
|
+
token.map = [startLine, matchedEndLine];
|
|
355
|
+
token.info = "yml";
|
|
356
|
+
token.markup = "---";
|
|
357
|
+
token.attrPush(["data-yaml-metadata", ""]);
|
|
358
|
+
}
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
return false;
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/presets/plugins/unique-custom-id.ts
|
|
366
|
+
var attrPluginName = "curly_attributes";
|
|
367
|
+
var uniqueCustomIdAttr = (state) => {
|
|
368
|
+
const { tokens } = state;
|
|
369
|
+
let map;
|
|
370
|
+
tokens.filter((x) => !!x.attrGet("id")).forEach((token) => {
|
|
371
|
+
map != null ? map : map = {};
|
|
372
|
+
const idAttrValue = token.attrGet("id");
|
|
373
|
+
if (map.hasOwnProperty(idAttrValue)) {
|
|
374
|
+
const count = map[idAttrValue];
|
|
375
|
+
token.attrSet("id", `${idAttrValue}-${count}`);
|
|
376
|
+
map[idAttrValue] = count + 1;
|
|
377
|
+
} else {
|
|
378
|
+
map[idAttrValue] = 1;
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
map = void 0;
|
|
404
382
|
};
|
|
405
|
-
var
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
383
|
+
var plugin2 = (md, opt) => {
|
|
384
|
+
if (md.core.ruler.getRules("").some((x) => x.name === attrPluginName) != null) {
|
|
385
|
+
md.core.ruler.after(attrPluginName, "unique_custom_id_attribute", uniqueCustomIdAttr, opt);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/presets/plugins/multiline-blockquote/multiline-blockquote.rule.ts
|
|
390
|
+
var MultilineBlockquoteRule = (state, startLine, endLine) => {
|
|
391
|
+
let nextLine, token;
|
|
392
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
393
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
let marker = state.src.charCodeAt(pos);
|
|
397
|
+
if (marker !== 62) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
let markerLength = state.skipChars(pos, marker) - pos;
|
|
401
|
+
if (markerLength !== 3)
|
|
402
|
+
return false;
|
|
403
|
+
if (state.src.charCodeAt(state.skipChars(
|
|
404
|
+
pos + markerLength,
|
|
405
|
+
32
|
|
406
|
+
/* ' ' */
|
|
407
|
+
)) !== 10) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
nextLine = startLine + 1;
|
|
411
|
+
while (nextLine < endLine) {
|
|
412
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
413
|
+
marker = state.src.charCodeAt(pos);
|
|
414
|
+
if (marker === 62 && (markerLength = state.skipChars(pos, marker) - pos) === 3) {
|
|
415
|
+
pos = state.skipChars(pos + markerLength, 32);
|
|
416
|
+
if (pos >= state.src.length || state.src.charCodeAt(pos) === 10)
|
|
417
|
+
break;
|
|
416
418
|
}
|
|
419
|
+
nextLine++;
|
|
417
420
|
}
|
|
418
|
-
|
|
421
|
+
if (nextLine > endLine) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
token = state.push("multiline_blockquote_open", "blockquote", 1);
|
|
425
|
+
token.markup = ">>>";
|
|
426
|
+
token.map = [startLine, 0];
|
|
427
|
+
state.md.block.tokenize(state, startLine + 1, nextLine);
|
|
428
|
+
token = state.push("multiline_blockquote_close", "blockquote", -1);
|
|
429
|
+
token.map = [nextLine, 0];
|
|
430
|
+
state.line = nextLine + 1;
|
|
431
|
+
return true;
|
|
419
432
|
};
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
parent: rootNode
|
|
430
|
-
};
|
|
431
|
-
rootNode.children.push(listItem);
|
|
432
|
-
return listItem;
|
|
433
|
+
|
|
434
|
+
// src/presets/plugins/multiline-blockquote/multiline-blockquote.plugin.ts
|
|
435
|
+
var MultilineBlockquotePlugin = (md, options) => {
|
|
436
|
+
options != null ? options : options = {};
|
|
437
|
+
md.block.ruler.before("blockquote", "multiline_blockquote", (...args) => {
|
|
438
|
+
if (options.enable != null && !options.enable(md))
|
|
439
|
+
return false;
|
|
440
|
+
return MultilineBlockquoteRule.apply(void 0, args);
|
|
441
|
+
});
|
|
433
442
|
};
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
443
|
+
|
|
444
|
+
// src/presets/plugins/simple-math.plugin.ts
|
|
445
|
+
function isValidDelimiter(state, pos) {
|
|
446
|
+
let max = state.posMax;
|
|
447
|
+
let canOpen = true;
|
|
448
|
+
let canClose = true;
|
|
449
|
+
let prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
450
|
+
let nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
451
|
+
if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
|
|
452
|
+
canClose = false;
|
|
453
|
+
}
|
|
454
|
+
if (nextChar === 32 || nextChar === 9) {
|
|
455
|
+
canOpen = false;
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
canOpen,
|
|
459
|
+
canClose
|
|
441
460
|
};
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
headlineItem.markdownContent,
|
|
456
|
-
headlineItem.anchor,
|
|
457
|
-
currentRootNode
|
|
458
|
-
);
|
|
459
|
-
} else if (headlineItem.level < prevListItem.level) {
|
|
460
|
-
for (let i = 0; i < prevListItem.level - headlineItem.level; i++) {
|
|
461
|
-
currentRootNode = currentRootNode.parent;
|
|
462
|
-
}
|
|
463
|
-
prevListItem = addListItem(
|
|
464
|
-
headlineItem.level,
|
|
465
|
-
headlineItem.markdownContent,
|
|
466
|
-
headlineItem.anchor,
|
|
467
|
-
currentRootNode
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
return toc;
|
|
461
|
+
}
|
|
462
|
+
var mathInTable = (state) => {
|
|
463
|
+
const { src } = state;
|
|
464
|
+
const regex = /(\|.*\|)\n(\|\s*?-+:?\s*?)+\|\n(\|.*\|\n?)*?((\|.*?\$+.*\n?)+)/g;
|
|
465
|
+
const inlineMathRegex = /\$(.*?)\$/g;
|
|
466
|
+
state.src = src.replace(
|
|
467
|
+
regex,
|
|
468
|
+
(match, sub1, sub2, sub3, sub4) => match.replace(
|
|
469
|
+
sub4,
|
|
470
|
+
sub4.replace(inlineMathRegex, (match2, sub) => `$${sub.replace(/\\*?\|/g, "\\|")}$$`)
|
|
471
|
+
)
|
|
472
|
+
);
|
|
473
|
+
return true;
|
|
472
474
|
};
|
|
473
|
-
var
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
475
|
+
var mathInline = (state, silent) => {
|
|
476
|
+
let start, match, token, res, pos;
|
|
477
|
+
if (state.src[state.pos] !== "$") {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
res = isValidDelimiter(state, state.pos);
|
|
481
|
+
if (!res.canOpen) {
|
|
482
|
+
if (!silent) {
|
|
483
|
+
state.pending += "$";
|
|
479
484
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const toc = (state, silent) => {
|
|
490
|
-
let token;
|
|
491
|
-
let match;
|
|
492
|
-
if (state.src.charCodeAt(state.pos) !== 91) {
|
|
493
|
-
return false;
|
|
485
|
+
state.pos += 1;
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
start = state.pos + 1;
|
|
489
|
+
match = start;
|
|
490
|
+
while ((match = state.src.indexOf("$", match)) !== -1) {
|
|
491
|
+
pos = match - 1;
|
|
492
|
+
while (state.src[pos] === "\\") {
|
|
493
|
+
pos -= 1;
|
|
494
494
|
}
|
|
495
|
-
if (
|
|
496
|
-
|
|
495
|
+
if ((match - pos) % 2 == 1) {
|
|
496
|
+
break;
|
|
497
497
|
}
|
|
498
|
-
match
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
return false;
|
|
498
|
+
match += 1;
|
|
499
|
+
}
|
|
500
|
+
if (match === -1) {
|
|
501
|
+
if (!silent) {
|
|
502
|
+
state.pending += "$";
|
|
504
503
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
504
|
+
state.pos = start;
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
if (match - start === 0) {
|
|
508
|
+
if (!silent) {
|
|
509
|
+
state.pending += "$$";
|
|
510
|
+
}
|
|
511
|
+
state.pos = start + 1;
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
res = isValidDelimiter(state, match);
|
|
515
|
+
if (!res.canClose) {
|
|
516
|
+
if (!silent) {
|
|
517
|
+
state.pending += "$";
|
|
514
518
|
}
|
|
519
|
+
state.pos = start;
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
if (!silent) {
|
|
523
|
+
token = state.push("math_inline", "math", 0);
|
|
524
|
+
token.markup = "$";
|
|
525
|
+
token.content = state.src.slice(start, match);
|
|
526
|
+
}
|
|
527
|
+
state.pos = match + 1;
|
|
528
|
+
return true;
|
|
529
|
+
};
|
|
530
|
+
var mathBlock = (state, start, end, silent) => {
|
|
531
|
+
let lastLine;
|
|
532
|
+
let next;
|
|
533
|
+
let lastPos;
|
|
534
|
+
let found = false;
|
|
535
|
+
let token;
|
|
536
|
+
let pos = state.bMarks[start] + state.tShift[start];
|
|
537
|
+
let max = state.eMarks[start];
|
|
538
|
+
if (pos + 2 > max) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
if (state.src[pos] !== "$" || state.src[pos + 1] !== "$") {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
pos += 2;
|
|
545
|
+
if (silent) {
|
|
515
546
|
return true;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
547
|
+
}
|
|
548
|
+
let firstLine = state.src.slice(pos, max);
|
|
549
|
+
if (firstLine.trim().slice(-2) === "$$") {
|
|
550
|
+
firstLine = firstLine.trim().slice(0, -2);
|
|
551
|
+
found = true;
|
|
552
|
+
}
|
|
553
|
+
for (next = start; !found; ) {
|
|
554
|
+
next++;
|
|
555
|
+
if (next >= end) {
|
|
556
|
+
break;
|
|
521
557
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (options.containerFooterHtml) {
|
|
527
|
-
tocFooterHtml = options.containerFooterHtml;
|
|
558
|
+
pos = state.bMarks[next] + state.tShift[next];
|
|
559
|
+
max = state.eMarks[next];
|
|
560
|
+
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
561
|
+
break;
|
|
528
562
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
throw "forceFullToc was removed in version 0.5.0. For more information, see https://github.com/Oktavilla/markdown-it-table-of-contents/pull/41";
|
|
534
|
-
} else {
|
|
535
|
-
const headlineItems = findHeadlineElements(options.includeLevel, gState.tokens, options, md, env);
|
|
536
|
-
const toc2 = flatHeadlineItemsToNestedTree(headlineItems);
|
|
537
|
-
return tocItemToHtml(toc2, options, md);
|
|
563
|
+
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
564
|
+
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
565
|
+
lastLine = state.src.slice(pos, lastPos);
|
|
566
|
+
found = true;
|
|
538
567
|
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
568
|
+
}
|
|
569
|
+
state.line = next + 1;
|
|
570
|
+
token = state.push("math_block", "math", 0);
|
|
571
|
+
token.block = true;
|
|
572
|
+
token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
|
|
573
|
+
token.map = [start, state.line];
|
|
574
|
+
token.markup = "$$";
|
|
575
|
+
return true;
|
|
576
|
+
};
|
|
577
|
+
var simpleMathPlugin = (md) => {
|
|
578
|
+
md.core.ruler.before("block", "math_in_table", mathInTable);
|
|
579
|
+
md.inline.ruler.after("escape", "math_inline", mathInline);
|
|
580
|
+
md.block.ruler.after("blockquote", "math_block", mathBlock, {
|
|
581
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
543
582
|
});
|
|
544
|
-
|
|
583
|
+
const simpleInlineRenderer = (tokens, idx) => {
|
|
584
|
+
return '<span class="math inline">\\(' + md.utils.escapeHtml(tokens[idx].content) + "\\)</span>";
|
|
585
|
+
};
|
|
586
|
+
const simpleBlockRenderer = (tokens, idx) => {
|
|
587
|
+
return '<p><div class="math display">\\[' + md.utils.escapeHtml(tokens[idx].content) + "\\]</div></p>";
|
|
588
|
+
};
|
|
589
|
+
md.renderer.rules.math_inline = simpleInlineRenderer;
|
|
590
|
+
md.renderer.rules.math_block = simpleBlockRenderer;
|
|
545
591
|
};
|
|
546
592
|
|
|
547
|
-
// src/presets/plugins/
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
md.renderer.rules.fence
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
highlightedLines = Array.from(
|
|
560
|
-
new Set(
|
|
561
|
-
token.attrs.map(([attr]) => attr.split(",").map((x) => x.trim())).flat().filter((attr) => attr != null && attr.length > 0 && LineNumberAttrRegex.test(attr)).map((v) => {
|
|
562
|
-
let [start, end] = v.split(/\s*?-\s*?/).map((v2) => parseInt(v2.trim(), 10));
|
|
563
|
-
start = start > 0 ? start : 1;
|
|
564
|
-
end = end > start ? end : start;
|
|
565
|
-
const paddedArr = new Array((start > end ? start - end : end - start) + 1).fill(0);
|
|
566
|
-
paddedArr.forEach((_, idx2) => {
|
|
567
|
-
paddedArr[idx2] = start + idx2;
|
|
568
|
-
});
|
|
569
|
-
return paddedArr;
|
|
570
|
-
}).flat()
|
|
571
|
-
)
|
|
572
|
-
);
|
|
573
|
-
} catch (ex) {
|
|
574
|
-
console.warn(ex);
|
|
593
|
+
// src/presets/plugins/simple-mermaid.plugin.ts
|
|
594
|
+
function diagramPlugin(md, options) {
|
|
595
|
+
function getLangName(info) {
|
|
596
|
+
return info.split(/\s+/g)[0];
|
|
597
|
+
}
|
|
598
|
+
let defaultFenceRenderer = md.renderer.rules.fence;
|
|
599
|
+
function customFenceRenderer(tokens, idx, options2, env, slf) {
|
|
600
|
+
let token = tokens[idx];
|
|
601
|
+
let info = token.info.trim();
|
|
602
|
+
let langName = info ? getLangName(info) : "";
|
|
603
|
+
if (langName.toLowerCase() === "mermaid") {
|
|
604
|
+
return '<div class="mermaid">' + md.utils.escapeHtml(token.content) + "</div>";
|
|
575
605
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
606
|
+
return defaultFenceRenderer(tokens, idx, options2, env, slf);
|
|
607
|
+
}
|
|
608
|
+
md.renderer.rules.fence = customFenceRenderer;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/presets/plugins/imsize/helpers/parse_image_size.ts
|
|
612
|
+
function parseNextNumber(str, pos, max) {
|
|
613
|
+
let code, start = pos, result = {
|
|
614
|
+
ok: false,
|
|
615
|
+
pos,
|
|
616
|
+
value: ""
|
|
587
617
|
};
|
|
588
|
-
|
|
618
|
+
code = str.charCodeAt(pos);
|
|
619
|
+
while (pos < max && code >= 48 && code <= 57 || code === 37) {
|
|
620
|
+
code = str.charCodeAt(++pos);
|
|
621
|
+
}
|
|
622
|
+
result.ok = true;
|
|
623
|
+
result.pos = pos;
|
|
624
|
+
result.value = str.slice(start, pos);
|
|
625
|
+
return result;
|
|
626
|
+
}
|
|
627
|
+
function parseImageSize(str, pos, max) {
|
|
628
|
+
let code, result = {
|
|
629
|
+
ok: false,
|
|
630
|
+
pos: 0,
|
|
631
|
+
width: "",
|
|
632
|
+
height: ""
|
|
633
|
+
};
|
|
634
|
+
if (pos >= max) {
|
|
635
|
+
return result;
|
|
636
|
+
}
|
|
637
|
+
code = str.charCodeAt(pos);
|
|
638
|
+
if (code !== 61) {
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
641
|
+
pos++;
|
|
642
|
+
code = str.charCodeAt(pos);
|
|
643
|
+
if (code !== 120 && (code < 48 || code > 57)) {
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
const resultW = parseNextNumber(str, pos, max);
|
|
647
|
+
pos = resultW.pos;
|
|
648
|
+
code = str.charCodeAt(pos);
|
|
649
|
+
if (code !== 120) {
|
|
650
|
+
return result;
|
|
651
|
+
}
|
|
652
|
+
pos++;
|
|
653
|
+
const resultH = parseNextNumber(str, pos, max);
|
|
654
|
+
pos = resultH.pos;
|
|
655
|
+
result.width = resultW.value;
|
|
656
|
+
result.height = resultH.value;
|
|
657
|
+
result.pos = pos;
|
|
658
|
+
result.ok = true;
|
|
659
|
+
return result;
|
|
660
|
+
}
|
|
589
661
|
|
|
590
|
-
// src/presets/plugins/
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
662
|
+
// src/presets/plugins/imsize/index.ts
|
|
663
|
+
function image_with_size(md, options) {
|
|
664
|
+
return function(state, silent) {
|
|
665
|
+
let attrs, code, label, labelEnd, labelStart, pos, ref, res, title, width = "", height = "", token, tokens, start, href = "", oldPos = state.pos, max = state.posMax;
|
|
666
|
+
if (state.src.charCodeAt(state.pos) !== 33) {
|
|
594
667
|
return false;
|
|
595
668
|
}
|
|
596
|
-
if (state.
|
|
669
|
+
if (state.src.charCodeAt(state.pos + 1) !== 91) {
|
|
597
670
|
return false;
|
|
598
671
|
}
|
|
599
|
-
|
|
672
|
+
labelStart = state.pos + 2;
|
|
673
|
+
labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
|
|
674
|
+
if (labelEnd < 0) {
|
|
600
675
|
return false;
|
|
601
676
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
677
|
+
pos = labelEnd + 1;
|
|
678
|
+
if (pos < max && state.src.charCodeAt(pos) === 40) {
|
|
679
|
+
pos++;
|
|
680
|
+
for (; pos < max; pos++) {
|
|
681
|
+
code = state.src.charCodeAt(pos);
|
|
682
|
+
if (code !== 32 && code !== 10) {
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
610
685
|
}
|
|
611
|
-
if (
|
|
612
|
-
|
|
686
|
+
if (pos >= max) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
start = pos;
|
|
690
|
+
res = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
691
|
+
if (res.ok) {
|
|
692
|
+
href = state.md.normalizeLink(res.str);
|
|
693
|
+
if (state.md.validateLink(href)) {
|
|
694
|
+
pos = res.pos;
|
|
695
|
+
} else {
|
|
696
|
+
href = "";
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
start = pos;
|
|
700
|
+
for (; pos < max; pos++) {
|
|
701
|
+
code = state.src.charCodeAt(pos);
|
|
702
|
+
if (code !== 32 && code !== 10) {
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
res = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
|
|
707
|
+
if (pos < max && start !== pos && res.ok) {
|
|
708
|
+
title = res.str;
|
|
709
|
+
pos = res.pos;
|
|
710
|
+
for (; pos < max; pos++) {
|
|
711
|
+
code = state.src.charCodeAt(pos);
|
|
712
|
+
if (code !== 32 && code !== 10) {
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
} else {
|
|
717
|
+
title = "";
|
|
613
718
|
}
|
|
719
|
+
if (pos - 1 >= 0) {
|
|
720
|
+
code = state.src.charCodeAt(pos - 1);
|
|
721
|
+
if (code === 32) {
|
|
722
|
+
res = parseImageSize(state.src, pos, state.posMax);
|
|
723
|
+
if (res.ok) {
|
|
724
|
+
width = res.width;
|
|
725
|
+
height = res.height;
|
|
726
|
+
pos = res.pos;
|
|
727
|
+
for (; pos < max; pos++) {
|
|
728
|
+
code = state.src.charCodeAt(pos);
|
|
729
|
+
if (code !== 32 && code !== 10) {
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (pos >= max || state.src.charCodeAt(pos) !== 41) {
|
|
737
|
+
state.pos = oldPos;
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
pos++;
|
|
741
|
+
} else {
|
|
742
|
+
if (typeof state.env.references === "undefined") {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
for (; pos < max; pos++) {
|
|
746
|
+
code = state.src.charCodeAt(pos);
|
|
747
|
+
if (code !== 32 && code !== 10) {
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (pos < max && state.src.charCodeAt(pos) === 91) {
|
|
752
|
+
start = pos + 1;
|
|
753
|
+
pos = md.helpers.parseLinkLabel(state, pos);
|
|
754
|
+
if (pos >= 0) {
|
|
755
|
+
label = state.src.slice(start, pos++);
|
|
756
|
+
} else {
|
|
757
|
+
pos = labelEnd + 1;
|
|
758
|
+
}
|
|
759
|
+
} else {
|
|
760
|
+
pos = labelEnd + 1;
|
|
761
|
+
}
|
|
762
|
+
if (!label) {
|
|
763
|
+
label = state.src.slice(labelStart, labelEnd);
|
|
764
|
+
}
|
|
765
|
+
ref = state.env.references[md.utils.normalizeReference(label)];
|
|
766
|
+
if (!ref) {
|
|
767
|
+
state.pos = oldPos;
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
href = ref.href;
|
|
771
|
+
title = ref.title;
|
|
614
772
|
}
|
|
615
|
-
if (
|
|
616
|
-
state.
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
773
|
+
if (!silent) {
|
|
774
|
+
state.pos = labelStart;
|
|
775
|
+
state.posMax = labelEnd;
|
|
776
|
+
const newState = new state.md.inline.State(
|
|
777
|
+
state.src.slice(labelStart, labelEnd),
|
|
778
|
+
state.md,
|
|
779
|
+
state.env,
|
|
780
|
+
tokens = []
|
|
781
|
+
);
|
|
782
|
+
newState.md.inline.tokenize(newState);
|
|
783
|
+
token = state.push("image", "img", 0);
|
|
784
|
+
token.attrs = attrs = [
|
|
785
|
+
["src", href],
|
|
786
|
+
["alt", ""]
|
|
787
|
+
];
|
|
788
|
+
token.children = tokens;
|
|
789
|
+
if (title) {
|
|
790
|
+
attrs.push(["title", title]);
|
|
791
|
+
}
|
|
792
|
+
if (width !== "") {
|
|
793
|
+
attrs.push(["width", width]);
|
|
794
|
+
}
|
|
795
|
+
if (height !== "") {
|
|
796
|
+
attrs.push(["height", height]);
|
|
624
797
|
}
|
|
625
|
-
return true;
|
|
626
798
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
799
|
+
state.pos = pos;
|
|
800
|
+
state.posMax = max;
|
|
801
|
+
return true;
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
function ImageSizePlugin(md, options) {
|
|
805
|
+
md.inline.ruler.before("emphasis", "image", image_with_size(md, options));
|
|
806
|
+
}
|
|
630
807
|
|
|
631
|
-
// src/presets/plugins/
|
|
632
|
-
var
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (map.hasOwnProperty(idAttrValue)) {
|
|
640
|
-
const count = map[idAttrValue];
|
|
641
|
-
token.attrSet("id", `${idAttrValue}-${count}`);
|
|
642
|
-
map[idAttrValue] = count + 1;
|
|
643
|
-
} else {
|
|
644
|
-
map[idAttrValue] = 1;
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
map = void 0;
|
|
648
|
-
};
|
|
649
|
-
var plugin2 = (md, opt) => {
|
|
650
|
-
if (md.core.ruler.getRules("").some((x) => x.name === attrPluginName) != null) {
|
|
651
|
-
md.core.ruler.after(attrPluginName, "unique_custom_id_attribute", uniqueCustomIdAttr, opt);
|
|
808
|
+
// src/presets/plugins/html-filter.plugin.ts
|
|
809
|
+
var tagFilterRules = {
|
|
810
|
+
title: { rule: "escape" },
|
|
811
|
+
head: { rule: "escape" },
|
|
812
|
+
body: { rule: "escape" },
|
|
813
|
+
img: {
|
|
814
|
+
rule: "filterAttributes",
|
|
815
|
+
disabledAttributes: ["onerror"]
|
|
652
816
|
}
|
|
653
817
|
};
|
|
818
|
+
var HtmlFilterPlugin = (md) => {
|
|
819
|
+
const defaultHtmlBlock = md.renderer.rules.html_block;
|
|
820
|
+
md.renderer.rules.html_block = (tokens, idx, options, env, self) => {
|
|
821
|
+
const token = tokens[idx];
|
|
822
|
+
if (token.type === "html_block" && !token.tag) {
|
|
823
|
+
let { content } = token;
|
|
824
|
+
for (let tagName in tagFilterRules) {
|
|
825
|
+
const rule = tagFilterRules[tagName];
|
|
826
|
+
const { rule: handleStrategy, disabledAttributes } = rule;
|
|
827
|
+
if (handleStrategy === "escape") {
|
|
828
|
+
const start = `<${tagName}>`;
|
|
829
|
+
const end = `</${tagName}>`;
|
|
830
|
+
const matchStart = content.replace(new RegExp("\n", "g"), "").startsWith(start);
|
|
831
|
+
const matchEnd = content.replace(new RegExp("\n", "g"), "").endsWith(end);
|
|
832
|
+
if (matchStart || matchEnd) {
|
|
833
|
+
content = md.utils.escapeHtml(content);
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
} else if (handleStrategy === "filterAttributes" && disabledAttributes != null && disabledAttributes.length > 0) {
|
|
837
|
+
for (let attribute of disabledAttributes) {
|
|
838
|
+
content = content.replace(
|
|
839
|
+
new RegExp(`(<${tagName}.*? +)(${attribute}=)(.*?>)`, "ig"),
|
|
840
|
+
(match, p1, p2, p3) => p1 + "data-" + p2 + p3
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (content !== token.content)
|
|
846
|
+
return content;
|
|
847
|
+
}
|
|
848
|
+
return defaultHtmlBlock(tokens, idx, options, env, self);
|
|
849
|
+
};
|
|
850
|
+
};
|
|
654
851
|
|
|
655
852
|
// src/presets/index.ts
|
|
656
853
|
var mdUtils = new import_markdown_it.default().utils;
|
|
@@ -688,7 +885,8 @@ var markdownItFactory = ({
|
|
|
688
885
|
linkify: linkifyOption,
|
|
689
886
|
preserveLineBreaks,
|
|
690
887
|
enableMarkdownAttrs,
|
|
691
|
-
showFrontMatter
|
|
888
|
+
showFrontMatter,
|
|
889
|
+
enableImageSize
|
|
692
890
|
} = defaultMarkdownItOption) => {
|
|
693
891
|
const mdOpt = {
|
|
694
892
|
html,
|
|
@@ -713,6 +911,9 @@ var markdownItFactory = ({
|
|
|
713
911
|
if (disableRules && disableRules.length > 0) {
|
|
714
912
|
md.disable(disableRules);
|
|
715
913
|
}
|
|
914
|
+
if (enableImageSize == null || enableImageSize) {
|
|
915
|
+
md.use(ImageSizePlugin);
|
|
916
|
+
}
|
|
716
917
|
const { normalize: defaultNormalize } = md.linkify.set(linkifyOption);
|
|
717
918
|
if (linkifyOption.fuzzyLink && linkifyOption.fuzzyLinkUseHttps) {
|
|
718
919
|
md.linkify.normalize = (match) => {
|