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