rapier-html 1.2.46 → 1.2.49
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/BUILD.json +4 -4
- package/README.md +12 -11
- package/dist/ledger/carried.mjs +17 -8
- package/dist/ledger/diff/concerns.mjs +2 -2
- package/dist/ledger/document-fonts.mjs +60 -6
- package/dist/ledger/source.mjs +31 -2
- package/dist/ledger/vendor/SOURCES.json +253 -0
- package/dist/ledger/vendor/entities/decode-codepoint.mjs +27 -0
- package/dist/ledger/vendor/entities.mjs +499 -0
- package/dist/ledger/vendor/linkify-it.mjs +427 -0
- package/dist/ledger/vendor/markdown-it.mjs +4027 -0
- package/dist/ledger/vendor/markdown-plugins.mjs +1328 -11
- package/dist/ledger/vendor/markdown-runtime.mjs +3 -11
- package/dist/ledger/vendor/mdurl/index.mjs +11 -0
- package/dist/ledger/vendor/mdurl/lib/decode.mjs +107 -0
- package/dist/ledger/vendor/mdurl/lib/encode.mjs +77 -0
- package/dist/ledger/vendor/mdurl/lib/format.mjs +20 -0
- package/dist/ledger/vendor/mdurl/lib/parse.mjs +231 -0
- package/dist/ledger/vendor/punycode.mjs +282 -0
- package/dist/ledger/vendor/uc.micro.mjs +49 -0
- package/dist/page.mjs +11 -3
- package/dist/rapier.html +97 -51
- package/dist/wrap.mjs +10 -5
- package/package.json +1 -1
- package/dist/ledger/vendor/BROWSER-ENTITIES.json +0 -36
- package/dist/ledger/vendor/MARKDOWN-RUNTIME.json +0 -136
- package/dist/ledger/vendor/MARKDOWNIT.json +0 -582
- package/dist/ledger/vendor/markdown-plugins.json +0 -46
|
@@ -0,0 +1,4027 @@
|
|
|
1
|
+
/*! markdown-it 15.0.3 https://github.com/markdown-it/markdown-it @license MIT */
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
var utils_exports = {};
|
|
9
|
+
__export(utils_exports, {
|
|
10
|
+
arrayReplaceAt: () => arrayReplaceAt,
|
|
11
|
+
asciiTrim: () => asciiTrim,
|
|
12
|
+
callable: () => callable,
|
|
13
|
+
escapeHtml: () => escapeHtml,
|
|
14
|
+
escapeRE: () => escapeRE,
|
|
15
|
+
fromCodePoint: () => fromCodePoint,
|
|
16
|
+
isMdAsciiPunct: () => isMdAsciiPunct,
|
|
17
|
+
isPunctChar: () => isPunctChar,
|
|
18
|
+
isPunctCharCode: () => isPunctCharCode,
|
|
19
|
+
isSpace: () => isSpace,
|
|
20
|
+
isValidEntityCode: () => isValidEntityCode,
|
|
21
|
+
isWhiteSpace: () => isWhiteSpace,
|
|
22
|
+
lib: () => lib,
|
|
23
|
+
normalizeReference: () => normalizeReference,
|
|
24
|
+
unescapeAll: () => unescapeAll,
|
|
25
|
+
unescapeMd: () => unescapeMd
|
|
26
|
+
});
|
|
27
|
+
import * as mdurl from "./mdurl/index.mjs";
|
|
28
|
+
import * as ucmicro from "./uc.micro.mjs";
|
|
29
|
+
import { decodeHTMLStrict } from "./entities.mjs";
|
|
30
|
+
function callable(cls) {
|
|
31
|
+
const wrapper = function(...args) {
|
|
32
|
+
const newTarget = new.target && new.target !== wrapper ? new.target : cls;
|
|
33
|
+
return Reflect.construct(cls, args, newTarget);
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(wrapper, "name", { value: cls.name });
|
|
36
|
+
Object.setPrototypeOf(wrapper, cls);
|
|
37
|
+
wrapper.prototype = cls.prototype;
|
|
38
|
+
return wrapper;
|
|
39
|
+
}
|
|
40
|
+
function arrayReplaceAt(src, pos, newElements) {
|
|
41
|
+
return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1));
|
|
42
|
+
}
|
|
43
|
+
function isValidEntityCode(c) {
|
|
44
|
+
if (c >= 55296 && c <= 57343) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (c >= 64976 && c <= 65007) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if ((c & 65535) === 65535 || (c & 65535) === 65534) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (c >= 0 && c <= 8) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (c === 11) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (c >= 14 && c <= 31) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (c >= 127 && c <= 159) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (c > 1114111) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
function fromCodePoint(c) {
|
|
71
|
+
if (c > 65535) {
|
|
72
|
+
c -= 65536;
|
|
73
|
+
const surrogate1 = 55296 + (c >> 10);
|
|
74
|
+
const surrogate2 = 56320 + (c & 1023);
|
|
75
|
+
return String.fromCharCode(surrogate1, surrogate2);
|
|
76
|
+
}
|
|
77
|
+
return String.fromCharCode(c);
|
|
78
|
+
}
|
|
79
|
+
var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
|
|
80
|
+
var ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi;
|
|
81
|
+
var UNESCAPE_ALL_RE = new RegExp(`${UNESCAPE_MD_RE.source}|${ENTITY_RE.source}`, "gi");
|
|
82
|
+
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i;
|
|
83
|
+
function replaceEntityPattern(match, name) {
|
|
84
|
+
if (name.charCodeAt(0) === 35 && DIGITAL_ENTITY_TEST_RE.test(name)) {
|
|
85
|
+
const code2 = name[1].toLowerCase() === "x" ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10);
|
|
86
|
+
if (isValidEntityCode(code2)) {
|
|
87
|
+
return fromCodePoint(code2);
|
|
88
|
+
}
|
|
89
|
+
return match;
|
|
90
|
+
}
|
|
91
|
+
const decoded = decodeHTMLStrict(match);
|
|
92
|
+
if (decoded !== match) {
|
|
93
|
+
return decoded;
|
|
94
|
+
}
|
|
95
|
+
return match;
|
|
96
|
+
}
|
|
97
|
+
function unescapeMd(str) {
|
|
98
|
+
if (str.indexOf("\\") < 0) {
|
|
99
|
+
return str;
|
|
100
|
+
}
|
|
101
|
+
return str.replace(UNESCAPE_MD_RE, "$1");
|
|
102
|
+
}
|
|
103
|
+
function unescapeAll(str) {
|
|
104
|
+
if (str.indexOf("\\") < 0 && str.indexOf("&") < 0) {
|
|
105
|
+
return str;
|
|
106
|
+
}
|
|
107
|
+
return str.replace(UNESCAPE_ALL_RE, function(match, escaped, entity2) {
|
|
108
|
+
if (escaped) {
|
|
109
|
+
return escaped;
|
|
110
|
+
}
|
|
111
|
+
return replaceEntityPattern(match, entity2);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
var HTML_ESCAPE_TEST_RE = /[&<>"]/;
|
|
115
|
+
var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
|
|
116
|
+
var HTML_REPLACEMENTS = {
|
|
117
|
+
"&": "&",
|
|
118
|
+
"<": "<",
|
|
119
|
+
">": ">",
|
|
120
|
+
'"': """
|
|
121
|
+
};
|
|
122
|
+
function replaceUnsafeChar(ch) {
|
|
123
|
+
return HTML_REPLACEMENTS[ch];
|
|
124
|
+
}
|
|
125
|
+
function escapeHtml(str) {
|
|
126
|
+
if (HTML_ESCAPE_TEST_RE.test(str)) {
|
|
127
|
+
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
|
|
128
|
+
}
|
|
129
|
+
return str;
|
|
130
|
+
}
|
|
131
|
+
var REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g;
|
|
132
|
+
function escapeRE(str) {
|
|
133
|
+
return str.replace(REGEXP_ESCAPE_RE, "\\$&");
|
|
134
|
+
}
|
|
135
|
+
function isSpace(code2) {
|
|
136
|
+
switch (code2) {
|
|
137
|
+
case 9:
|
|
138
|
+
case 32:
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
function isWhiteSpace(code2) {
|
|
144
|
+
if (code2 >= 8192 && code2 <= 8202) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
switch (code2) {
|
|
148
|
+
case 9:
|
|
149
|
+
case 10:
|
|
150
|
+
case 11:
|
|
151
|
+
case 12:
|
|
152
|
+
case 13:
|
|
153
|
+
case 32:
|
|
154
|
+
case 160:
|
|
155
|
+
case 5760:
|
|
156
|
+
case 8239:
|
|
157
|
+
case 8287:
|
|
158
|
+
case 12288:
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
function isPunctChar(ch) {
|
|
164
|
+
return ucmicro.P.test(ch) || ucmicro.S.test(ch);
|
|
165
|
+
}
|
|
166
|
+
function isPunctCharCode(code2) {
|
|
167
|
+
return isPunctChar(fromCodePoint(code2));
|
|
168
|
+
}
|
|
169
|
+
function isMdAsciiPunct(ch) {
|
|
170
|
+
switch (ch) {
|
|
171
|
+
case 33:
|
|
172
|
+
case 34:
|
|
173
|
+
case 35:
|
|
174
|
+
case 36:
|
|
175
|
+
case 37:
|
|
176
|
+
case 38:
|
|
177
|
+
case 39:
|
|
178
|
+
case 40:
|
|
179
|
+
case 41:
|
|
180
|
+
case 42:
|
|
181
|
+
case 43:
|
|
182
|
+
case 44:
|
|
183
|
+
case 45:
|
|
184
|
+
case 46:
|
|
185
|
+
case 47:
|
|
186
|
+
case 58:
|
|
187
|
+
case 59:
|
|
188
|
+
case 60:
|
|
189
|
+
case 61:
|
|
190
|
+
case 62:
|
|
191
|
+
case 63:
|
|
192
|
+
case 64:
|
|
193
|
+
case 91:
|
|
194
|
+
case 92:
|
|
195
|
+
case 93:
|
|
196
|
+
case 94:
|
|
197
|
+
case 95:
|
|
198
|
+
case 96:
|
|
199
|
+
case 123:
|
|
200
|
+
case 124:
|
|
201
|
+
case 125:
|
|
202
|
+
case 126:
|
|
203
|
+
return true;
|
|
204
|
+
default:
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function normalizeReference(str) {
|
|
209
|
+
str = str.trim().replace(/\s+/g, " ");
|
|
210
|
+
return str.toLowerCase().toUpperCase();
|
|
211
|
+
}
|
|
212
|
+
function isAsciiTrimmable(c) {
|
|
213
|
+
return c === 32 || c === 9 || c === 10 || c === 13;
|
|
214
|
+
}
|
|
215
|
+
function asciiTrim(str) {
|
|
216
|
+
let start = 0;
|
|
217
|
+
for (; start < str.length; start++) {
|
|
218
|
+
if (!isAsciiTrimmable(str.charCodeAt(start))) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let end = str.length - 1;
|
|
223
|
+
for (; end >= start; end--) {
|
|
224
|
+
if (!isAsciiTrimmable(str.charCodeAt(end))) {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return str.slice(start, end + 1);
|
|
229
|
+
}
|
|
230
|
+
var lib = { mdurl, ucmicro };
|
|
231
|
+
|
|
232
|
+
var helpers_exports = {};
|
|
233
|
+
__export(helpers_exports, {
|
|
234
|
+
parseLinkDestination: () => parseLinkDestination,
|
|
235
|
+
parseLinkLabel: () => parseLinkLabel,
|
|
236
|
+
parseLinkTitle: () => parseLinkTitle
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
function parseLinkLabel(state, start, disableNested) {
|
|
240
|
+
let level, found, marker, prevPos;
|
|
241
|
+
const max = state.posMax;
|
|
242
|
+
const oldPos = state.pos;
|
|
243
|
+
state.pos = start + 1;
|
|
244
|
+
level = 1;
|
|
245
|
+
while (state.pos < max) {
|
|
246
|
+
marker = state.src.charCodeAt(state.pos);
|
|
247
|
+
if (marker === 93) {
|
|
248
|
+
level--;
|
|
249
|
+
if (level === 0) {
|
|
250
|
+
found = true;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
prevPos = state.pos;
|
|
255
|
+
state.md.inline.skipToken(state);
|
|
256
|
+
if (marker === 91) {
|
|
257
|
+
if (prevPos === state.pos - 1) {
|
|
258
|
+
level++;
|
|
259
|
+
} else if (disableNested) {
|
|
260
|
+
state.pos = oldPos;
|
|
261
|
+
return -1;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
let labelEnd = -1;
|
|
266
|
+
if (found) {
|
|
267
|
+
labelEnd = state.pos;
|
|
268
|
+
}
|
|
269
|
+
state.pos = oldPos;
|
|
270
|
+
return labelEnd;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function parseLinkDestination(str, start, max) {
|
|
274
|
+
let code2;
|
|
275
|
+
let pos = start;
|
|
276
|
+
const result = {
|
|
277
|
+
ok: false,
|
|
278
|
+
pos: 0,
|
|
279
|
+
str: ""
|
|
280
|
+
};
|
|
281
|
+
if (str.charCodeAt(pos) === 60) {
|
|
282
|
+
pos++;
|
|
283
|
+
while (pos < max) {
|
|
284
|
+
code2 = str.charCodeAt(pos);
|
|
285
|
+
if (code2 === 10) {
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
if (code2 === 60) {
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
if (code2 === 62) {
|
|
292
|
+
result.pos = pos + 1;
|
|
293
|
+
result.str = unescapeAll(str.slice(start + 1, pos));
|
|
294
|
+
result.ok = true;
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
if (code2 === 92 && pos + 1 < max) {
|
|
298
|
+
pos += 2;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
pos++;
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
let level = 0;
|
|
306
|
+
while (pos < max) {
|
|
307
|
+
code2 = str.charCodeAt(pos);
|
|
308
|
+
if (code2 === 32) {
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
if (code2 < 32 || code2 === 127) {
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
if (code2 === 92 && pos + 1 < max) {
|
|
315
|
+
if (str.charCodeAt(pos + 1) === 32) {
|
|
316
|
+
pos++;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
pos += 2;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (code2 === 40) {
|
|
323
|
+
level++;
|
|
324
|
+
if (level > 32) {
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (code2 === 41) {
|
|
329
|
+
if (level === 0) {
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
level--;
|
|
333
|
+
}
|
|
334
|
+
pos++;
|
|
335
|
+
}
|
|
336
|
+
if (start === pos) {
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
if (level !== 0) {
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
result.str = unescapeAll(str.slice(start, pos));
|
|
343
|
+
result.pos = pos;
|
|
344
|
+
result.ok = true;
|
|
345
|
+
return result;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function parseLinkTitle(str, start, max, prev_state) {
|
|
349
|
+
let code2;
|
|
350
|
+
let pos = start;
|
|
351
|
+
const state = {
|
|
352
|
+
ok: false,
|
|
353
|
+
can_continue: false,
|
|
354
|
+
pos: 0,
|
|
355
|
+
str: "",
|
|
356
|
+
marker: 0
|
|
357
|
+
};
|
|
358
|
+
if (prev_state) {
|
|
359
|
+
state.str = prev_state.str;
|
|
360
|
+
state.marker = prev_state.marker;
|
|
361
|
+
} else {
|
|
362
|
+
if (pos >= max) {
|
|
363
|
+
return state;
|
|
364
|
+
}
|
|
365
|
+
let marker = str.charCodeAt(pos);
|
|
366
|
+
if (marker !== 34 && marker !== 39 && marker !== 40) {
|
|
367
|
+
return state;
|
|
368
|
+
}
|
|
369
|
+
start++;
|
|
370
|
+
pos++;
|
|
371
|
+
if (marker === 40) {
|
|
372
|
+
marker = 41;
|
|
373
|
+
}
|
|
374
|
+
state.marker = marker;
|
|
375
|
+
}
|
|
376
|
+
while (pos < max) {
|
|
377
|
+
code2 = str.charCodeAt(pos);
|
|
378
|
+
if (code2 === state.marker) {
|
|
379
|
+
state.pos = pos + 1;
|
|
380
|
+
state.str += unescapeAll(str.slice(start, pos));
|
|
381
|
+
state.ok = true;
|
|
382
|
+
return state;
|
|
383
|
+
} else if (code2 === 40 && state.marker === 41) {
|
|
384
|
+
return state;
|
|
385
|
+
} else if (code2 === 92 && pos + 1 < max) {
|
|
386
|
+
pos++;
|
|
387
|
+
}
|
|
388
|
+
pos++;
|
|
389
|
+
}
|
|
390
|
+
state.can_continue = true;
|
|
391
|
+
state.str += unescapeAll(str.slice(start, pos));
|
|
392
|
+
return state;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
var Token = class {
|
|
396
|
+
map = null;
|
|
397
|
+
level = 0;
|
|
398
|
+
children = null;
|
|
399
|
+
content = "";
|
|
400
|
+
markup = "";
|
|
401
|
+
info = "";
|
|
402
|
+
block = false;
|
|
403
|
+
hidden = false;
|
|
404
|
+
constructor(type, tag, nesting) {
|
|
405
|
+
this.type = type;
|
|
406
|
+
this.tag = tag;
|
|
407
|
+
this.attrs = null;
|
|
408
|
+
this.nesting = nesting;
|
|
409
|
+
this.meta = null;
|
|
410
|
+
}
|
|
411
|
+
attrIndex(name) {
|
|
412
|
+
if (!this.attrs) {
|
|
413
|
+
return -1;
|
|
414
|
+
}
|
|
415
|
+
const attrs = this.attrs;
|
|
416
|
+
for (let i = 0, len = attrs.length; i < len; i++) {
|
|
417
|
+
if (attrs[i][0] === name) {
|
|
418
|
+
return i;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return -1;
|
|
422
|
+
}
|
|
423
|
+
attrPush(attrData) {
|
|
424
|
+
if (this.attrs) {
|
|
425
|
+
this.attrs.push(attrData);
|
|
426
|
+
} else {
|
|
427
|
+
this.attrs = [attrData];
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
attrSet(name, value) {
|
|
431
|
+
const idx = this.attrIndex(name);
|
|
432
|
+
const attrData = [name, value];
|
|
433
|
+
if (idx < 0) {
|
|
434
|
+
this.attrPush(attrData);
|
|
435
|
+
} else {
|
|
436
|
+
this.attrs[idx] = attrData;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
attrGet(name) {
|
|
440
|
+
const idx = this.attrIndex(name);
|
|
441
|
+
let value = null;
|
|
442
|
+
if (idx >= 0) {
|
|
443
|
+
value = this.attrs[idx][1];
|
|
444
|
+
}
|
|
445
|
+
return value;
|
|
446
|
+
}
|
|
447
|
+
attrJoin(name, value) {
|
|
448
|
+
const idx = this.attrIndex(name);
|
|
449
|
+
if (idx < 0) {
|
|
450
|
+
this.attrPush([name, value]);
|
|
451
|
+
} else {
|
|
452
|
+
this.attrs[idx][1] = `${this.attrs[idx][1]} ${value}`;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var token_default = Token;
|
|
457
|
+
|
|
458
|
+
var Ruler = class {
|
|
459
|
+
__rules__ = [];
|
|
460
|
+
__cache__ = null;
|
|
461
|
+
__find__(name) {
|
|
462
|
+
for (let i = 0; i < this.__rules__.length; i++) {
|
|
463
|
+
if (this.__rules__[i].name === name) {
|
|
464
|
+
return i;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return -1;
|
|
468
|
+
}
|
|
469
|
+
__compile__() {
|
|
470
|
+
const chains = /* @__PURE__ */ new Set();
|
|
471
|
+
this.__rules__.forEach((rule) => {
|
|
472
|
+
if (!rule.enabled) return;
|
|
473
|
+
rule.alt.forEach((altName) => {
|
|
474
|
+
if (altName) chains.add(altName);
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
this.__cache__ = /* @__PURE__ */ Object.create(null);
|
|
478
|
+
this.__cache__[""] = [];
|
|
479
|
+
this.__rules__.forEach((rule) => {
|
|
480
|
+
if (rule.enabled) this.__cache__[""].push(rule.fn);
|
|
481
|
+
});
|
|
482
|
+
chains.forEach((chain) => {
|
|
483
|
+
this.__cache__[chain] = [];
|
|
484
|
+
this.__rules__.forEach((rule) => {
|
|
485
|
+
if (rule.enabled && rule.alt.indexOf(chain) >= 0) {
|
|
486
|
+
this.__cache__[chain].push(rule.fn);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
at(name, fn, options4 = {}) {
|
|
492
|
+
const index = this.__find__(name);
|
|
493
|
+
if (index === -1) {
|
|
494
|
+
throw new Error(`Parser rule not found: ${name}`);
|
|
495
|
+
}
|
|
496
|
+
this.__rules__[index].fn = fn;
|
|
497
|
+
this.__rules__[index].alt = options4.alt || [];
|
|
498
|
+
this.__cache__ = null;
|
|
499
|
+
}
|
|
500
|
+
before(beforeName, ruleName, fn, options4 = {}) {
|
|
501
|
+
const index = this.__find__(beforeName);
|
|
502
|
+
if (index === -1) {
|
|
503
|
+
throw new Error(`Parser rule not found: ${beforeName}`);
|
|
504
|
+
}
|
|
505
|
+
this.__rules__.splice(index, 0, {
|
|
506
|
+
name: ruleName,
|
|
507
|
+
enabled: true,
|
|
508
|
+
fn,
|
|
509
|
+
alt: options4.alt || []
|
|
510
|
+
});
|
|
511
|
+
this.__cache__ = null;
|
|
512
|
+
}
|
|
513
|
+
after(afterName, ruleName, fn, options4 = {}) {
|
|
514
|
+
const index = this.__find__(afterName);
|
|
515
|
+
if (index === -1) {
|
|
516
|
+
throw new Error(`Parser rule not found: ${afterName}`);
|
|
517
|
+
}
|
|
518
|
+
this.__rules__.splice(index + 1, 0, {
|
|
519
|
+
name: ruleName,
|
|
520
|
+
enabled: true,
|
|
521
|
+
fn,
|
|
522
|
+
alt: options4.alt || []
|
|
523
|
+
});
|
|
524
|
+
this.__cache__ = null;
|
|
525
|
+
}
|
|
526
|
+
push(ruleName, fn, options4 = {}) {
|
|
527
|
+
this.__rules__.push({
|
|
528
|
+
name: ruleName,
|
|
529
|
+
enabled: true,
|
|
530
|
+
fn,
|
|
531
|
+
alt: options4.alt || []
|
|
532
|
+
});
|
|
533
|
+
this.__cache__ = null;
|
|
534
|
+
}
|
|
535
|
+
enable(list2, ignoreInvalid = false) {
|
|
536
|
+
if (!Array.isArray(list2)) {
|
|
537
|
+
list2 = [list2];
|
|
538
|
+
}
|
|
539
|
+
const result = [];
|
|
540
|
+
list2.forEach((name) => {
|
|
541
|
+
const idx = this.__find__(name);
|
|
542
|
+
if (idx < 0) {
|
|
543
|
+
if (ignoreInvalid) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
throw new Error(`Rules manager: invalid rule name ${name}`);
|
|
547
|
+
}
|
|
548
|
+
this.__rules__[idx].enabled = true;
|
|
549
|
+
result.push(name);
|
|
550
|
+
});
|
|
551
|
+
this.__cache__ = null;
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
enableOnly(list2, ignoreInvalid = false) {
|
|
555
|
+
if (!Array.isArray(list2)) {
|
|
556
|
+
list2 = [list2];
|
|
557
|
+
}
|
|
558
|
+
this.__rules__.forEach((rule) => {
|
|
559
|
+
rule.enabled = false;
|
|
560
|
+
});
|
|
561
|
+
this.enable(list2, ignoreInvalid);
|
|
562
|
+
}
|
|
563
|
+
disable(list2, ignoreInvalid = false) {
|
|
564
|
+
if (!Array.isArray(list2)) {
|
|
565
|
+
list2 = [list2];
|
|
566
|
+
}
|
|
567
|
+
const result = [];
|
|
568
|
+
list2.forEach((name) => {
|
|
569
|
+
const idx = this.__find__(name);
|
|
570
|
+
if (idx < 0) {
|
|
571
|
+
if (ignoreInvalid) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
throw new Error(`Rules manager: invalid rule name ${name}`);
|
|
575
|
+
}
|
|
576
|
+
this.__rules__[idx].enabled = false;
|
|
577
|
+
result.push(name);
|
|
578
|
+
});
|
|
579
|
+
this.__cache__ = null;
|
|
580
|
+
return result;
|
|
581
|
+
}
|
|
582
|
+
getRules(chainName) {
|
|
583
|
+
if (!this.__cache__) this.__compile__();
|
|
584
|
+
return this.__cache__[chainName] || [];
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var ruler_default = Ruler;
|
|
588
|
+
|
|
589
|
+
var default_rules = {};
|
|
590
|
+
default_rules.code_inline = function(tokens, idx, options4, env, slf) {
|
|
591
|
+
const token = tokens[idx];
|
|
592
|
+
return `<code${slf.renderAttrs(token)}>${escapeHtml(token.content)}</code>`;
|
|
593
|
+
};
|
|
594
|
+
default_rules.code_block = function(tokens, idx, options4, env, slf) {
|
|
595
|
+
const token = tokens[idx];
|
|
596
|
+
return `<pre${slf.renderAttrs(token)}><code>${escapeHtml(tokens[idx].content)}</code></pre>
|
|
597
|
+
`;
|
|
598
|
+
};
|
|
599
|
+
default_rules.fence = function(tokens, idx, options4, env, slf) {
|
|
600
|
+
const token = tokens[idx];
|
|
601
|
+
const info = token.info ? unescapeAll(token.info).trim() : "";
|
|
602
|
+
let langName = "";
|
|
603
|
+
let langAttrs = "";
|
|
604
|
+
if (info) {
|
|
605
|
+
const arr = info.split(/(\s+)/g);
|
|
606
|
+
langName = arr[0];
|
|
607
|
+
langAttrs = arr.slice(2).join("");
|
|
608
|
+
}
|
|
609
|
+
let highlighted;
|
|
610
|
+
if (options4.highlight) {
|
|
611
|
+
highlighted = options4.highlight(token.content, langName, langAttrs) || escapeHtml(token.content);
|
|
612
|
+
} else {
|
|
613
|
+
highlighted = escapeHtml(token.content);
|
|
614
|
+
}
|
|
615
|
+
if (highlighted.indexOf("<pre") === 0) {
|
|
616
|
+
return highlighted + "\n";
|
|
617
|
+
}
|
|
618
|
+
if (info) {
|
|
619
|
+
const i = token.attrIndex("class");
|
|
620
|
+
const tmpAttrs = token.attrs ? token.attrs.slice() : [];
|
|
621
|
+
if (i < 0) {
|
|
622
|
+
tmpAttrs.push(["class", `${options4.langPrefix}${langName}`]);
|
|
623
|
+
} else {
|
|
624
|
+
tmpAttrs[i] = [tmpAttrs[i][0], tmpAttrs[i][1]];
|
|
625
|
+
tmpAttrs[i][1] += ` ${options4.langPrefix}${langName}`;
|
|
626
|
+
}
|
|
627
|
+
const tmpToken = {
|
|
628
|
+
attrs: tmpAttrs
|
|
629
|
+
};
|
|
630
|
+
return `<pre><code${slf.renderAttrs(tmpToken)}>${highlighted}</code></pre>
|
|
631
|
+
`;
|
|
632
|
+
}
|
|
633
|
+
return `<pre><code${slf.renderAttrs(token)}>${highlighted}</code></pre>
|
|
634
|
+
`;
|
|
635
|
+
};
|
|
636
|
+
default_rules.image = function(tokens, idx, options4, env, slf) {
|
|
637
|
+
const token = tokens[idx];
|
|
638
|
+
token.attrs[token.attrIndex("alt")][1] = slf.renderInlineAsText(token.children, options4, env);
|
|
639
|
+
return slf.renderToken(tokens, idx, options4);
|
|
640
|
+
};
|
|
641
|
+
default_rules.hardbreak = function(tokens, idx, options4) {
|
|
642
|
+
return options4.xhtmlOut ? "<br />\n" : "<br>\n";
|
|
643
|
+
};
|
|
644
|
+
default_rules.softbreak = function(tokens, idx, options4) {
|
|
645
|
+
return options4.breaks ? options4.xhtmlOut ? "<br />\n" : "<br>\n" : "\n";
|
|
646
|
+
};
|
|
647
|
+
default_rules.text = function(tokens, idx) {
|
|
648
|
+
return escapeHtml(tokens[idx].content);
|
|
649
|
+
};
|
|
650
|
+
default_rules.html_block = function(tokens, idx) {
|
|
651
|
+
return tokens[idx].content;
|
|
652
|
+
};
|
|
653
|
+
default_rules.html_inline = function(tokens, idx) {
|
|
654
|
+
return tokens[idx].content;
|
|
655
|
+
};
|
|
656
|
+
var Renderer = class {
|
|
657
|
+
rules = Object.assign({}, default_rules);
|
|
658
|
+
renderAttrs(token) {
|
|
659
|
+
let i, l, result;
|
|
660
|
+
if (!token.attrs) {
|
|
661
|
+
return "";
|
|
662
|
+
}
|
|
663
|
+
result = "";
|
|
664
|
+
for (i = 0, l = token.attrs.length; i < l; i++) {
|
|
665
|
+
result += ` ${escapeHtml(token.attrs[i][0])}="${escapeHtml(String(token.attrs[i][1]))}"`;
|
|
666
|
+
}
|
|
667
|
+
return result;
|
|
668
|
+
}
|
|
669
|
+
renderToken(tokens, idx, options4) {
|
|
670
|
+
const token = tokens[idx];
|
|
671
|
+
let result = "";
|
|
672
|
+
if (token.hidden) {
|
|
673
|
+
return "";
|
|
674
|
+
}
|
|
675
|
+
let prev = idx - 1;
|
|
676
|
+
while (prev >= 0 && tokens[prev].hidden && tokens[prev].nesting === 0) {
|
|
677
|
+
prev--;
|
|
678
|
+
}
|
|
679
|
+
if (token.block && token.nesting !== -1 && prev >= 0 && tokens[prev].hidden && tokens[prev].nesting === -1) {
|
|
680
|
+
result += "\n";
|
|
681
|
+
}
|
|
682
|
+
result += (token.nesting === -1 ? "</" : "<") + token.tag;
|
|
683
|
+
result += this.renderAttrs(token);
|
|
684
|
+
if (token.nesting === 0 && options4.xhtmlOut) {
|
|
685
|
+
result += " /";
|
|
686
|
+
}
|
|
687
|
+
let needLf = false;
|
|
688
|
+
if (token.block) {
|
|
689
|
+
needLf = true;
|
|
690
|
+
if (token.nesting === 1) {
|
|
691
|
+
let next = idx + 1;
|
|
692
|
+
while (next < tokens.length && tokens[next].hidden && tokens[next].nesting === 0) {
|
|
693
|
+
next++;
|
|
694
|
+
}
|
|
695
|
+
if (next < tokens.length) {
|
|
696
|
+
const nextToken = tokens[next];
|
|
697
|
+
if (nextToken.type === "inline" || nextToken.hidden) {
|
|
698
|
+
needLf = false;
|
|
699
|
+
} else if (nextToken.nesting === -1 && nextToken.tag === token.tag) {
|
|
700
|
+
needLf = false;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
result += needLf ? ">\n" : ">";
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
renderInline(tokens, options4, env) {
|
|
709
|
+
let result = "";
|
|
710
|
+
const rules = this.rules;
|
|
711
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
712
|
+
const type = tokens[i].type;
|
|
713
|
+
if (typeof rules[type] !== "undefined") {
|
|
714
|
+
result += rules[type](tokens, i, options4, env, this);
|
|
715
|
+
} else {
|
|
716
|
+
result += this.renderToken(tokens, i, options4);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return result;
|
|
720
|
+
}
|
|
721
|
+
renderInlineAsText(tokens, options4, env) {
|
|
722
|
+
let result = "";
|
|
723
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
724
|
+
switch (tokens[i].type) {
|
|
725
|
+
case "text":
|
|
726
|
+
case "code_inline":
|
|
727
|
+
result += tokens[i].content;
|
|
728
|
+
break;
|
|
729
|
+
case "image":
|
|
730
|
+
result += this.renderInlineAsText(tokens[i].children, options4, env);
|
|
731
|
+
break;
|
|
732
|
+
case "html_inline":
|
|
733
|
+
case "html_block":
|
|
734
|
+
result += tokens[i].content;
|
|
735
|
+
break;
|
|
736
|
+
case "softbreak":
|
|
737
|
+
case "hardbreak":
|
|
738
|
+
result += "\n";
|
|
739
|
+
break;
|
|
740
|
+
default:
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return result;
|
|
744
|
+
}
|
|
745
|
+
render(tokens, options4, env) {
|
|
746
|
+
let result = "";
|
|
747
|
+
const rules = this.rules;
|
|
748
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
749
|
+
const type = tokens[i].type;
|
|
750
|
+
if (type === "inline") {
|
|
751
|
+
result += this.renderInline(tokens[i].children, options4, env);
|
|
752
|
+
} else if (typeof rules[type] !== "undefined") {
|
|
753
|
+
result += rules[type](tokens, i, options4, env, this);
|
|
754
|
+
} else {
|
|
755
|
+
result += this.renderToken(tokens, i, options4);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
var renderer_default = Renderer;
|
|
762
|
+
|
|
763
|
+
var StateCore = class {
|
|
764
|
+
tokens = [];
|
|
765
|
+
inlineMode = false;
|
|
766
|
+
Token = token_default;
|
|
767
|
+
constructor(src, md, env) {
|
|
768
|
+
this.src = src;
|
|
769
|
+
this.env = env;
|
|
770
|
+
this.md = md;
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
var state_core_default = StateCore;
|
|
774
|
+
|
|
775
|
+
var UNNORMALIZED_NEWLINE_RE = /\r\n?/g;
|
|
776
|
+
var NULL_RE = /\0/g;
|
|
777
|
+
function normalize(state) {
|
|
778
|
+
let str;
|
|
779
|
+
str = state.src.replace(UNNORMALIZED_NEWLINE_RE, "\n");
|
|
780
|
+
str = str.replace(NULL_RE, "\uFFFD");
|
|
781
|
+
state.src = str;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function block(state) {
|
|
785
|
+
let token;
|
|
786
|
+
if (state.inlineMode) {
|
|
787
|
+
token = new state.Token("inline", "", 0);
|
|
788
|
+
token.content = state.src;
|
|
789
|
+
token.map = [0, 1];
|
|
790
|
+
token.children = [];
|
|
791
|
+
state.tokens.push(token);
|
|
792
|
+
} else {
|
|
793
|
+
state.md.block.parse(state.src, state.md, state.env, state.tokens);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function strip_references(state) {
|
|
798
|
+
const tokens = state.tokens;
|
|
799
|
+
let last = 0;
|
|
800
|
+
for (let curr = 0; curr < tokens.length; curr++) {
|
|
801
|
+
if (tokens[curr].type === "reference_definition") continue;
|
|
802
|
+
if (curr !== last) {
|
|
803
|
+
tokens[last] = tokens[curr];
|
|
804
|
+
}
|
|
805
|
+
last++;
|
|
806
|
+
}
|
|
807
|
+
if (tokens.length !== last) {
|
|
808
|
+
tokens.length = last;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function inline(state) {
|
|
813
|
+
const tokens = state.tokens;
|
|
814
|
+
for (let i = 0, l = tokens.length; i < l; i++) {
|
|
815
|
+
const tok = tokens[i];
|
|
816
|
+
if (tok.type === "inline") {
|
|
817
|
+
state.md.inline.parse(tok.content, state.md, state.env, tok.children);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function isLinkOpen(str) {
|
|
823
|
+
return /^<a[>\s]/i.test(str);
|
|
824
|
+
}
|
|
825
|
+
function isLinkClose(str) {
|
|
826
|
+
return /^<\/a\s*>/i.test(str);
|
|
827
|
+
}
|
|
828
|
+
function linkify(state) {
|
|
829
|
+
const blockTokens = state.tokens;
|
|
830
|
+
if (!state.md.options.linkify) {
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
for (let j = 0, l = blockTokens.length; j < l; j++) {
|
|
834
|
+
if (blockTokens[j].type !== "inline" || !state.md.linkify.test(blockTokens[j].content)) {
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
const tokens = blockTokens[j].children;
|
|
838
|
+
const replacements = [];
|
|
839
|
+
let htmlLinkLevel = 0;
|
|
840
|
+
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
841
|
+
const currentToken = tokens[i];
|
|
842
|
+
if (currentToken.type === "link_close") {
|
|
843
|
+
i--;
|
|
844
|
+
while (tokens[i].level !== currentToken.level && tokens[i].type !== "link_open") {
|
|
845
|
+
i--;
|
|
846
|
+
}
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (currentToken.type === "html_inline") {
|
|
850
|
+
if (isLinkOpen(currentToken.content) && htmlLinkLevel > 0) {
|
|
851
|
+
htmlLinkLevel--;
|
|
852
|
+
}
|
|
853
|
+
if (isLinkClose(currentToken.content)) {
|
|
854
|
+
htmlLinkLevel++;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
if (htmlLinkLevel > 0) {
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
if (currentToken.type === "text" && state.md.linkify.test(currentToken.content)) {
|
|
861
|
+
const text2 = currentToken.content;
|
|
862
|
+
let links = state.md.linkify.match(text2);
|
|
863
|
+
const nodes = [];
|
|
864
|
+
let level = currentToken.level;
|
|
865
|
+
let lastPos = 0;
|
|
866
|
+
if (links.length > 0 && links[0].index === 0 && i > 0 && tokens[i - 1].type === "text_special") {
|
|
867
|
+
links = links.slice(1);
|
|
868
|
+
}
|
|
869
|
+
for (let ln = 0; ln < links.length; ln++) {
|
|
870
|
+
const url = links[ln].url;
|
|
871
|
+
const fullUrl = state.md.normalizeLink(url);
|
|
872
|
+
if (!state.md.validateLink(fullUrl)) {
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
let urlText = links[ln].text;
|
|
876
|
+
if (!links[ln].schema) {
|
|
877
|
+
urlText = state.md.normalizeLinkText(`http://${urlText}`).replace(/^http:\/\//, "");
|
|
878
|
+
} else if (links[ln].schema === "mailto:" && !/^mailto:/i.test(urlText)) {
|
|
879
|
+
urlText = state.md.normalizeLinkText(`mailto:${urlText}`).replace(/^mailto:/, "");
|
|
880
|
+
} else {
|
|
881
|
+
urlText = state.md.normalizeLinkText(urlText);
|
|
882
|
+
}
|
|
883
|
+
const pos = links[ln].index;
|
|
884
|
+
if (pos > lastPos) {
|
|
885
|
+
const token = new state.Token("text", "", 0);
|
|
886
|
+
token.content = text2.slice(lastPos, pos);
|
|
887
|
+
token.level = level;
|
|
888
|
+
nodes.push(token);
|
|
889
|
+
}
|
|
890
|
+
const token_o = new state.Token("link_open", "a", 1);
|
|
891
|
+
token_o.attrs = [["href", fullUrl]];
|
|
892
|
+
token_o.level = level++;
|
|
893
|
+
token_o.markup = "linkify";
|
|
894
|
+
token_o.info = "auto";
|
|
895
|
+
nodes.push(token_o);
|
|
896
|
+
const token_t = new state.Token("text", "", 0);
|
|
897
|
+
token_t.content = urlText;
|
|
898
|
+
token_t.level = level;
|
|
899
|
+
nodes.push(token_t);
|
|
900
|
+
const token_c = new state.Token("link_close", "a", -1);
|
|
901
|
+
token_c.level = --level;
|
|
902
|
+
token_c.markup = "linkify";
|
|
903
|
+
token_c.info = "auto";
|
|
904
|
+
nodes.push(token_c);
|
|
905
|
+
lastPos = links[ln].lastIndex;
|
|
906
|
+
}
|
|
907
|
+
if (lastPos < text2.length) {
|
|
908
|
+
const token = new state.Token("text", "", 0);
|
|
909
|
+
token.content = text2.slice(lastPos);
|
|
910
|
+
token.level = level;
|
|
911
|
+
nodes.push(token);
|
|
912
|
+
}
|
|
913
|
+
replacements.push({ index: i, nodes });
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (replacements.length > 0) {
|
|
917
|
+
let newTokensLength = tokens.length;
|
|
918
|
+
for (const replacement of replacements) {
|
|
919
|
+
newTokensLength += replacement.nodes.length - 1;
|
|
920
|
+
}
|
|
921
|
+
const newTokens = new Array(newTokensLength);
|
|
922
|
+
let replacementIndex = 0;
|
|
923
|
+
let newTokenIndex = 0;
|
|
924
|
+
replacements.reverse();
|
|
925
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
926
|
+
const replacement = replacements[replacementIndex];
|
|
927
|
+
if (replacement?.index === i) {
|
|
928
|
+
for (const node of replacement.nodes) {
|
|
929
|
+
newTokens[newTokenIndex++] = node;
|
|
930
|
+
}
|
|
931
|
+
replacementIndex++;
|
|
932
|
+
} else {
|
|
933
|
+
newTokens[newTokenIndex++] = tokens[i];
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
blockTokens[j].children = newTokens;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/;
|
|
942
|
+
var SCOPED_ABBR_TEST_RE = /\((c|tm|r)\)/i;
|
|
943
|
+
var SCOPED_ABBR_RE = /\((c|tm|r)\)/ig;
|
|
944
|
+
var SCOPED_ABBR = {
|
|
945
|
+
c: "\xA9",
|
|
946
|
+
r: "\xAE",
|
|
947
|
+
tm: "\u2122"
|
|
948
|
+
};
|
|
949
|
+
function replaceFn(match, name) {
|
|
950
|
+
return SCOPED_ABBR[name.toLowerCase()];
|
|
951
|
+
}
|
|
952
|
+
function replace_scoped(inlineTokens) {
|
|
953
|
+
let inside_autolink = 0;
|
|
954
|
+
for (let i = inlineTokens.length - 1; i >= 0; i--) {
|
|
955
|
+
const token = inlineTokens[i];
|
|
956
|
+
if (token.type === "text" && !inside_autolink) {
|
|
957
|
+
token.content = token.content.replace(SCOPED_ABBR_RE, replaceFn);
|
|
958
|
+
}
|
|
959
|
+
if (token.type === "link_open" && token.info === "auto") {
|
|
960
|
+
inside_autolink--;
|
|
961
|
+
}
|
|
962
|
+
if (token.type === "link_close" && token.info === "auto") {
|
|
963
|
+
inside_autolink++;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
function replace_rare(inlineTokens) {
|
|
968
|
+
let inside_autolink = 0;
|
|
969
|
+
for (let i = inlineTokens.length - 1; i >= 0; i--) {
|
|
970
|
+
const token = inlineTokens[i];
|
|
971
|
+
if (token.type === "text" && !inside_autolink) {
|
|
972
|
+
if (RARE_RE.test(token.content)) {
|
|
973
|
+
token.content = token.content.replace(/\+-/g, "\xB1").replace(/\.{2,}/g, "\u2026").replace(/([?!])…/g, "$1..").replace(/([?!]){4,}/g, "$1$1$1").replace(/,{2,}/g, ",").replace(/(^|[^-])---(?=[^-]|$)/mg, "$1\u2014").replace(/(^|\s)--(?=\s|$)/mg, "$1\u2013").replace(/(^|[^-\s])--(?=[^-\s]|$)/mg, "$1\u2013");
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (token.type === "link_open" && token.info === "auto") {
|
|
977
|
+
inside_autolink--;
|
|
978
|
+
}
|
|
979
|
+
if (token.type === "link_close" && token.info === "auto") {
|
|
980
|
+
inside_autolink++;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
function replace(state) {
|
|
985
|
+
let blkIdx;
|
|
986
|
+
if (!state.md.options.typographer) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {
|
|
990
|
+
if (state.tokens[blkIdx].type !== "inline") {
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
if (SCOPED_ABBR_TEST_RE.test(state.tokens[blkIdx].content)) {
|
|
994
|
+
replace_scoped(state.tokens[blkIdx].children);
|
|
995
|
+
}
|
|
996
|
+
if (RARE_RE.test(state.tokens[blkIdx].content)) {
|
|
997
|
+
replace_rare(state.tokens[blkIdx].children);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
var QUOTE_TEST_RE = /['"]/;
|
|
1003
|
+
var QUOTE_RE = /['"]/g;
|
|
1004
|
+
var APOSTROPHE = "\u2019";
|
|
1005
|
+
var MAX_OPENERS = 1e3;
|
|
1006
|
+
function truncateStack(stack, heads, length) {
|
|
1007
|
+
while (stack.length > length) {
|
|
1008
|
+
const item = stack.pop();
|
|
1009
|
+
if (item.isSingleQuote) {
|
|
1010
|
+
heads.single = item.prevSameQuoteIdx;
|
|
1011
|
+
} else {
|
|
1012
|
+
heads.double = item.prevSameQuoteIdx;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
function addReplacement(replacements, tokenIdx, pos, ch) {
|
|
1017
|
+
if (!replacements[tokenIdx]) {
|
|
1018
|
+
replacements[tokenIdx] = [];
|
|
1019
|
+
}
|
|
1020
|
+
replacements[tokenIdx].push({ pos, ch });
|
|
1021
|
+
}
|
|
1022
|
+
function applyReplacements(str, replacements) {
|
|
1023
|
+
let result = "";
|
|
1024
|
+
let lastPos = 0;
|
|
1025
|
+
replacements.sort((a, b) => a.pos - b.pos);
|
|
1026
|
+
for (let i = 0; i < replacements.length; i++) {
|
|
1027
|
+
const replacement = replacements[i];
|
|
1028
|
+
result += str.slice(lastPos, replacement.pos) + replacement.ch;
|
|
1029
|
+
lastPos = replacement.pos + 1;
|
|
1030
|
+
}
|
|
1031
|
+
return result + str.slice(lastPos);
|
|
1032
|
+
}
|
|
1033
|
+
function process_inlines(tokens, state) {
|
|
1034
|
+
let j;
|
|
1035
|
+
const stack = [];
|
|
1036
|
+
const heads = { single: -1, double: -1 };
|
|
1037
|
+
const replacements = {};
|
|
1038
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
1039
|
+
const token = tokens[i];
|
|
1040
|
+
const thisLevel = tokens[i].level;
|
|
1041
|
+
for (j = stack.length - 1; j >= 0; j--) {
|
|
1042
|
+
if (stack[j].level <= thisLevel) {
|
|
1043
|
+
break;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
truncateStack(stack, heads, j + 1);
|
|
1047
|
+
if (token.type !== "text") {
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
const text2 = token.content;
|
|
1051
|
+
let pos = 0;
|
|
1052
|
+
const max = text2.length;
|
|
1053
|
+
OUTER:
|
|
1054
|
+
while (pos < max) {
|
|
1055
|
+
QUOTE_RE.lastIndex = pos;
|
|
1056
|
+
const t = QUOTE_RE.exec(text2);
|
|
1057
|
+
if (!t) {
|
|
1058
|
+
break;
|
|
1059
|
+
}
|
|
1060
|
+
let canOpen = true;
|
|
1061
|
+
let canClose = true;
|
|
1062
|
+
pos = t.index + 1;
|
|
1063
|
+
const isSingle = t[0] === "'";
|
|
1064
|
+
let lastChar = 32;
|
|
1065
|
+
if (t.index - 1 >= 0) {
|
|
1066
|
+
lastChar = text2.charCodeAt(t.index - 1);
|
|
1067
|
+
} else {
|
|
1068
|
+
for (j = i - 1; j >= 0; j--) {
|
|
1069
|
+
if (tokens[j].type === "softbreak" || tokens[j].type === "hardbreak") break;
|
|
1070
|
+
if (!tokens[j].content) continue;
|
|
1071
|
+
lastChar = tokens[j].content.charCodeAt(tokens[j].content.length - 1);
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
let nextChar = 32;
|
|
1076
|
+
if (pos < max) {
|
|
1077
|
+
nextChar = text2.charCodeAt(pos);
|
|
1078
|
+
} else {
|
|
1079
|
+
for (j = i + 1; j < tokens.length; j++) {
|
|
1080
|
+
if (tokens[j].type === "softbreak" || tokens[j].type === "hardbreak") break;
|
|
1081
|
+
if (!tokens[j].content) continue;
|
|
1082
|
+
nextChar = tokens[j].content.charCodeAt(0);
|
|
1083
|
+
break;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar);
|
|
1087
|
+
const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar);
|
|
1088
|
+
const isLastWhiteSpace = isWhiteSpace(lastChar);
|
|
1089
|
+
const isNextWhiteSpace = isWhiteSpace(nextChar);
|
|
1090
|
+
if (isNextWhiteSpace) {
|
|
1091
|
+
canOpen = false;
|
|
1092
|
+
} else if (isNextPunctChar) {
|
|
1093
|
+
if (!(isLastWhiteSpace || isLastPunctChar)) {
|
|
1094
|
+
canOpen = false;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (isLastWhiteSpace) {
|
|
1098
|
+
canClose = false;
|
|
1099
|
+
} else if (isLastPunctChar) {
|
|
1100
|
+
if (!(isNextWhiteSpace || isNextPunctChar)) {
|
|
1101
|
+
canClose = false;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (nextChar === 34 && t[0] === '"') {
|
|
1105
|
+
if (lastChar >= 48 && lastChar <= 57) {
|
|
1106
|
+
canClose = canOpen = false;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
if (canOpen && canClose) {
|
|
1110
|
+
canOpen = isLastPunctChar;
|
|
1111
|
+
canClose = isNextPunctChar;
|
|
1112
|
+
}
|
|
1113
|
+
if (!canOpen && !canClose) {
|
|
1114
|
+
if (isSingle) {
|
|
1115
|
+
addReplacement(replacements, i, t.index, APOSTROPHE);
|
|
1116
|
+
}
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
if (canClose) {
|
|
1120
|
+
j = isSingle ? heads.single : heads.double;
|
|
1121
|
+
if (j >= 0 && stack[j].level === thisLevel) {
|
|
1122
|
+
const item = stack[j];
|
|
1123
|
+
let openQuote;
|
|
1124
|
+
let closeQuote;
|
|
1125
|
+
if (isSingle) {
|
|
1126
|
+
openQuote = state.md.options.quotes[2];
|
|
1127
|
+
closeQuote = state.md.options.quotes[3];
|
|
1128
|
+
} else {
|
|
1129
|
+
openQuote = state.md.options.quotes[0];
|
|
1130
|
+
closeQuote = state.md.options.quotes[1];
|
|
1131
|
+
}
|
|
1132
|
+
addReplacement(replacements, i, t.index, closeQuote);
|
|
1133
|
+
addReplacement(replacements, item.tokenIdx, item.contentPos, openQuote);
|
|
1134
|
+
truncateStack(stack, heads, j);
|
|
1135
|
+
continue OUTER;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
if (canOpen) {
|
|
1139
|
+
if (stack.length >= MAX_OPENERS) {
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
stack.push({
|
|
1143
|
+
tokenIdx: i,
|
|
1144
|
+
contentPos: t.index,
|
|
1145
|
+
isSingleQuote: isSingle,
|
|
1146
|
+
level: thisLevel,
|
|
1147
|
+
prevSameQuoteIdx: isSingle ? heads.single : heads.double
|
|
1148
|
+
});
|
|
1149
|
+
if (isSingle) {
|
|
1150
|
+
heads.single = stack.length - 1;
|
|
1151
|
+
} else {
|
|
1152
|
+
heads.double = stack.length - 1;
|
|
1153
|
+
}
|
|
1154
|
+
} else if (canClose && isSingle) {
|
|
1155
|
+
addReplacement(replacements, i, t.index, APOSTROPHE);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
Object.keys(replacements).forEach(function(tokenIdx) {
|
|
1160
|
+
const idx = Number(tokenIdx);
|
|
1161
|
+
tokens[idx].content = applyReplacements(tokens[idx].content, replacements[tokenIdx]);
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
function smartquotes(state) {
|
|
1165
|
+
if (!state.md.options.typographer) {
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
for (let blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {
|
|
1169
|
+
if (state.tokens[blkIdx].type !== "inline" || !QUOTE_TEST_RE.test(state.tokens[blkIdx].content)) {
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
process_inlines(state.tokens[blkIdx].children, state);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function join_alt(tokens) {
|
|
1177
|
+
let curr, last;
|
|
1178
|
+
const max = tokens.length;
|
|
1179
|
+
for (curr = 0; curr < max; curr++) {
|
|
1180
|
+
if (tokens[curr].type === "text_special") tokens[curr].type = "text";
|
|
1181
|
+
}
|
|
1182
|
+
for (curr = last = 0; curr < max; curr++) {
|
|
1183
|
+
if (tokens[curr].type === "text" && curr + 1 < max && tokens[curr + 1].type === "text") {
|
|
1184
|
+
tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content;
|
|
1185
|
+
} else {
|
|
1186
|
+
if (curr !== last) {
|
|
1187
|
+
tokens[last] = tokens[curr];
|
|
1188
|
+
}
|
|
1189
|
+
last++;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
if (curr !== last) tokens.length = last;
|
|
1193
|
+
}
|
|
1194
|
+
function text_join(state) {
|
|
1195
|
+
let curr, last;
|
|
1196
|
+
const blockTokens = state.tokens;
|
|
1197
|
+
const l = blockTokens.length;
|
|
1198
|
+
for (let j = 0; j < l; j++) {
|
|
1199
|
+
if (blockTokens[j].type !== "inline") continue;
|
|
1200
|
+
const tokens = blockTokens[j].children;
|
|
1201
|
+
const max = tokens.length;
|
|
1202
|
+
for (curr = 0; curr < max; curr++) {
|
|
1203
|
+
if (tokens[curr].type === "text_special") tokens[curr].type = "text";
|
|
1204
|
+
if (tokens[curr].children) join_alt(tokens[curr].children);
|
|
1205
|
+
}
|
|
1206
|
+
for (curr = last = 0; curr < max; curr++) {
|
|
1207
|
+
if (tokens[curr].type === "text" && curr + 1 < max && tokens[curr + 1].type === "text") {
|
|
1208
|
+
tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content;
|
|
1209
|
+
} else {
|
|
1210
|
+
if (curr !== last) {
|
|
1211
|
+
tokens[last] = tokens[curr];
|
|
1212
|
+
}
|
|
1213
|
+
last++;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
if (curr !== last) tokens.length = last;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
var _rules = [
|
|
1221
|
+
["normalize", normalize],
|
|
1222
|
+
["block", block],
|
|
1223
|
+
["strip_references", strip_references],
|
|
1224
|
+
["inline", inline],
|
|
1225
|
+
["linkify", linkify],
|
|
1226
|
+
["replacements", replace],
|
|
1227
|
+
["smartquotes", smartquotes],
|
|
1228
|
+
["text_join", text_join]
|
|
1229
|
+
];
|
|
1230
|
+
var ParserCore = class {
|
|
1231
|
+
ruler = new ruler_default();
|
|
1232
|
+
State = state_core_default;
|
|
1233
|
+
constructor() {
|
|
1234
|
+
for (let i = 0; i < _rules.length; i++) {
|
|
1235
|
+
this.ruler.push(_rules[i][0], _rules[i][1]);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
process(state) {
|
|
1239
|
+
const rules = this.ruler.getRules("");
|
|
1240
|
+
for (let i = 0, l = rules.length; i < l; i++) {
|
|
1241
|
+
rules[i](state);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
var parser_core_default = ParserCore;
|
|
1246
|
+
|
|
1247
|
+
var StateBlock = class {
|
|
1248
|
+
bMarks = [];
|
|
1249
|
+
eMarks = [];
|
|
1250
|
+
tShift = [];
|
|
1251
|
+
sCount = [];
|
|
1252
|
+
bsCount = [];
|
|
1253
|
+
blkIndent = 0;
|
|
1254
|
+
line = 0;
|
|
1255
|
+
lineMax = 0;
|
|
1256
|
+
tight = false;
|
|
1257
|
+
listIndent = -1;
|
|
1258
|
+
parentType = "root";
|
|
1259
|
+
level = 0;
|
|
1260
|
+
Token = token_default;
|
|
1261
|
+
constructor(src, md, env, tokens) {
|
|
1262
|
+
this.src = src;
|
|
1263
|
+
this.md = md;
|
|
1264
|
+
this.env = env;
|
|
1265
|
+
this.tokens = tokens;
|
|
1266
|
+
const s = this.src;
|
|
1267
|
+
for (let start = 0, pos = 0, indent = 0, offset = 0, len = s.length, indent_found = false; pos < len; pos++) {
|
|
1268
|
+
const ch = s.charCodeAt(pos);
|
|
1269
|
+
if (!indent_found) {
|
|
1270
|
+
if (isSpace(ch)) {
|
|
1271
|
+
indent++;
|
|
1272
|
+
if (ch === 9) {
|
|
1273
|
+
offset += 4 - offset % 4;
|
|
1274
|
+
} else {
|
|
1275
|
+
offset++;
|
|
1276
|
+
}
|
|
1277
|
+
continue;
|
|
1278
|
+
} else {
|
|
1279
|
+
indent_found = true;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (ch === 10 || pos === len - 1) {
|
|
1283
|
+
if (ch !== 10) {
|
|
1284
|
+
pos++;
|
|
1285
|
+
}
|
|
1286
|
+
this.bMarks.push(start);
|
|
1287
|
+
this.eMarks.push(pos);
|
|
1288
|
+
this.tShift.push(indent);
|
|
1289
|
+
this.sCount.push(offset);
|
|
1290
|
+
this.bsCount.push(0);
|
|
1291
|
+
indent_found = false;
|
|
1292
|
+
indent = 0;
|
|
1293
|
+
offset = 0;
|
|
1294
|
+
start = pos + 1;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
this.bMarks.push(s.length);
|
|
1298
|
+
this.eMarks.push(s.length);
|
|
1299
|
+
this.tShift.push(0);
|
|
1300
|
+
this.sCount.push(0);
|
|
1301
|
+
this.bsCount.push(0);
|
|
1302
|
+
this.lineMax = this.bMarks.length - 1;
|
|
1303
|
+
}
|
|
1304
|
+
push(type, tag, nesting) {
|
|
1305
|
+
const token = new token_default(type, tag, nesting);
|
|
1306
|
+
token.block = true;
|
|
1307
|
+
if (nesting < 0) this.level--;
|
|
1308
|
+
token.level = this.level;
|
|
1309
|
+
if (nesting > 0) this.level++;
|
|
1310
|
+
this.tokens.push(token);
|
|
1311
|
+
return token;
|
|
1312
|
+
}
|
|
1313
|
+
isEmpty(line) {
|
|
1314
|
+
return this.bMarks[line] + this.tShift[line] >= this.eMarks[line];
|
|
1315
|
+
}
|
|
1316
|
+
skipEmptyLines(from) {
|
|
1317
|
+
for (let max = this.lineMax; from < max; from++) {
|
|
1318
|
+
if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) {
|
|
1319
|
+
break;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return from;
|
|
1323
|
+
}
|
|
1324
|
+
skipSpaces(pos) {
|
|
1325
|
+
for (let max = this.src.length; pos < max; pos++) {
|
|
1326
|
+
const ch = this.src.charCodeAt(pos);
|
|
1327
|
+
if (!isSpace(ch)) {
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
return pos;
|
|
1332
|
+
}
|
|
1333
|
+
skipSpacesBack(pos, min) {
|
|
1334
|
+
if (pos <= min) {
|
|
1335
|
+
return pos;
|
|
1336
|
+
}
|
|
1337
|
+
while (pos > min) {
|
|
1338
|
+
if (!isSpace(this.src.charCodeAt(--pos))) {
|
|
1339
|
+
return pos + 1;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
return pos;
|
|
1343
|
+
}
|
|
1344
|
+
skipChars(pos, code2) {
|
|
1345
|
+
for (let max = this.src.length; pos < max; pos++) {
|
|
1346
|
+
if (this.src.charCodeAt(pos) !== code2) {
|
|
1347
|
+
break;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
return pos;
|
|
1351
|
+
}
|
|
1352
|
+
skipCharsBack(pos, code2, min) {
|
|
1353
|
+
if (pos <= min) {
|
|
1354
|
+
return pos;
|
|
1355
|
+
}
|
|
1356
|
+
while (pos > min) {
|
|
1357
|
+
if (code2 !== this.src.charCodeAt(--pos)) {
|
|
1358
|
+
return pos + 1;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return pos;
|
|
1362
|
+
}
|
|
1363
|
+
getLines(begin, end, indent, keepLastLF) {
|
|
1364
|
+
if (begin >= end) {
|
|
1365
|
+
return "";
|
|
1366
|
+
}
|
|
1367
|
+
const queue = new Array(end - begin);
|
|
1368
|
+
for (let i = 0, line = begin; line < end; line++, i++) {
|
|
1369
|
+
let lineIndent = 0;
|
|
1370
|
+
const lineStart = this.bMarks[line];
|
|
1371
|
+
let first = lineStart;
|
|
1372
|
+
let last;
|
|
1373
|
+
if (line + 1 < end || keepLastLF) {
|
|
1374
|
+
last = this.eMarks[line] + 1;
|
|
1375
|
+
} else {
|
|
1376
|
+
last = this.eMarks[line];
|
|
1377
|
+
}
|
|
1378
|
+
while (first < last && lineIndent < indent) {
|
|
1379
|
+
const ch = this.src.charCodeAt(first);
|
|
1380
|
+
if (isSpace(ch)) {
|
|
1381
|
+
if (ch === 9) {
|
|
1382
|
+
lineIndent += 4 - (lineIndent + this.bsCount[line]) % 4;
|
|
1383
|
+
} else {
|
|
1384
|
+
lineIndent++;
|
|
1385
|
+
}
|
|
1386
|
+
} else if (first - lineStart < this.tShift[line]) {
|
|
1387
|
+
lineIndent++;
|
|
1388
|
+
} else {
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
first++;
|
|
1392
|
+
}
|
|
1393
|
+
if (lineIndent > indent) {
|
|
1394
|
+
queue[i] = new Array(lineIndent - indent + 1).join(" ") + this.src.slice(first, last);
|
|
1395
|
+
} else {
|
|
1396
|
+
queue[i] = this.src.slice(first, last);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return queue.join("");
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
var state_block_default = StateBlock;
|
|
1403
|
+
|
|
1404
|
+
var MAX_AUTOCOMPLETED_CELLS = 65536;
|
|
1405
|
+
function getLine(state, line) {
|
|
1406
|
+
const pos = state.bMarks[line] + state.tShift[line];
|
|
1407
|
+
const max = state.eMarks[line];
|
|
1408
|
+
return state.src.slice(pos, max);
|
|
1409
|
+
}
|
|
1410
|
+
function escapedSplit(str) {
|
|
1411
|
+
const result = [];
|
|
1412
|
+
const max = str.length;
|
|
1413
|
+
let pos = 0;
|
|
1414
|
+
let ch = str.charCodeAt(pos);
|
|
1415
|
+
let isEscaped = false;
|
|
1416
|
+
let lastPos = 0;
|
|
1417
|
+
let current = "";
|
|
1418
|
+
while (pos < max) {
|
|
1419
|
+
if (ch === 124) {
|
|
1420
|
+
if (!isEscaped) {
|
|
1421
|
+
result.push(current + str.substring(lastPos, pos));
|
|
1422
|
+
current = "";
|
|
1423
|
+
lastPos = pos + 1;
|
|
1424
|
+
} else {
|
|
1425
|
+
current += str.substring(lastPos, pos - 1);
|
|
1426
|
+
lastPos = pos;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
isEscaped = ch === 92;
|
|
1430
|
+
pos++;
|
|
1431
|
+
ch = str.charCodeAt(pos);
|
|
1432
|
+
}
|
|
1433
|
+
result.push(current + str.substring(lastPos));
|
|
1434
|
+
return result;
|
|
1435
|
+
}
|
|
1436
|
+
function table(state, startLine, endLine, silent) {
|
|
1437
|
+
if (startLine + 2 > endLine) {
|
|
1438
|
+
return false;
|
|
1439
|
+
}
|
|
1440
|
+
let nextLine = startLine + 1;
|
|
1441
|
+
if (state.sCount[nextLine] < state.blkIndent) {
|
|
1442
|
+
return false;
|
|
1443
|
+
}
|
|
1444
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
1445
|
+
return false;
|
|
1446
|
+
}
|
|
1447
|
+
let pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
1448
|
+
if (pos >= state.eMarks[nextLine]) {
|
|
1449
|
+
return false;
|
|
1450
|
+
}
|
|
1451
|
+
const firstCh = state.src.charCodeAt(pos++);
|
|
1452
|
+
if (firstCh !== 124 && firstCh !== 45 && firstCh !== 58) {
|
|
1453
|
+
return false;
|
|
1454
|
+
}
|
|
1455
|
+
if (pos >= state.eMarks[nextLine]) {
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
const secondCh = state.src.charCodeAt(pos++);
|
|
1459
|
+
if (secondCh !== 124 && secondCh !== 45 && secondCh !== 58 && !isSpace(secondCh)) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
if (firstCh === 45 && isSpace(secondCh)) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
while (pos < state.eMarks[nextLine]) {
|
|
1466
|
+
const ch = state.src.charCodeAt(pos);
|
|
1467
|
+
if (ch !== 124 && ch !== 45 && ch !== 58 && !isSpace(ch)) {
|
|
1468
|
+
return false;
|
|
1469
|
+
}
|
|
1470
|
+
pos++;
|
|
1471
|
+
}
|
|
1472
|
+
let lineText = getLine(state, startLine + 1);
|
|
1473
|
+
let columns = lineText.split("|");
|
|
1474
|
+
const aligns = [];
|
|
1475
|
+
for (let i = 0; i < columns.length; i++) {
|
|
1476
|
+
const t = columns[i].trim();
|
|
1477
|
+
if (!t) {
|
|
1478
|
+
if (i === 0 || i === columns.length - 1) {
|
|
1479
|
+
continue;
|
|
1480
|
+
} else {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
if (!/^:?-+:?$/.test(t)) {
|
|
1485
|
+
return false;
|
|
1486
|
+
}
|
|
1487
|
+
if (t.charCodeAt(t.length - 1) === 58) {
|
|
1488
|
+
aligns.push(t.charCodeAt(0) === 58 ? "center" : "right");
|
|
1489
|
+
} else if (t.charCodeAt(0) === 58) {
|
|
1490
|
+
aligns.push("left");
|
|
1491
|
+
} else {
|
|
1492
|
+
aligns.push("");
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
lineText = getLine(state, startLine).trim();
|
|
1496
|
+
if (lineText.indexOf("|") === -1) {
|
|
1497
|
+
return false;
|
|
1498
|
+
}
|
|
1499
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
1500
|
+
return false;
|
|
1501
|
+
}
|
|
1502
|
+
columns = escapedSplit(lineText);
|
|
1503
|
+
if (columns.length && columns[0] === "") columns.shift();
|
|
1504
|
+
if (columns.length && columns[columns.length - 1] === "") columns.pop();
|
|
1505
|
+
const columnCount = columns.length;
|
|
1506
|
+
if (columnCount === 0 || columnCount !== aligns.length) {
|
|
1507
|
+
return false;
|
|
1508
|
+
}
|
|
1509
|
+
if (silent) {
|
|
1510
|
+
return true;
|
|
1511
|
+
}
|
|
1512
|
+
const oldParentType = state.parentType;
|
|
1513
|
+
state.parentType = "table";
|
|
1514
|
+
const terminatorRules = state.md.block.ruler.getRules("blockquote");
|
|
1515
|
+
const token_to = state.push("table_open", "table", 1);
|
|
1516
|
+
const tableLines = [startLine, 0];
|
|
1517
|
+
token_to.map = tableLines;
|
|
1518
|
+
const token_tho = state.push("thead_open", "thead", 1);
|
|
1519
|
+
token_tho.map = [startLine, startLine + 1];
|
|
1520
|
+
const token_htro = state.push("tr_open", "tr", 1);
|
|
1521
|
+
token_htro.map = [startLine, startLine + 1];
|
|
1522
|
+
for (let i = 0; i < columns.length; i++) {
|
|
1523
|
+
const token_ho = state.push("th_open", "th", 1);
|
|
1524
|
+
if (aligns[i]) {
|
|
1525
|
+
token_ho.attrs = [["style", `text-align:${aligns[i]}`]];
|
|
1526
|
+
}
|
|
1527
|
+
const token_il = state.push("inline", "", 0);
|
|
1528
|
+
token_il.content = columns[i].trim();
|
|
1529
|
+
token_il.children = [];
|
|
1530
|
+
state.push("th_close", "th", -1);
|
|
1531
|
+
}
|
|
1532
|
+
state.push("tr_close", "tr", -1);
|
|
1533
|
+
state.push("thead_close", "thead", -1);
|
|
1534
|
+
let tbodyLines;
|
|
1535
|
+
let autocompletedCells = 0;
|
|
1536
|
+
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) {
|
|
1537
|
+
if (state.sCount[nextLine] < state.blkIndent) {
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
let terminate = false;
|
|
1541
|
+
for (let i = 0, l = terminatorRules.length; i < l; i++) {
|
|
1542
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
1543
|
+
terminate = true;
|
|
1544
|
+
break;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
if (terminate) {
|
|
1548
|
+
break;
|
|
1549
|
+
}
|
|
1550
|
+
lineText = getLine(state, nextLine).trim();
|
|
1551
|
+
if (!lineText) {
|
|
1552
|
+
break;
|
|
1553
|
+
}
|
|
1554
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
1555
|
+
break;
|
|
1556
|
+
}
|
|
1557
|
+
columns = escapedSplit(lineText);
|
|
1558
|
+
if (columns.length && columns[0] === "") columns.shift();
|
|
1559
|
+
if (columns.length && columns[columns.length - 1] === "") columns.pop();
|
|
1560
|
+
autocompletedCells += columnCount - columns.length;
|
|
1561
|
+
if (autocompletedCells > MAX_AUTOCOMPLETED_CELLS) {
|
|
1562
|
+
break;
|
|
1563
|
+
}
|
|
1564
|
+
if (nextLine === startLine + 2) {
|
|
1565
|
+
const token_tbo = state.push("tbody_open", "tbody", 1);
|
|
1566
|
+
token_tbo.map = tbodyLines = [startLine + 2, 0];
|
|
1567
|
+
}
|
|
1568
|
+
const token_tro = state.push("tr_open", "tr", 1);
|
|
1569
|
+
token_tro.map = [nextLine, nextLine + 1];
|
|
1570
|
+
for (let i = 0; i < columnCount; i++) {
|
|
1571
|
+
const token_tdo = state.push("td_open", "td", 1);
|
|
1572
|
+
if (aligns[i]) {
|
|
1573
|
+
token_tdo.attrs = [["style", `text-align:${aligns[i]}`]];
|
|
1574
|
+
}
|
|
1575
|
+
const token_il = state.push("inline", "", 0);
|
|
1576
|
+
token_il.content = columns[i] ? columns[i].trim() : "";
|
|
1577
|
+
token_il.children = [];
|
|
1578
|
+
state.push("td_close", "td", -1);
|
|
1579
|
+
}
|
|
1580
|
+
state.push("tr_close", "tr", -1);
|
|
1581
|
+
}
|
|
1582
|
+
if (tbodyLines) {
|
|
1583
|
+
state.push("tbody_close", "tbody", -1);
|
|
1584
|
+
tbodyLines[1] = nextLine;
|
|
1585
|
+
}
|
|
1586
|
+
state.push("table_close", "table", -1);
|
|
1587
|
+
tableLines[1] = nextLine;
|
|
1588
|
+
state.parentType = oldParentType;
|
|
1589
|
+
state.line = nextLine;
|
|
1590
|
+
return true;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
function code(state, startLine, endLine) {
|
|
1594
|
+
if (state.sCount[startLine] - state.blkIndent < 4) {
|
|
1595
|
+
return false;
|
|
1596
|
+
}
|
|
1597
|
+
let nextLine = startLine + 1;
|
|
1598
|
+
let last = nextLine;
|
|
1599
|
+
while (nextLine < endLine) {
|
|
1600
|
+
if (state.isEmpty(nextLine)) {
|
|
1601
|
+
nextLine++;
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
1605
|
+
nextLine++;
|
|
1606
|
+
last = nextLine;
|
|
1607
|
+
continue;
|
|
1608
|
+
}
|
|
1609
|
+
break;
|
|
1610
|
+
}
|
|
1611
|
+
state.line = last;
|
|
1612
|
+
const token = state.push("code_block", "code", 0);
|
|
1613
|
+
token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + "\n";
|
|
1614
|
+
token.map = [startLine, state.line];
|
|
1615
|
+
return true;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function fence(state, startLine, endLine, silent) {
|
|
1619
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
1620
|
+
let max = state.eMarks[startLine];
|
|
1621
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
1622
|
+
return false;
|
|
1623
|
+
}
|
|
1624
|
+
if (pos + 3 > max) {
|
|
1625
|
+
return false;
|
|
1626
|
+
}
|
|
1627
|
+
const marker = state.src.charCodeAt(pos);
|
|
1628
|
+
if (marker !== 126 && marker !== 96) {
|
|
1629
|
+
return false;
|
|
1630
|
+
}
|
|
1631
|
+
let mem = pos;
|
|
1632
|
+
pos = state.skipChars(pos, marker);
|
|
1633
|
+
let len = pos - mem;
|
|
1634
|
+
if (len < 3) {
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
const markup = state.src.slice(mem, pos);
|
|
1638
|
+
const params = state.src.slice(pos, max);
|
|
1639
|
+
if (marker === 96) {
|
|
1640
|
+
if (params.indexOf(String.fromCharCode(marker)) >= 0) {
|
|
1641
|
+
return false;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
if (silent) {
|
|
1645
|
+
return true;
|
|
1646
|
+
}
|
|
1647
|
+
let nextLine = startLine;
|
|
1648
|
+
let haveEndMarker = false;
|
|
1649
|
+
for (; ; ) {
|
|
1650
|
+
nextLine++;
|
|
1651
|
+
if (nextLine >= endLine) {
|
|
1652
|
+
break;
|
|
1653
|
+
}
|
|
1654
|
+
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
1655
|
+
max = state.eMarks[nextLine];
|
|
1656
|
+
if (pos < max && state.sCount[nextLine] < state.blkIndent) {
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
if (state.src.charCodeAt(pos) !== marker) {
|
|
1660
|
+
continue;
|
|
1661
|
+
}
|
|
1662
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
1663
|
+
continue;
|
|
1664
|
+
}
|
|
1665
|
+
pos = state.skipChars(pos, marker);
|
|
1666
|
+
if (pos - mem < len) {
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
pos = state.skipSpaces(pos);
|
|
1670
|
+
if (pos < max) {
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
haveEndMarker = true;
|
|
1674
|
+
break;
|
|
1675
|
+
}
|
|
1676
|
+
len = state.sCount[startLine];
|
|
1677
|
+
state.line = nextLine + (haveEndMarker ? 1 : 0);
|
|
1678
|
+
const token = state.push("fence", "code", 0);
|
|
1679
|
+
token.info = params;
|
|
1680
|
+
token.content = state.getLines(startLine + 1, nextLine, len, true);
|
|
1681
|
+
token.markup = markup;
|
|
1682
|
+
token.map = [startLine, state.line];
|
|
1683
|
+
return true;
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
function blockquote(state, startLine, endLine, silent) {
|
|
1687
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
1688
|
+
let max = state.eMarks[startLine];
|
|
1689
|
+
const oldLineMax = state.lineMax;
|
|
1690
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
1691
|
+
return false;
|
|
1692
|
+
}
|
|
1693
|
+
if (state.src.charCodeAt(pos) !== 62) {
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
if (silent) {
|
|
1697
|
+
return true;
|
|
1698
|
+
}
|
|
1699
|
+
const oldBMarks = [];
|
|
1700
|
+
const oldBSCount = [];
|
|
1701
|
+
const oldSCount = [];
|
|
1702
|
+
const oldTShift = [];
|
|
1703
|
+
const terminatorRules = state.md.block.ruler.getRules("blockquote");
|
|
1704
|
+
const oldParentType = state.parentType;
|
|
1705
|
+
state.parentType = "blockquote";
|
|
1706
|
+
let lastLineEmpty = false;
|
|
1707
|
+
let nextLine;
|
|
1708
|
+
for (nextLine = startLine; nextLine < endLine; nextLine++) {
|
|
1709
|
+
const isOutdented = state.sCount[nextLine] < state.blkIndent;
|
|
1710
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
1711
|
+
max = state.eMarks[nextLine];
|
|
1712
|
+
if (pos >= max) {
|
|
1713
|
+
break;
|
|
1714
|
+
}
|
|
1715
|
+
if (state.src.charCodeAt(pos++) === 62 && !isOutdented) {
|
|
1716
|
+
let initial = state.sCount[nextLine] + 1;
|
|
1717
|
+
let spaceAfterMarker;
|
|
1718
|
+
let adjustTab;
|
|
1719
|
+
if (state.src.charCodeAt(pos) === 32) {
|
|
1720
|
+
pos++;
|
|
1721
|
+
initial++;
|
|
1722
|
+
adjustTab = false;
|
|
1723
|
+
spaceAfterMarker = true;
|
|
1724
|
+
} else if (state.src.charCodeAt(pos) === 9) {
|
|
1725
|
+
spaceAfterMarker = true;
|
|
1726
|
+
if ((state.bsCount[nextLine] + initial) % 4 === 3) {
|
|
1727
|
+
pos++;
|
|
1728
|
+
initial++;
|
|
1729
|
+
adjustTab = false;
|
|
1730
|
+
} else {
|
|
1731
|
+
adjustTab = true;
|
|
1732
|
+
}
|
|
1733
|
+
} else {
|
|
1734
|
+
spaceAfterMarker = false;
|
|
1735
|
+
}
|
|
1736
|
+
let offset = initial;
|
|
1737
|
+
oldBMarks.push(state.bMarks[nextLine]);
|
|
1738
|
+
state.bMarks[nextLine] = pos;
|
|
1739
|
+
while (pos < max) {
|
|
1740
|
+
const ch = state.src.charCodeAt(pos);
|
|
1741
|
+
if (isSpace(ch)) {
|
|
1742
|
+
if (ch === 9) {
|
|
1743
|
+
offset += 4 - (offset + state.bsCount[nextLine] + (adjustTab ? 1 : 0)) % 4;
|
|
1744
|
+
} else {
|
|
1745
|
+
offset++;
|
|
1746
|
+
}
|
|
1747
|
+
} else {
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
pos++;
|
|
1751
|
+
}
|
|
1752
|
+
lastLineEmpty = pos >= max;
|
|
1753
|
+
oldBSCount.push(state.bsCount[nextLine]);
|
|
1754
|
+
state.bsCount[nextLine] = state.sCount[nextLine] + 1 + (spaceAfterMarker ? 1 : 0);
|
|
1755
|
+
oldSCount.push(state.sCount[nextLine]);
|
|
1756
|
+
state.sCount[nextLine] = offset - initial;
|
|
1757
|
+
oldTShift.push(state.tShift[nextLine]);
|
|
1758
|
+
state.tShift[nextLine] = pos - state.bMarks[nextLine];
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
if (lastLineEmpty) {
|
|
1762
|
+
break;
|
|
1763
|
+
}
|
|
1764
|
+
let terminate = false;
|
|
1765
|
+
for (let i = 0, l = terminatorRules.length; i < l; i++) {
|
|
1766
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
1767
|
+
terminate = true;
|
|
1768
|
+
break;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
if (terminate) {
|
|
1772
|
+
state.lineMax = nextLine;
|
|
1773
|
+
if (state.blkIndent !== 0) {
|
|
1774
|
+
oldBMarks.push(state.bMarks[nextLine]);
|
|
1775
|
+
oldBSCount.push(state.bsCount[nextLine]);
|
|
1776
|
+
oldTShift.push(state.tShift[nextLine]);
|
|
1777
|
+
oldSCount.push(state.sCount[nextLine]);
|
|
1778
|
+
state.sCount[nextLine] -= state.blkIndent;
|
|
1779
|
+
}
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
oldBMarks.push(state.bMarks[nextLine]);
|
|
1783
|
+
oldBSCount.push(state.bsCount[nextLine]);
|
|
1784
|
+
oldTShift.push(state.tShift[nextLine]);
|
|
1785
|
+
oldSCount.push(state.sCount[nextLine]);
|
|
1786
|
+
state.sCount[nextLine] = -1;
|
|
1787
|
+
}
|
|
1788
|
+
const oldIndent = state.blkIndent;
|
|
1789
|
+
state.blkIndent = 0;
|
|
1790
|
+
const token_o = state.push("blockquote_open", "blockquote", 1);
|
|
1791
|
+
token_o.markup = ">";
|
|
1792
|
+
const lines = [startLine, 0];
|
|
1793
|
+
token_o.map = lines;
|
|
1794
|
+
state.md.block.tokenize(state, startLine, nextLine);
|
|
1795
|
+
const token_c = state.push("blockquote_close", "blockquote", -1);
|
|
1796
|
+
token_c.markup = ">";
|
|
1797
|
+
state.lineMax = oldLineMax;
|
|
1798
|
+
state.parentType = oldParentType;
|
|
1799
|
+
lines[1] = state.line;
|
|
1800
|
+
for (let i = 0; i < oldTShift.length; i++) {
|
|
1801
|
+
state.bMarks[i + startLine] = oldBMarks[i];
|
|
1802
|
+
state.tShift[i + startLine] = oldTShift[i];
|
|
1803
|
+
state.sCount[i + startLine] = oldSCount[i];
|
|
1804
|
+
state.bsCount[i + startLine] = oldBSCount[i];
|
|
1805
|
+
}
|
|
1806
|
+
state.blkIndent = oldIndent;
|
|
1807
|
+
return true;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
function hr(state, startLine, endLine, silent) {
|
|
1811
|
+
const max = state.eMarks[startLine];
|
|
1812
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
1813
|
+
return false;
|
|
1814
|
+
}
|
|
1815
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
1816
|
+
const marker = state.src.charCodeAt(pos++);
|
|
1817
|
+
if (marker !== 42 && marker !== 45 && marker !== 95) {
|
|
1818
|
+
return false;
|
|
1819
|
+
}
|
|
1820
|
+
let cnt = 1;
|
|
1821
|
+
while (pos < max) {
|
|
1822
|
+
const ch = state.src.charCodeAt(pos++);
|
|
1823
|
+
if (ch !== marker && !isSpace(ch)) {
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
if (ch === marker) {
|
|
1827
|
+
cnt++;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
if (cnt < 3) {
|
|
1831
|
+
return false;
|
|
1832
|
+
}
|
|
1833
|
+
if (silent) {
|
|
1834
|
+
return true;
|
|
1835
|
+
}
|
|
1836
|
+
state.line = startLine + 1;
|
|
1837
|
+
const token = state.push("hr", "hr", 0);
|
|
1838
|
+
token.map = [startLine, state.line];
|
|
1839
|
+
token.markup = Array(cnt + 1).join(String.fromCharCode(marker));
|
|
1840
|
+
return true;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
function skipBulletListMarker(state, startLine) {
|
|
1844
|
+
const max = state.eMarks[startLine];
|
|
1845
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
1846
|
+
const marker = state.src.charCodeAt(pos++);
|
|
1847
|
+
if (marker !== 42 && marker !== 45 && marker !== 43) {
|
|
1848
|
+
return -1;
|
|
1849
|
+
}
|
|
1850
|
+
if (pos < max) {
|
|
1851
|
+
const ch = state.src.charCodeAt(pos);
|
|
1852
|
+
if (!isSpace(ch)) {
|
|
1853
|
+
return -1;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return pos;
|
|
1857
|
+
}
|
|
1858
|
+
function skipOrderedListMarker(state, startLine) {
|
|
1859
|
+
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
1860
|
+
const max = state.eMarks[startLine];
|
|
1861
|
+
let pos = start;
|
|
1862
|
+
if (pos + 1 >= max) {
|
|
1863
|
+
return -1;
|
|
1864
|
+
}
|
|
1865
|
+
let ch = state.src.charCodeAt(pos++);
|
|
1866
|
+
if (ch < 48 || ch > 57) {
|
|
1867
|
+
return -1;
|
|
1868
|
+
}
|
|
1869
|
+
for (; ; ) {
|
|
1870
|
+
if (pos >= max) {
|
|
1871
|
+
return -1;
|
|
1872
|
+
}
|
|
1873
|
+
ch = state.src.charCodeAt(pos++);
|
|
1874
|
+
if (ch >= 48 && ch <= 57) {
|
|
1875
|
+
if (pos - start >= 10) {
|
|
1876
|
+
return -1;
|
|
1877
|
+
}
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
if (ch === 41 || ch === 46) {
|
|
1881
|
+
break;
|
|
1882
|
+
}
|
|
1883
|
+
return -1;
|
|
1884
|
+
}
|
|
1885
|
+
if (pos < max) {
|
|
1886
|
+
ch = state.src.charCodeAt(pos);
|
|
1887
|
+
if (!isSpace(ch)) {
|
|
1888
|
+
return -1;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
return pos;
|
|
1892
|
+
}
|
|
1893
|
+
function markTightParagraphs(state, idx) {
|
|
1894
|
+
const level = state.level + 2;
|
|
1895
|
+
for (let i = idx + 2, l = state.tokens.length - 2; i < l; i++) {
|
|
1896
|
+
if (state.tokens[i].level === level && state.tokens[i].type === "paragraph_open") {
|
|
1897
|
+
state.tokens[i + 2].hidden = true;
|
|
1898
|
+
state.tokens[i].hidden = true;
|
|
1899
|
+
i += 2;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
function list(state, startLine, endLine, silent) {
|
|
1904
|
+
let max, pos, start, token;
|
|
1905
|
+
let nextLine = startLine;
|
|
1906
|
+
let tight = true;
|
|
1907
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
if (state.listIndent >= 0 && state.sCount[nextLine] - state.listIndent >= 4 && state.sCount[nextLine] < state.blkIndent) {
|
|
1911
|
+
return false;
|
|
1912
|
+
}
|
|
1913
|
+
let isTerminatingParagraph = false;
|
|
1914
|
+
if (silent && state.parentType === "paragraph") {
|
|
1915
|
+
if (state.sCount[nextLine] >= state.blkIndent) {
|
|
1916
|
+
isTerminatingParagraph = true;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
let isOrdered;
|
|
1920
|
+
let markerValue;
|
|
1921
|
+
let posAfterMarker;
|
|
1922
|
+
if ((posAfterMarker = skipOrderedListMarker(state, nextLine)) >= 0) {
|
|
1923
|
+
isOrdered = true;
|
|
1924
|
+
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
1925
|
+
markerValue = Number(state.src.slice(start, posAfterMarker - 1));
|
|
1926
|
+
if (isTerminatingParagraph && markerValue !== 1) return false;
|
|
1927
|
+
} else if ((posAfterMarker = skipBulletListMarker(state, nextLine)) >= 0) {
|
|
1928
|
+
isOrdered = false;
|
|
1929
|
+
} else {
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
if (isTerminatingParagraph) {
|
|
1933
|
+
if (state.skipSpaces(posAfterMarker) >= state.eMarks[nextLine]) return false;
|
|
1934
|
+
}
|
|
1935
|
+
if (silent) {
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
const markerCharCode = state.src.charCodeAt(posAfterMarker - 1);
|
|
1939
|
+
const listTokIdx = state.tokens.length;
|
|
1940
|
+
if (isOrdered) {
|
|
1941
|
+
token = state.push("ordered_list_open", "ol", 1);
|
|
1942
|
+
if (markerValue !== 1) {
|
|
1943
|
+
token.attrs = [["start", markerValue]];
|
|
1944
|
+
}
|
|
1945
|
+
} else {
|
|
1946
|
+
token = state.push("bullet_list_open", "ul", 1);
|
|
1947
|
+
}
|
|
1948
|
+
const listLines = [nextLine, 0];
|
|
1949
|
+
token.map = listLines;
|
|
1950
|
+
token.markup = String.fromCharCode(markerCharCode);
|
|
1951
|
+
let prevEmptyEnd = false;
|
|
1952
|
+
const terminatorRules = state.md.block.ruler.getRules("list");
|
|
1953
|
+
const oldParentType = state.parentType;
|
|
1954
|
+
state.parentType = "list";
|
|
1955
|
+
while (nextLine < endLine) {
|
|
1956
|
+
pos = posAfterMarker;
|
|
1957
|
+
max = state.eMarks[nextLine];
|
|
1958
|
+
const initial = state.sCount[nextLine] + posAfterMarker - (state.bMarks[nextLine] + state.tShift[nextLine]);
|
|
1959
|
+
let offset = initial;
|
|
1960
|
+
while (pos < max) {
|
|
1961
|
+
const ch = state.src.charCodeAt(pos);
|
|
1962
|
+
if (ch === 9) {
|
|
1963
|
+
offset += 4 - (offset + state.bsCount[nextLine]) % 4;
|
|
1964
|
+
} else if (ch === 32) {
|
|
1965
|
+
offset++;
|
|
1966
|
+
} else {
|
|
1967
|
+
break;
|
|
1968
|
+
}
|
|
1969
|
+
pos++;
|
|
1970
|
+
}
|
|
1971
|
+
const contentStart = pos;
|
|
1972
|
+
let indentAfterMarker;
|
|
1973
|
+
if (contentStart >= max) {
|
|
1974
|
+
indentAfterMarker = 1;
|
|
1975
|
+
} else {
|
|
1976
|
+
indentAfterMarker = offset - initial;
|
|
1977
|
+
}
|
|
1978
|
+
if (indentAfterMarker > 4) {
|
|
1979
|
+
indentAfterMarker = 1;
|
|
1980
|
+
}
|
|
1981
|
+
const indent = initial + indentAfterMarker;
|
|
1982
|
+
token = state.push("list_item_open", "li", 1);
|
|
1983
|
+
token.markup = String.fromCharCode(markerCharCode);
|
|
1984
|
+
const itemLines = [nextLine, 0];
|
|
1985
|
+
token.map = itemLines;
|
|
1986
|
+
if (isOrdered) {
|
|
1987
|
+
token.info = state.src.slice(start, posAfterMarker - 1);
|
|
1988
|
+
}
|
|
1989
|
+
const oldTight = state.tight;
|
|
1990
|
+
const oldTShift = state.tShift[nextLine];
|
|
1991
|
+
const oldSCount = state.sCount[nextLine];
|
|
1992
|
+
const oldListIndent = state.listIndent;
|
|
1993
|
+
state.listIndent = state.blkIndent;
|
|
1994
|
+
state.blkIndent = indent;
|
|
1995
|
+
state.tight = true;
|
|
1996
|
+
state.tShift[nextLine] = contentStart - state.bMarks[nextLine];
|
|
1997
|
+
state.sCount[nextLine] = offset;
|
|
1998
|
+
if (contentStart >= max && state.isEmpty(nextLine + 1)) {
|
|
1999
|
+
state.line = Math.min(state.line + 2, endLine);
|
|
2000
|
+
} else {
|
|
2001
|
+
state.md.block.tokenize(state, nextLine, endLine);
|
|
2002
|
+
}
|
|
2003
|
+
if (!state.tight || prevEmptyEnd) {
|
|
2004
|
+
tight = false;
|
|
2005
|
+
}
|
|
2006
|
+
prevEmptyEnd = state.line - nextLine > 1 && state.isEmpty(state.line - 1);
|
|
2007
|
+
state.blkIndent = state.listIndent;
|
|
2008
|
+
state.listIndent = oldListIndent;
|
|
2009
|
+
state.tShift[nextLine] = oldTShift;
|
|
2010
|
+
state.sCount[nextLine] = oldSCount;
|
|
2011
|
+
state.tight = oldTight;
|
|
2012
|
+
token = state.push("list_item_close", "li", -1);
|
|
2013
|
+
token.markup = String.fromCharCode(markerCharCode);
|
|
2014
|
+
nextLine = state.line;
|
|
2015
|
+
itemLines[1] = nextLine;
|
|
2016
|
+
if (nextLine >= endLine) {
|
|
2017
|
+
break;
|
|
2018
|
+
}
|
|
2019
|
+
if (state.sCount[nextLine] < state.blkIndent) {
|
|
2020
|
+
break;
|
|
2021
|
+
}
|
|
2022
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
let terminate = false;
|
|
2026
|
+
for (let i = 0, l = terminatorRules.length; i < l; i++) {
|
|
2027
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
2028
|
+
terminate = true;
|
|
2029
|
+
break;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
if (terminate) {
|
|
2033
|
+
break;
|
|
2034
|
+
}
|
|
2035
|
+
if (isOrdered) {
|
|
2036
|
+
posAfterMarker = skipOrderedListMarker(state, nextLine);
|
|
2037
|
+
if (posAfterMarker < 0) {
|
|
2038
|
+
break;
|
|
2039
|
+
}
|
|
2040
|
+
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
2041
|
+
} else {
|
|
2042
|
+
posAfterMarker = skipBulletListMarker(state, nextLine);
|
|
2043
|
+
if (posAfterMarker < 0) {
|
|
2044
|
+
break;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
if (markerCharCode !== state.src.charCodeAt(posAfterMarker - 1)) {
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
if (isOrdered) {
|
|
2052
|
+
token = state.push("ordered_list_close", "ol", -1);
|
|
2053
|
+
} else {
|
|
2054
|
+
token = state.push("bullet_list_close", "ul", -1);
|
|
2055
|
+
}
|
|
2056
|
+
token.markup = String.fromCharCode(markerCharCode);
|
|
2057
|
+
listLines[1] = nextLine;
|
|
2058
|
+
state.line = nextLine;
|
|
2059
|
+
state.parentType = oldParentType;
|
|
2060
|
+
if (tight) {
|
|
2061
|
+
markTightParagraphs(state, listTokIdx);
|
|
2062
|
+
}
|
|
2063
|
+
return true;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
var MAX_LABEL_LENGTH = 999;
|
|
2067
|
+
function countCodePoints(str) {
|
|
2068
|
+
let length = str.length;
|
|
2069
|
+
for (let i = 0; i < str.length - 1; i++) {
|
|
2070
|
+
const high = str.charCodeAt(i);
|
|
2071
|
+
if (high < 55296 || high > 56319) {
|
|
2072
|
+
continue;
|
|
2073
|
+
}
|
|
2074
|
+
const low = str.charCodeAt(i + 1);
|
|
2075
|
+
if (low >= 56320 && low <= 57343) {
|
|
2076
|
+
length--;
|
|
2077
|
+
i++;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
return length;
|
|
2081
|
+
}
|
|
2082
|
+
function lineEnd(state, line) {
|
|
2083
|
+
return Math.min(state.eMarks[line] + 1, state.src.length);
|
|
2084
|
+
}
|
|
2085
|
+
function getNextLinePos(state, nextLine) {
|
|
2086
|
+
const endLine = state.lineMax;
|
|
2087
|
+
if (nextLine >= endLine || state.isEmpty(nextLine)) {
|
|
2088
|
+
return -1;
|
|
2089
|
+
}
|
|
2090
|
+
let isContinuation = false;
|
|
2091
|
+
if (state.sCount[nextLine] - state.blkIndent > 3) {
|
|
2092
|
+
isContinuation = true;
|
|
2093
|
+
}
|
|
2094
|
+
if (state.sCount[nextLine] < 0) {
|
|
2095
|
+
isContinuation = true;
|
|
2096
|
+
}
|
|
2097
|
+
if (!isContinuation) {
|
|
2098
|
+
const terminatorRules = state.md.block.ruler.getRules("reference");
|
|
2099
|
+
const oldParentType = state.parentType;
|
|
2100
|
+
state.parentType = "reference";
|
|
2101
|
+
let terminate = false;
|
|
2102
|
+
for (let i = 0, l = terminatorRules.length; i < l; i++) {
|
|
2103
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
2104
|
+
terminate = true;
|
|
2105
|
+
break;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
state.parentType = oldParentType;
|
|
2109
|
+
if (terminate) {
|
|
2110
|
+
return -1;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
return state.bMarks[nextLine] + state.tShift[nextLine];
|
|
2114
|
+
}
|
|
2115
|
+
function reference(state, startLine, _endLine, silent) {
|
|
2116
|
+
const src = state.src;
|
|
2117
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
2118
|
+
let nextLine = startLine + 1;
|
|
2119
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
2120
|
+
return false;
|
|
2121
|
+
}
|
|
2122
|
+
if (src.charCodeAt(pos) !== 91) {
|
|
2123
|
+
return false;
|
|
2124
|
+
}
|
|
2125
|
+
let max = lineEnd(state, startLine);
|
|
2126
|
+
let rawLabel = "";
|
|
2127
|
+
let labelEnd = -1;
|
|
2128
|
+
let segmentStart = ++pos;
|
|
2129
|
+
while (pos < max) {
|
|
2130
|
+
if (rawLabel.length + pos - segmentStart > MAX_LABEL_LENGTH * 2) {
|
|
2131
|
+
return false;
|
|
2132
|
+
}
|
|
2133
|
+
let ch = src.charCodeAt(pos);
|
|
2134
|
+
if (ch === 91) {
|
|
2135
|
+
return false;
|
|
2136
|
+
}
|
|
2137
|
+
if (ch === 93) {
|
|
2138
|
+
labelEnd = pos;
|
|
2139
|
+
break;
|
|
2140
|
+
}
|
|
2141
|
+
if (ch === 92) {
|
|
2142
|
+
ch = src.charCodeAt(++pos);
|
|
2143
|
+
}
|
|
2144
|
+
if (ch === 10 && pos < max) {
|
|
2145
|
+
const nextPos = getNextLinePos(state, nextLine);
|
|
2146
|
+
if (nextPos < 0) {
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
rawLabel += src.slice(segmentStart, max);
|
|
2150
|
+
pos = segmentStart = nextPos;
|
|
2151
|
+
max = lineEnd(state, nextLine++);
|
|
2152
|
+
continue;
|
|
2153
|
+
}
|
|
2154
|
+
pos++;
|
|
2155
|
+
}
|
|
2156
|
+
if (labelEnd < 0 || src.charCodeAt(labelEnd + 1) !== 58) {
|
|
2157
|
+
return false;
|
|
2158
|
+
}
|
|
2159
|
+
rawLabel += src.slice(segmentStart, labelEnd);
|
|
2160
|
+
if (rawLabel.length > MAX_LABEL_LENGTH && countCodePoints(rawLabel) > MAX_LABEL_LENGTH) {
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
pos = labelEnd + 2;
|
|
2164
|
+
while (pos < max) {
|
|
2165
|
+
const ch = src.charCodeAt(pos);
|
|
2166
|
+
if (ch === 10) {
|
|
2167
|
+
const nextPos = getNextLinePos(state, nextLine);
|
|
2168
|
+
if (nextPos < 0) {
|
|
2169
|
+
break;
|
|
2170
|
+
}
|
|
2171
|
+
pos = nextPos;
|
|
2172
|
+
max = lineEnd(state, nextLine++);
|
|
2173
|
+
} else if (isSpace(ch)) {
|
|
2174
|
+
pos++;
|
|
2175
|
+
} else {
|
|
2176
|
+
break;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
const destRes = state.md.helpers.parseLinkDestination(src, pos, max);
|
|
2180
|
+
if (!destRes.ok) {
|
|
2181
|
+
return false;
|
|
2182
|
+
}
|
|
2183
|
+
const href = state.md.normalizeLink(destRes.str);
|
|
2184
|
+
if (!state.md.validateLink(href)) {
|
|
2185
|
+
return false;
|
|
2186
|
+
}
|
|
2187
|
+
pos = destRes.pos;
|
|
2188
|
+
const destEndPos = pos;
|
|
2189
|
+
const destEndMax = max;
|
|
2190
|
+
const destEndLineNo = nextLine;
|
|
2191
|
+
while (pos < max) {
|
|
2192
|
+
const ch = src.charCodeAt(pos);
|
|
2193
|
+
if (ch === 10) {
|
|
2194
|
+
const nextPos = getNextLinePos(state, nextLine);
|
|
2195
|
+
if (nextPos < 0) {
|
|
2196
|
+
break;
|
|
2197
|
+
}
|
|
2198
|
+
pos = nextPos;
|
|
2199
|
+
max = lineEnd(state, nextLine++);
|
|
2200
|
+
} else if (isSpace(ch)) {
|
|
2201
|
+
pos++;
|
|
2202
|
+
} else {
|
|
2203
|
+
break;
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
const titleStart = pos;
|
|
2207
|
+
let titleRes = state.md.helpers.parseLinkTitle(src, pos, max);
|
|
2208
|
+
while (titleRes.can_continue) {
|
|
2209
|
+
const nextPos = getNextLinePos(state, nextLine);
|
|
2210
|
+
if (nextPos < 0) break;
|
|
2211
|
+
pos = nextPos;
|
|
2212
|
+
max = lineEnd(state, nextLine++);
|
|
2213
|
+
titleRes = state.md.helpers.parseLinkTitle(src, pos, max, titleRes);
|
|
2214
|
+
}
|
|
2215
|
+
let title;
|
|
2216
|
+
if (titleStart !== destEndPos && titleRes.ok) {
|
|
2217
|
+
title = titleRes.str;
|
|
2218
|
+
pos = titleRes.pos;
|
|
2219
|
+
} else {
|
|
2220
|
+
title = "";
|
|
2221
|
+
pos = destEndPos;
|
|
2222
|
+
max = destEndMax;
|
|
2223
|
+
nextLine = destEndLineNo;
|
|
2224
|
+
}
|
|
2225
|
+
while (pos < max) {
|
|
2226
|
+
const ch = src.charCodeAt(pos);
|
|
2227
|
+
if (!isSpace(ch)) {
|
|
2228
|
+
break;
|
|
2229
|
+
}
|
|
2230
|
+
pos++;
|
|
2231
|
+
}
|
|
2232
|
+
if (pos < max && src.charCodeAt(pos) !== 10) {
|
|
2233
|
+
if (title) {
|
|
2234
|
+
title = "";
|
|
2235
|
+
pos = destEndPos;
|
|
2236
|
+
max = destEndMax;
|
|
2237
|
+
nextLine = destEndLineNo;
|
|
2238
|
+
while (pos < max) {
|
|
2239
|
+
const ch = src.charCodeAt(pos);
|
|
2240
|
+
if (!isSpace(ch)) {
|
|
2241
|
+
break;
|
|
2242
|
+
}
|
|
2243
|
+
pos++;
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
if (pos < max && src.charCodeAt(pos) !== 10) {
|
|
2248
|
+
return false;
|
|
2249
|
+
}
|
|
2250
|
+
const label = normalizeReference(rawLabel);
|
|
2251
|
+
if (!label) {
|
|
2252
|
+
return false;
|
|
2253
|
+
}
|
|
2254
|
+
if (silent) {
|
|
2255
|
+
return true;
|
|
2256
|
+
}
|
|
2257
|
+
if (typeof state.env.references === "undefined") {
|
|
2258
|
+
state.env.references = {};
|
|
2259
|
+
}
|
|
2260
|
+
if (typeof state.env.references[label] === "undefined") {
|
|
2261
|
+
state.env.references[label] = { title, href };
|
|
2262
|
+
}
|
|
2263
|
+
const token = state.push("reference_definition", "", 0);
|
|
2264
|
+
token.map = [startLine, nextLine];
|
|
2265
|
+
token.hidden = true;
|
|
2266
|
+
const meta = /* @__PURE__ */ Object.create(null);
|
|
2267
|
+
meta.label = label;
|
|
2268
|
+
token.meta = meta;
|
|
2269
|
+
state.line = nextLine;
|
|
2270
|
+
return true;
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
var html_blocks_default = [
|
|
2274
|
+
"address",
|
|
2275
|
+
"article",
|
|
2276
|
+
"aside",
|
|
2277
|
+
"base",
|
|
2278
|
+
"basefont",
|
|
2279
|
+
"blockquote",
|
|
2280
|
+
"body",
|
|
2281
|
+
"caption",
|
|
2282
|
+
"center",
|
|
2283
|
+
"col",
|
|
2284
|
+
"colgroup",
|
|
2285
|
+
"dd",
|
|
2286
|
+
"details",
|
|
2287
|
+
"dialog",
|
|
2288
|
+
"dir",
|
|
2289
|
+
"div",
|
|
2290
|
+
"dl",
|
|
2291
|
+
"dt",
|
|
2292
|
+
"fieldset",
|
|
2293
|
+
"figcaption",
|
|
2294
|
+
"figure",
|
|
2295
|
+
"footer",
|
|
2296
|
+
"form",
|
|
2297
|
+
"frame",
|
|
2298
|
+
"frameset",
|
|
2299
|
+
"h1",
|
|
2300
|
+
"h2",
|
|
2301
|
+
"h3",
|
|
2302
|
+
"h4",
|
|
2303
|
+
"h5",
|
|
2304
|
+
"h6",
|
|
2305
|
+
"head",
|
|
2306
|
+
"header",
|
|
2307
|
+
"hr",
|
|
2308
|
+
"html",
|
|
2309
|
+
"iframe",
|
|
2310
|
+
"legend",
|
|
2311
|
+
"li",
|
|
2312
|
+
"link",
|
|
2313
|
+
"main",
|
|
2314
|
+
"menu",
|
|
2315
|
+
"menuitem",
|
|
2316
|
+
"nav",
|
|
2317
|
+
"noframes",
|
|
2318
|
+
"ol",
|
|
2319
|
+
"optgroup",
|
|
2320
|
+
"option",
|
|
2321
|
+
"p",
|
|
2322
|
+
"param",
|
|
2323
|
+
"search",
|
|
2324
|
+
"section",
|
|
2325
|
+
"summary",
|
|
2326
|
+
"table",
|
|
2327
|
+
"tbody",
|
|
2328
|
+
"td",
|
|
2329
|
+
"tfoot",
|
|
2330
|
+
"th",
|
|
2331
|
+
"thead",
|
|
2332
|
+
"title",
|
|
2333
|
+
"tr",
|
|
2334
|
+
"track",
|
|
2335
|
+
"ul"
|
|
2336
|
+
];
|
|
2337
|
+
|
|
2338
|
+
var attr_name = "[a-zA-Z_:][a-zA-Z0-9:._-]*";
|
|
2339
|
+
var unquoted = "[^\"'=<>`\\x00-\\x20]+";
|
|
2340
|
+
var single_quoted = "'[^']*'";
|
|
2341
|
+
var double_quoted = '"[^"]*"';
|
|
2342
|
+
var attr_value = `(?:${unquoted}|${single_quoted}|${double_quoted})`;
|
|
2343
|
+
var attribute = `(?:\\s+${attr_name}(?:\\s*=\\s*${attr_value})?)`;
|
|
2344
|
+
var open_tag = `<[A-Za-z][A-Za-z0-9\\-]*${attribute}*\\s*\\/?>`;
|
|
2345
|
+
var close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>";
|
|
2346
|
+
var comment = "<!---?>|<!--(?:[^-]|-[^-]|--[^>])*-->";
|
|
2347
|
+
var processing = "<[?][\\s\\S]*?[?]>";
|
|
2348
|
+
var declaration = "<![A-Za-z][^>]*>";
|
|
2349
|
+
var cdata = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>";
|
|
2350
|
+
var HTML_TAG_RE = new RegExp(
|
|
2351
|
+
`^(?:${open_tag}|${close_tag}|${comment}|${processing}|${declaration}|${cdata})`
|
|
2352
|
+
);
|
|
2353
|
+
var HTML_OPEN_CLOSE_TAG_RE = new RegExp(`^(?:${open_tag}|${close_tag})`);
|
|
2354
|
+
|
|
2355
|
+
var HTML_SEQUENCES = [
|
|
2356
|
+
[/^<(script|pre|style|textarea)(?=(\s|>|$))/i, /<\/(script|pre|style|textarea)>/i, true],
|
|
2357
|
+
[/^<!--/, /-->/, true],
|
|
2358
|
+
[/^<\?/, /\?>/, true],
|
|
2359
|
+
[/^<![A-Za-z]/, />/, true],
|
|
2360
|
+
[/^<!\[CDATA\[/, /\]\]>/, true],
|
|
2361
|
+
[new RegExp(`^</?(${html_blocks_default.join("|")})(?=(\\s|/?>|$))`, "i"), /^$/, true],
|
|
2362
|
+
[new RegExp(`${HTML_OPEN_CLOSE_TAG_RE.source}\\s*$`), /^$/, false]
|
|
2363
|
+
];
|
|
2364
|
+
function html_block(state, startLine, endLine, silent) {
|
|
2365
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
2366
|
+
let max = state.eMarks[startLine];
|
|
2367
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
2368
|
+
return false;
|
|
2369
|
+
}
|
|
2370
|
+
if (!state.md.options.html) {
|
|
2371
|
+
return false;
|
|
2372
|
+
}
|
|
2373
|
+
if (state.src.charCodeAt(pos) !== 60) {
|
|
2374
|
+
return false;
|
|
2375
|
+
}
|
|
2376
|
+
let lineText = state.src.slice(pos, max);
|
|
2377
|
+
let i = 0;
|
|
2378
|
+
for (; i < HTML_SEQUENCES.length; i++) {
|
|
2379
|
+
if (HTML_SEQUENCES[i][0].test(lineText)) {
|
|
2380
|
+
break;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
if (i === HTML_SEQUENCES.length) {
|
|
2384
|
+
return false;
|
|
2385
|
+
}
|
|
2386
|
+
if (silent) {
|
|
2387
|
+
return HTML_SEQUENCES[i][2];
|
|
2388
|
+
}
|
|
2389
|
+
let nextLine = startLine + 1;
|
|
2390
|
+
const endsOnBlankLine = HTML_SEQUENCES[i][1].test("");
|
|
2391
|
+
if (!HTML_SEQUENCES[i][1].test(lineText)) {
|
|
2392
|
+
for (; nextLine < endLine; nextLine++) {
|
|
2393
|
+
if (state.sCount[nextLine] < state.blkIndent) {
|
|
2394
|
+
if (endsOnBlankLine || !state.isEmpty(nextLine)) {
|
|
2395
|
+
break;
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
2399
|
+
max = state.eMarks[nextLine];
|
|
2400
|
+
lineText = state.src.slice(pos, max);
|
|
2401
|
+
if (HTML_SEQUENCES[i][1].test(lineText)) {
|
|
2402
|
+
if (lineText.length !== 0) {
|
|
2403
|
+
nextLine++;
|
|
2404
|
+
}
|
|
2405
|
+
break;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
state.line = nextLine;
|
|
2410
|
+
const token = state.push("html_block", "", 0);
|
|
2411
|
+
token.map = [startLine, nextLine];
|
|
2412
|
+
token.content = state.getLines(startLine, nextLine, state.blkIndent, true);
|
|
2413
|
+
return true;
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
function heading(state, startLine, endLine, silent) {
|
|
2417
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
2418
|
+
let max = state.eMarks[startLine];
|
|
2419
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
2420
|
+
return false;
|
|
2421
|
+
}
|
|
2422
|
+
let ch = state.src.charCodeAt(pos);
|
|
2423
|
+
if (ch !== 35 || pos >= max) {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
let level = 1;
|
|
2427
|
+
ch = state.src.charCodeAt(++pos);
|
|
2428
|
+
while (ch === 35 && pos < max && level <= 6) {
|
|
2429
|
+
level++;
|
|
2430
|
+
ch = state.src.charCodeAt(++pos);
|
|
2431
|
+
}
|
|
2432
|
+
if (level > 6 || pos < max && !isSpace(ch)) {
|
|
2433
|
+
return false;
|
|
2434
|
+
}
|
|
2435
|
+
if (silent) {
|
|
2436
|
+
return true;
|
|
2437
|
+
}
|
|
2438
|
+
max = state.skipSpacesBack(max, pos);
|
|
2439
|
+
const tmp = state.skipCharsBack(max, 35, pos);
|
|
2440
|
+
if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) {
|
|
2441
|
+
max = tmp;
|
|
2442
|
+
}
|
|
2443
|
+
state.line = startLine + 1;
|
|
2444
|
+
const token_o = state.push("heading_open", `h${level}`, 1);
|
|
2445
|
+
token_o.markup = "########".slice(0, level);
|
|
2446
|
+
token_o.map = [startLine, state.line];
|
|
2447
|
+
const token_i = state.push("inline", "", 0);
|
|
2448
|
+
token_i.content = asciiTrim(state.src.slice(pos, max));
|
|
2449
|
+
token_i.map = [startLine, state.line];
|
|
2450
|
+
token_i.children = [];
|
|
2451
|
+
const token_c = state.push("heading_close", `h${level}`, -1);
|
|
2452
|
+
token_c.markup = "########".slice(0, level);
|
|
2453
|
+
return true;
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
function lheading(state, startLine, endLine) {
|
|
2457
|
+
const terminatorRules = state.md.block.ruler.getRules("paragraph");
|
|
2458
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
2459
|
+
return false;
|
|
2460
|
+
}
|
|
2461
|
+
const oldParentType = state.parentType;
|
|
2462
|
+
state.parentType = "paragraph";
|
|
2463
|
+
let level = 0;
|
|
2464
|
+
let marker;
|
|
2465
|
+
let nextLine = startLine + 1;
|
|
2466
|
+
for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) {
|
|
2467
|
+
if (state.sCount[nextLine] - state.blkIndent > 3) {
|
|
2468
|
+
continue;
|
|
2469
|
+
}
|
|
2470
|
+
if (state.sCount[nextLine] >= state.blkIndent) {
|
|
2471
|
+
let pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
2472
|
+
const max = state.eMarks[nextLine];
|
|
2473
|
+
if (pos < max) {
|
|
2474
|
+
marker = state.src.charCodeAt(pos);
|
|
2475
|
+
if (marker === 45 || marker === 61) {
|
|
2476
|
+
pos = state.skipChars(pos, marker);
|
|
2477
|
+
pos = state.skipSpaces(pos);
|
|
2478
|
+
if (pos >= max) {
|
|
2479
|
+
level = marker === 61 ? 1 : 2;
|
|
2480
|
+
break;
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
if (state.sCount[nextLine] < 0) {
|
|
2486
|
+
continue;
|
|
2487
|
+
}
|
|
2488
|
+
let terminate = false;
|
|
2489
|
+
for (let i = 0, l = terminatorRules.length; i < l; i++) {
|
|
2490
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
2491
|
+
terminate = true;
|
|
2492
|
+
break;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
if (terminate) {
|
|
2496
|
+
break;
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
if (!level) {
|
|
2500
|
+
state.parentType = oldParentType;
|
|
2501
|
+
return false;
|
|
2502
|
+
}
|
|
2503
|
+
const content = asciiTrim(state.getLines(startLine, nextLine, state.blkIndent, false));
|
|
2504
|
+
state.line = nextLine + 1;
|
|
2505
|
+
const token_o = state.push("heading_open", `h${level}`, 1);
|
|
2506
|
+
token_o.markup = String.fromCharCode(marker);
|
|
2507
|
+
token_o.map = [startLine, state.line];
|
|
2508
|
+
const token_i = state.push("inline", "", 0);
|
|
2509
|
+
token_i.content = content;
|
|
2510
|
+
token_i.map = [startLine, state.line - 1];
|
|
2511
|
+
token_i.children = [];
|
|
2512
|
+
const token_c = state.push("heading_close", `h${level}`, -1);
|
|
2513
|
+
token_c.markup = String.fromCharCode(marker);
|
|
2514
|
+
state.parentType = oldParentType;
|
|
2515
|
+
return true;
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
function paragraph(state, startLine, endLine) {
|
|
2519
|
+
const terminatorRules = state.md.block.ruler.getRules("paragraph");
|
|
2520
|
+
const oldParentType = state.parentType;
|
|
2521
|
+
let nextLine = startLine + 1;
|
|
2522
|
+
state.parentType = "paragraph";
|
|
2523
|
+
for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) {
|
|
2524
|
+
if (state.sCount[nextLine] - state.blkIndent > 3) {
|
|
2525
|
+
continue;
|
|
2526
|
+
}
|
|
2527
|
+
if (state.sCount[nextLine] < 0) {
|
|
2528
|
+
continue;
|
|
2529
|
+
}
|
|
2530
|
+
let terminate = false;
|
|
2531
|
+
for (let i = 0, l = terminatorRules.length; i < l; i++) {
|
|
2532
|
+
if (terminatorRules[i](state, nextLine, endLine, true)) {
|
|
2533
|
+
terminate = true;
|
|
2534
|
+
break;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
if (terminate) {
|
|
2538
|
+
break;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
const content = asciiTrim(state.getLines(startLine, nextLine, state.blkIndent, false));
|
|
2542
|
+
state.line = nextLine;
|
|
2543
|
+
const token_o = state.push("paragraph_open", "p", 1);
|
|
2544
|
+
token_o.map = [startLine, state.line];
|
|
2545
|
+
const token_i = state.push("inline", "", 0);
|
|
2546
|
+
token_i.content = content;
|
|
2547
|
+
token_i.map = [startLine, state.line];
|
|
2548
|
+
token_i.children = [];
|
|
2549
|
+
state.push("paragraph_close", "p", -1);
|
|
2550
|
+
state.parentType = oldParentType;
|
|
2551
|
+
return true;
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
var _rules2 = [
|
|
2555
|
+
["table", table, ["paragraph", "reference"]],
|
|
2556
|
+
["code", code],
|
|
2557
|
+
["fence", fence, ["paragraph", "reference", "blockquote", "list"]],
|
|
2558
|
+
["blockquote", blockquote, ["paragraph", "reference", "blockquote", "list"]],
|
|
2559
|
+
["hr", hr, ["paragraph", "reference", "blockquote", "list"]],
|
|
2560
|
+
["list", list, ["paragraph", "reference", "blockquote"]],
|
|
2561
|
+
["reference", reference],
|
|
2562
|
+
["html_block", html_block, ["paragraph", "reference", "blockquote"]],
|
|
2563
|
+
["heading", heading, ["paragraph", "reference", "blockquote"]],
|
|
2564
|
+
["lheading", lheading],
|
|
2565
|
+
["paragraph", paragraph]
|
|
2566
|
+
];
|
|
2567
|
+
var ParserBlock = class {
|
|
2568
|
+
ruler = new ruler_default();
|
|
2569
|
+
State = state_block_default;
|
|
2570
|
+
constructor() {
|
|
2571
|
+
for (let i = 0; i < _rules2.length; i++) {
|
|
2572
|
+
this.ruler.push(_rules2[i][0], _rules2[i][1], { alt: (_rules2[i][2] || []).slice() });
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
tokenize(state, startLine, endLine) {
|
|
2576
|
+
const rules = this.ruler.getRules("");
|
|
2577
|
+
const len = rules.length;
|
|
2578
|
+
const maxNesting = state.md.options.maxNesting;
|
|
2579
|
+
let line = startLine;
|
|
2580
|
+
let hasEmptyLines = false;
|
|
2581
|
+
while (line < endLine) {
|
|
2582
|
+
state.line = line = state.skipEmptyLines(line);
|
|
2583
|
+
if (line >= endLine) {
|
|
2584
|
+
break;
|
|
2585
|
+
}
|
|
2586
|
+
if (state.sCount[line] < state.blkIndent) {
|
|
2587
|
+
break;
|
|
2588
|
+
}
|
|
2589
|
+
if (state.level >= maxNesting) {
|
|
2590
|
+
state.line = endLine;
|
|
2591
|
+
break;
|
|
2592
|
+
}
|
|
2593
|
+
const prevLine = state.line;
|
|
2594
|
+
let ok = false;
|
|
2595
|
+
for (let i = 0; i < len; i++) {
|
|
2596
|
+
ok = rules[i](state, line, endLine, false);
|
|
2597
|
+
if (ok) {
|
|
2598
|
+
if (prevLine >= state.line) {
|
|
2599
|
+
throw new Error("block rule didn't increment state.line");
|
|
2600
|
+
}
|
|
2601
|
+
break;
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
if (!ok) throw new Error("none of the block rules matched");
|
|
2605
|
+
state.tight = !hasEmptyLines;
|
|
2606
|
+
if (state.isEmpty(state.line - 1)) {
|
|
2607
|
+
hasEmptyLines = true;
|
|
2608
|
+
}
|
|
2609
|
+
line = state.line;
|
|
2610
|
+
if (line < endLine && state.isEmpty(line)) {
|
|
2611
|
+
hasEmptyLines = true;
|
|
2612
|
+
line++;
|
|
2613
|
+
state.line = line;
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
parse(src, md, env, outTokens) {
|
|
2618
|
+
if (!src) {
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
const state = new this.State(src, md, env, outTokens);
|
|
2622
|
+
this.tokenize(state, state.line, state.lineMax);
|
|
2623
|
+
}
|
|
2624
|
+
};
|
|
2625
|
+
var parser_block_default = ParserBlock;
|
|
2626
|
+
|
|
2627
|
+
var StateInline = class {
|
|
2628
|
+
pos = 0;
|
|
2629
|
+
level = 0;
|
|
2630
|
+
pending = "";
|
|
2631
|
+
pendingLevel = 0;
|
|
2632
|
+
cache = {};
|
|
2633
|
+
backticks = {};
|
|
2634
|
+
backticksScanned = false;
|
|
2635
|
+
skipHtmlSpecial = false;
|
|
2636
|
+
linkLevel = 0;
|
|
2637
|
+
delimiters = [];
|
|
2638
|
+
_prev_delimiters = [];
|
|
2639
|
+
Token = token_default;
|
|
2640
|
+
constructor(src, md, env, outTokens) {
|
|
2641
|
+
this.src = src;
|
|
2642
|
+
this.env = env;
|
|
2643
|
+
this.md = md;
|
|
2644
|
+
this.tokens = outTokens;
|
|
2645
|
+
this.tokens_meta = Array(outTokens.length);
|
|
2646
|
+
this.posMax = this.src.length;
|
|
2647
|
+
}
|
|
2648
|
+
pushPending() {
|
|
2649
|
+
const token = new token_default("text", "", 0);
|
|
2650
|
+
token.content = this.pending;
|
|
2651
|
+
token.level = this.pendingLevel;
|
|
2652
|
+
this.tokens.push(token);
|
|
2653
|
+
this.pending = "";
|
|
2654
|
+
return token;
|
|
2655
|
+
}
|
|
2656
|
+
push(type, tag, nesting) {
|
|
2657
|
+
if (this.pending) {
|
|
2658
|
+
this.pushPending();
|
|
2659
|
+
}
|
|
2660
|
+
const token = new token_default(type, tag, nesting);
|
|
2661
|
+
let token_meta = void 0;
|
|
2662
|
+
if (nesting < 0) {
|
|
2663
|
+
this.level--;
|
|
2664
|
+
this.delimiters = this._prev_delimiters.pop();
|
|
2665
|
+
}
|
|
2666
|
+
token.level = this.level;
|
|
2667
|
+
if (nesting > 0) {
|
|
2668
|
+
this.level++;
|
|
2669
|
+
this._prev_delimiters.push(this.delimiters);
|
|
2670
|
+
this.delimiters = [];
|
|
2671
|
+
token_meta = { delimiters: this.delimiters };
|
|
2672
|
+
}
|
|
2673
|
+
this.pendingLevel = this.level;
|
|
2674
|
+
this.tokens.push(token);
|
|
2675
|
+
this.tokens_meta.push(token_meta);
|
|
2676
|
+
return token;
|
|
2677
|
+
}
|
|
2678
|
+
scanDelims(start, canSplitWord) {
|
|
2679
|
+
const max = this.posMax;
|
|
2680
|
+
const marker = this.src.charCodeAt(start);
|
|
2681
|
+
let lastChar;
|
|
2682
|
+
if (start === 0) {
|
|
2683
|
+
lastChar = 32;
|
|
2684
|
+
} else if (start === 1) {
|
|
2685
|
+
lastChar = this.src.charCodeAt(0);
|
|
2686
|
+
if ((lastChar & 63488) === 55296) {
|
|
2687
|
+
lastChar = 65533;
|
|
2688
|
+
}
|
|
2689
|
+
} else {
|
|
2690
|
+
lastChar = this.src.charCodeAt(start - 1);
|
|
2691
|
+
if ((lastChar & 64512) === 56320) {
|
|
2692
|
+
const highSurr = this.src.charCodeAt(start - 2);
|
|
2693
|
+
lastChar = (highSurr & 64512) === 55296 ? 65536 + (highSurr - 55296 << 10) + (lastChar - 56320) : 65533;
|
|
2694
|
+
} else if ((lastChar & 64512) === 55296) {
|
|
2695
|
+
lastChar = 65533;
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
let pos = start;
|
|
2699
|
+
while (pos < max && this.src.charCodeAt(pos) === marker) {
|
|
2700
|
+
pos++;
|
|
2701
|
+
}
|
|
2702
|
+
const count = pos - start;
|
|
2703
|
+
let nextChar = pos < max ? this.src.charCodeAt(pos) : 32;
|
|
2704
|
+
if ((nextChar & 64512) === 55296) {
|
|
2705
|
+
const lowSurr = this.src.charCodeAt(pos + 1);
|
|
2706
|
+
nextChar = (lowSurr & 64512) === 56320 ? 65536 + (nextChar - 55296 << 10) + (lowSurr - 56320) : 65533;
|
|
2707
|
+
} else if ((nextChar & 64512) === 56320) {
|
|
2708
|
+
nextChar = 65533;
|
|
2709
|
+
}
|
|
2710
|
+
const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar);
|
|
2711
|
+
const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar);
|
|
2712
|
+
const isLastWhiteSpace = isWhiteSpace(lastChar);
|
|
2713
|
+
const isNextWhiteSpace = isWhiteSpace(nextChar);
|
|
2714
|
+
const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar);
|
|
2715
|
+
const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar);
|
|
2716
|
+
const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
|
|
2717
|
+
const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
|
|
2718
|
+
return { can_open, can_close, length: count };
|
|
2719
|
+
}
|
|
2720
|
+
};
|
|
2721
|
+
var state_inline_default = StateInline;
|
|
2722
|
+
|
|
2723
|
+
function isTerminatorChar(ch) {
|
|
2724
|
+
switch (ch) {
|
|
2725
|
+
case 10:
|
|
2726
|
+
case 33:
|
|
2727
|
+
case 35:
|
|
2728
|
+
case 36:
|
|
2729
|
+
case 37:
|
|
2730
|
+
case 38:
|
|
2731
|
+
case 42:
|
|
2732
|
+
case 43:
|
|
2733
|
+
case 45:
|
|
2734
|
+
case 58:
|
|
2735
|
+
case 60:
|
|
2736
|
+
case 61:
|
|
2737
|
+
case 62:
|
|
2738
|
+
case 64:
|
|
2739
|
+
case 91:
|
|
2740
|
+
case 92:
|
|
2741
|
+
case 93:
|
|
2742
|
+
case 94:
|
|
2743
|
+
case 95:
|
|
2744
|
+
case 96:
|
|
2745
|
+
case 123:
|
|
2746
|
+
case 125:
|
|
2747
|
+
case 126:
|
|
2748
|
+
return true;
|
|
2749
|
+
default:
|
|
2750
|
+
return false;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
function text(state, silent) {
|
|
2754
|
+
let pos = state.pos;
|
|
2755
|
+
while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) {
|
|
2756
|
+
pos++;
|
|
2757
|
+
}
|
|
2758
|
+
if (pos === state.pos) {
|
|
2759
|
+
return false;
|
|
2760
|
+
}
|
|
2761
|
+
if (!silent) {
|
|
2762
|
+
state.pending += state.src.slice(state.pos, pos);
|
|
2763
|
+
}
|
|
2764
|
+
state.pos = pos;
|
|
2765
|
+
return true;
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
function isAsciiAlpha(code2) {
|
|
2769
|
+
return code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122;
|
|
2770
|
+
}
|
|
2771
|
+
function isSchemeChar(code2) {
|
|
2772
|
+
return code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || code2 >= 48 && code2 <= 57 || code2 === 43 || code2 === 45 || code2 === 46;
|
|
2773
|
+
}
|
|
2774
|
+
function linkify2(state, silent) {
|
|
2775
|
+
if (!state.md.options.linkify) return false;
|
|
2776
|
+
if (state.linkLevel > 0) return false;
|
|
2777
|
+
const pos = state.pos;
|
|
2778
|
+
const max = state.posMax;
|
|
2779
|
+
if (pos + 3 > max) return false;
|
|
2780
|
+
if (state.src.charCodeAt(pos) !== 58) return false;
|
|
2781
|
+
if (state.src.charCodeAt(pos + 1) !== 47) return false;
|
|
2782
|
+
if (state.src.charCodeAt(pos + 2) !== 47) return false;
|
|
2783
|
+
const protoMin = pos - Math.min(10, state.pending.length, pos);
|
|
2784
|
+
let protoStart = pos;
|
|
2785
|
+
while (protoStart > protoMin && isSchemeChar(state.src.charCodeAt(protoStart - 1))) {
|
|
2786
|
+
protoStart--;
|
|
2787
|
+
}
|
|
2788
|
+
if (protoStart === pos || !isAsciiAlpha(state.src.charCodeAt(protoStart))) return false;
|
|
2789
|
+
const protoLength = pos - protoStart;
|
|
2790
|
+
const link2 = state.md.linkify.matchAtStart(state.src.slice(protoStart));
|
|
2791
|
+
if (!link2) return false;
|
|
2792
|
+
let url = link2.url;
|
|
2793
|
+
if (url.length <= protoLength) return false;
|
|
2794
|
+
let urlEnd = url.length;
|
|
2795
|
+
while (urlEnd > 0 && url.charCodeAt(urlEnd - 1) === 42) {
|
|
2796
|
+
urlEnd--;
|
|
2797
|
+
}
|
|
2798
|
+
if (urlEnd !== url.length) {
|
|
2799
|
+
url = url.slice(0, urlEnd);
|
|
2800
|
+
}
|
|
2801
|
+
const fullUrl = state.md.normalizeLink(url);
|
|
2802
|
+
if (!state.md.validateLink(fullUrl)) return false;
|
|
2803
|
+
if (!silent) {
|
|
2804
|
+
state.pending = state.pending.slice(0, -protoLength);
|
|
2805
|
+
const token_o = state.push("link_open", "a", 1);
|
|
2806
|
+
token_o.attrs = [["href", fullUrl]];
|
|
2807
|
+
token_o.markup = "linkify";
|
|
2808
|
+
token_o.info = "auto";
|
|
2809
|
+
const token_t = state.push("text", "", 0);
|
|
2810
|
+
token_t.content = state.md.normalizeLinkText(url);
|
|
2811
|
+
const token_c = state.push("link_close", "a", -1);
|
|
2812
|
+
token_c.markup = "linkify";
|
|
2813
|
+
token_c.info = "auto";
|
|
2814
|
+
}
|
|
2815
|
+
state.pos += url.length - protoLength;
|
|
2816
|
+
return true;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
function newline(state, silent) {
|
|
2820
|
+
let pos = state.pos;
|
|
2821
|
+
if (state.src.charCodeAt(pos) !== 10) {
|
|
2822
|
+
return false;
|
|
2823
|
+
}
|
|
2824
|
+
const pmax = state.pending.length - 1;
|
|
2825
|
+
const max = state.posMax;
|
|
2826
|
+
if (!silent) {
|
|
2827
|
+
if (pmax >= 0 && state.pending.charCodeAt(pmax) === 32) {
|
|
2828
|
+
if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 32) {
|
|
2829
|
+
let ws = pmax - 1;
|
|
2830
|
+
while (ws >= 1 && state.pending.charCodeAt(ws - 1) === 32) ws--;
|
|
2831
|
+
state.pending = state.pending.slice(0, ws);
|
|
2832
|
+
state.push("hardbreak", "br", 0);
|
|
2833
|
+
} else {
|
|
2834
|
+
state.pending = state.pending.slice(0, -1);
|
|
2835
|
+
state.push("softbreak", "br", 0);
|
|
2836
|
+
}
|
|
2837
|
+
} else {
|
|
2838
|
+
state.push("softbreak", "br", 0);
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
pos++;
|
|
2842
|
+
while (pos < max && isSpace(state.src.charCodeAt(pos))) {
|
|
2843
|
+
pos++;
|
|
2844
|
+
}
|
|
2845
|
+
state.pos = pos;
|
|
2846
|
+
return true;
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
var ESCAPED = [];
|
|
2850
|
+
for (let i = 0; i < 256; i++) {
|
|
2851
|
+
ESCAPED.push(0);
|
|
2852
|
+
}
|
|
2853
|
+
"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(ch) {
|
|
2854
|
+
ESCAPED[ch.charCodeAt(0)] = 1;
|
|
2855
|
+
});
|
|
2856
|
+
function escape(state, silent) {
|
|
2857
|
+
let pos = state.pos;
|
|
2858
|
+
const max = state.posMax;
|
|
2859
|
+
if (state.src.charCodeAt(pos) !== 92) return false;
|
|
2860
|
+
pos++;
|
|
2861
|
+
if (pos >= max) return false;
|
|
2862
|
+
let ch1 = state.src.charCodeAt(pos);
|
|
2863
|
+
if (ch1 === 10) {
|
|
2864
|
+
if (!silent) {
|
|
2865
|
+
state.push("hardbreak", "br", 0);
|
|
2866
|
+
}
|
|
2867
|
+
pos++;
|
|
2868
|
+
while (pos < max) {
|
|
2869
|
+
ch1 = state.src.charCodeAt(pos);
|
|
2870
|
+
if (!isSpace(ch1)) break;
|
|
2871
|
+
pos++;
|
|
2872
|
+
}
|
|
2873
|
+
state.pos = pos;
|
|
2874
|
+
return true;
|
|
2875
|
+
}
|
|
2876
|
+
if (ch1 === 32) {
|
|
2877
|
+
if (!silent) {
|
|
2878
|
+
const token = state.push("text_special", "", 0);
|
|
2879
|
+
token.content = "\\";
|
|
2880
|
+
token.markup = "\\";
|
|
2881
|
+
token.info = "escape";
|
|
2882
|
+
}
|
|
2883
|
+
state.pos = pos;
|
|
2884
|
+
return true;
|
|
2885
|
+
}
|
|
2886
|
+
let escapedStr = state.src[pos];
|
|
2887
|
+
if (ch1 >= 55296 && ch1 <= 56319 && pos + 1 < max) {
|
|
2888
|
+
const ch2 = state.src.charCodeAt(pos + 1);
|
|
2889
|
+
if (ch2 >= 56320 && ch2 <= 57343) {
|
|
2890
|
+
escapedStr += state.src[pos + 1];
|
|
2891
|
+
pos++;
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
const origStr = "\\" + escapedStr;
|
|
2895
|
+
if (!silent) {
|
|
2896
|
+
const token = state.push("text_special", "", 0);
|
|
2897
|
+
if (ch1 < 256 && ESCAPED[ch1] !== 0) {
|
|
2898
|
+
token.content = escapedStr;
|
|
2899
|
+
} else {
|
|
2900
|
+
token.content = origStr;
|
|
2901
|
+
}
|
|
2902
|
+
token.markup = origStr;
|
|
2903
|
+
token.info = "escape";
|
|
2904
|
+
}
|
|
2905
|
+
state.pos = pos + 1;
|
|
2906
|
+
return true;
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
function buildLastRuns(src) {
|
|
2910
|
+
const lastRuns = {};
|
|
2911
|
+
let pos = 0;
|
|
2912
|
+
while ((pos = src.indexOf("`", pos)) !== -1) {
|
|
2913
|
+
const start = pos;
|
|
2914
|
+
while (src.charCodeAt(++pos) === 96) {
|
|
2915
|
+
}
|
|
2916
|
+
lastRuns[pos - start] = start;
|
|
2917
|
+
}
|
|
2918
|
+
return lastRuns;
|
|
2919
|
+
}
|
|
2920
|
+
function backtick(state, silent) {
|
|
2921
|
+
const start = state.pos;
|
|
2922
|
+
if (state.src.charCodeAt(start) !== 96) {
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2925
|
+
const max = state.posMax;
|
|
2926
|
+
let pos = start + 1;
|
|
2927
|
+
while (pos < max && state.src.charCodeAt(pos) === 96) {
|
|
2928
|
+
pos++;
|
|
2929
|
+
}
|
|
2930
|
+
const marker = state.src.slice(start, pos);
|
|
2931
|
+
const openerLength = marker.length;
|
|
2932
|
+
if (!state.backticksScanned) {
|
|
2933
|
+
state.backticks = buildLastRuns(state.src);
|
|
2934
|
+
state.backticksScanned = true;
|
|
2935
|
+
}
|
|
2936
|
+
if ((state.backticks[openerLength] ?? -1) >= pos) {
|
|
2937
|
+
let matchEnd = pos;
|
|
2938
|
+
let matchStart;
|
|
2939
|
+
while ((matchStart = state.src.indexOf("`", matchEnd)) !== -1 && matchStart < max) {
|
|
2940
|
+
matchEnd = matchStart + 1;
|
|
2941
|
+
while (state.src.charCodeAt(matchEnd) === 96) {
|
|
2942
|
+
matchEnd++;
|
|
2943
|
+
}
|
|
2944
|
+
if (matchEnd > max) break;
|
|
2945
|
+
if (matchEnd - matchStart === openerLength) {
|
|
2946
|
+
if (!silent) {
|
|
2947
|
+
const token = state.push("code_inline", "code", 0);
|
|
2948
|
+
token.markup = marker;
|
|
2949
|
+
let content = state.src.slice(pos, matchStart).replace(/\n/g, " ");
|
|
2950
|
+
if (content.startsWith(" ") && content.endsWith(" ") && /[^ ]/.test(content)) {
|
|
2951
|
+
content = content.slice(1, -1);
|
|
2952
|
+
}
|
|
2953
|
+
token.content = content;
|
|
2954
|
+
}
|
|
2955
|
+
state.pos = matchEnd;
|
|
2956
|
+
return true;
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
if (!silent) state.pending += marker;
|
|
2961
|
+
state.pos = pos;
|
|
2962
|
+
return true;
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2965
|
+
function strikethrough_tokenize(state, silent) {
|
|
2966
|
+
const start = state.pos;
|
|
2967
|
+
const marker = state.src.charCodeAt(start);
|
|
2968
|
+
if (silent) {
|
|
2969
|
+
return false;
|
|
2970
|
+
}
|
|
2971
|
+
if (marker !== 126) {
|
|
2972
|
+
return false;
|
|
2973
|
+
}
|
|
2974
|
+
const scanned = state.scanDelims(state.pos, true);
|
|
2975
|
+
let len = scanned.length;
|
|
2976
|
+
const ch = String.fromCharCode(marker);
|
|
2977
|
+
if (len < 2) {
|
|
2978
|
+
return false;
|
|
2979
|
+
}
|
|
2980
|
+
let token;
|
|
2981
|
+
if (len % 2) {
|
|
2982
|
+
token = state.push("text", "", 0);
|
|
2983
|
+
token.content = ch;
|
|
2984
|
+
len--;
|
|
2985
|
+
}
|
|
2986
|
+
for (let i = 0; i < len; i += 2) {
|
|
2987
|
+
token = state.push("text", "", 0);
|
|
2988
|
+
token.content = ch + ch;
|
|
2989
|
+
state.delimiters.push({
|
|
2990
|
+
marker,
|
|
2991
|
+
length: 0,
|
|
2992
|
+
token: state.tokens.length - 1,
|
|
2993
|
+
end: -1,
|
|
2994
|
+
open: scanned.can_open,
|
|
2995
|
+
close: scanned.can_close
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
state.pos += scanned.length;
|
|
2999
|
+
return true;
|
|
3000
|
+
}
|
|
3001
|
+
function postProcess(state, delimiters) {
|
|
3002
|
+
let token;
|
|
3003
|
+
const loneMarkers = [];
|
|
3004
|
+
const max = delimiters.length;
|
|
3005
|
+
for (let i = 0; i < max; i++) {
|
|
3006
|
+
const startDelim = delimiters[i];
|
|
3007
|
+
if (startDelim.marker !== 126) {
|
|
3008
|
+
continue;
|
|
3009
|
+
}
|
|
3010
|
+
if (startDelim.end === -1) {
|
|
3011
|
+
continue;
|
|
3012
|
+
}
|
|
3013
|
+
const endDelim = delimiters[startDelim.end];
|
|
3014
|
+
token = state.tokens[startDelim.token];
|
|
3015
|
+
token.type = "s_open";
|
|
3016
|
+
token.tag = "s";
|
|
3017
|
+
token.nesting = 1;
|
|
3018
|
+
token.markup = "~~";
|
|
3019
|
+
token.content = "";
|
|
3020
|
+
token = state.tokens[endDelim.token];
|
|
3021
|
+
token.type = "s_close";
|
|
3022
|
+
token.tag = "s";
|
|
3023
|
+
token.nesting = -1;
|
|
3024
|
+
token.markup = "~~";
|
|
3025
|
+
token.content = "";
|
|
3026
|
+
if (state.tokens[endDelim.token - 1].type === "text" && state.tokens[endDelim.token - 1].content === "~") {
|
|
3027
|
+
loneMarkers.push(endDelim.token - 1);
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
while (loneMarkers.length) {
|
|
3031
|
+
const i = loneMarkers.pop();
|
|
3032
|
+
let j = i + 1;
|
|
3033
|
+
while (j < state.tokens.length && state.tokens[j].type === "s_close") {
|
|
3034
|
+
j++;
|
|
3035
|
+
}
|
|
3036
|
+
j--;
|
|
3037
|
+
if (i !== j) {
|
|
3038
|
+
token = state.tokens[j];
|
|
3039
|
+
state.tokens[j] = state.tokens[i];
|
|
3040
|
+
state.tokens[i] = token;
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
function strikethrough_postProcess(state) {
|
|
3045
|
+
const tokens_meta = state.tokens_meta;
|
|
3046
|
+
const max = state.tokens_meta.length;
|
|
3047
|
+
postProcess(state, state.delimiters);
|
|
3048
|
+
for (let curr = 0; curr < max; curr++) {
|
|
3049
|
+
const delimiters = tokens_meta[curr]?.delimiters;
|
|
3050
|
+
if (delimiters) {
|
|
3051
|
+
postProcess(state, delimiters);
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
var strikethrough_default = {
|
|
3056
|
+
tokenize: strikethrough_tokenize,
|
|
3057
|
+
postProcess: strikethrough_postProcess
|
|
3058
|
+
};
|
|
3059
|
+
|
|
3060
|
+
function emphasis_tokenize(state, silent) {
|
|
3061
|
+
const start = state.pos;
|
|
3062
|
+
const marker = state.src.charCodeAt(start);
|
|
3063
|
+
if (silent) {
|
|
3064
|
+
return false;
|
|
3065
|
+
}
|
|
3066
|
+
if (marker !== 95 && marker !== 42) {
|
|
3067
|
+
return false;
|
|
3068
|
+
}
|
|
3069
|
+
const scanned = state.scanDelims(state.pos, marker === 42);
|
|
3070
|
+
for (let i = 0; i < scanned.length; i++) {
|
|
3071
|
+
const token = state.push("text", "", 0);
|
|
3072
|
+
token.content = String.fromCharCode(marker);
|
|
3073
|
+
state.delimiters.push({
|
|
3074
|
+
marker,
|
|
3075
|
+
length: scanned.length,
|
|
3076
|
+
token: state.tokens.length - 1,
|
|
3077
|
+
end: -1,
|
|
3078
|
+
open: scanned.can_open,
|
|
3079
|
+
close: scanned.can_close
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
3082
|
+
state.pos += scanned.length;
|
|
3083
|
+
return true;
|
|
3084
|
+
}
|
|
3085
|
+
function postProcess2(state, delimiters) {
|
|
3086
|
+
const max = delimiters.length;
|
|
3087
|
+
for (let i = max - 1; i >= 0; i--) {
|
|
3088
|
+
const startDelim = delimiters[i];
|
|
3089
|
+
if (startDelim.marker !== 95 && startDelim.marker !== 42) {
|
|
3090
|
+
continue;
|
|
3091
|
+
}
|
|
3092
|
+
if (startDelim.end === -1) {
|
|
3093
|
+
continue;
|
|
3094
|
+
}
|
|
3095
|
+
const endDelim = delimiters[startDelim.end];
|
|
3096
|
+
const isStrong = i > 0 && delimiters[i - 1].end === startDelim.end + 1 &&
|
|
3097
|
+
delimiters[i - 1].marker === startDelim.marker && delimiters[i - 1].token === startDelim.token - 1 &&
|
|
3098
|
+
delimiters[startDelim.end + 1].token === endDelim.token + 1;
|
|
3099
|
+
const ch = String.fromCharCode(startDelim.marker);
|
|
3100
|
+
const token_o = state.tokens[startDelim.token];
|
|
3101
|
+
token_o.type = isStrong ? "strong_open" : "em_open";
|
|
3102
|
+
token_o.tag = isStrong ? "strong" : "em";
|
|
3103
|
+
token_o.nesting = 1;
|
|
3104
|
+
token_o.markup = isStrong ? ch + ch : ch;
|
|
3105
|
+
token_o.content = "";
|
|
3106
|
+
const token_c = state.tokens[endDelim.token];
|
|
3107
|
+
token_c.type = isStrong ? "strong_close" : "em_close";
|
|
3108
|
+
token_c.tag = isStrong ? "strong" : "em";
|
|
3109
|
+
token_c.nesting = -1;
|
|
3110
|
+
token_c.markup = isStrong ? ch + ch : ch;
|
|
3111
|
+
token_c.content = "";
|
|
3112
|
+
if (isStrong) {
|
|
3113
|
+
state.tokens[delimiters[i - 1].token].content = "";
|
|
3114
|
+
state.tokens[delimiters[startDelim.end + 1].token].content = "";
|
|
3115
|
+
i--;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
function emphasis_post_process(state) {
|
|
3120
|
+
const tokens_meta = state.tokens_meta;
|
|
3121
|
+
const max = state.tokens_meta.length;
|
|
3122
|
+
postProcess2(state, state.delimiters);
|
|
3123
|
+
for (let curr = 0; curr < max; curr++) {
|
|
3124
|
+
const delimiters = tokens_meta[curr]?.delimiters;
|
|
3125
|
+
if (delimiters) {
|
|
3126
|
+
postProcess2(state, delimiters);
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
var emphasis_default = {
|
|
3131
|
+
tokenize: emphasis_tokenize,
|
|
3132
|
+
postProcess: emphasis_post_process
|
|
3133
|
+
};
|
|
3134
|
+
|
|
3135
|
+
function link(state, silent) {
|
|
3136
|
+
let code2, label, res, ref;
|
|
3137
|
+
let href = "";
|
|
3138
|
+
let title = "";
|
|
3139
|
+
let start = state.pos;
|
|
3140
|
+
let parseReference = true;
|
|
3141
|
+
if (state.src.charCodeAt(state.pos) !== 91) {
|
|
3142
|
+
return false;
|
|
3143
|
+
}
|
|
3144
|
+
const oldPos = state.pos;
|
|
3145
|
+
const max = state.posMax;
|
|
3146
|
+
const labelStart = state.pos + 1;
|
|
3147
|
+
const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true);
|
|
3148
|
+
if (labelEnd < 0) {
|
|
3149
|
+
return false;
|
|
3150
|
+
}
|
|
3151
|
+
let pos = labelEnd + 1;
|
|
3152
|
+
if (pos < max && state.src.charCodeAt(pos) === 40) {
|
|
3153
|
+
parseReference = false;
|
|
3154
|
+
pos++;
|
|
3155
|
+
for (; pos < max; pos++) {
|
|
3156
|
+
code2 = state.src.charCodeAt(pos);
|
|
3157
|
+
if (!isSpace(code2) && code2 !== 10) {
|
|
3158
|
+
break;
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
if (pos >= max) {
|
|
3162
|
+
return false;
|
|
3163
|
+
}
|
|
3164
|
+
start = pos;
|
|
3165
|
+
res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
3166
|
+
if (res.ok) {
|
|
3167
|
+
href = state.md.normalizeLink(res.str);
|
|
3168
|
+
if (state.md.validateLink(href)) {
|
|
3169
|
+
pos = res.pos;
|
|
3170
|
+
} else {
|
|
3171
|
+
href = "";
|
|
3172
|
+
}
|
|
3173
|
+
start = pos;
|
|
3174
|
+
for (; pos < max; pos++) {
|
|
3175
|
+
code2 = state.src.charCodeAt(pos);
|
|
3176
|
+
if (!isSpace(code2) && code2 !== 10) {
|
|
3177
|
+
break;
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax);
|
|
3181
|
+
if (pos < max && start !== pos && res.ok) {
|
|
3182
|
+
title = res.str;
|
|
3183
|
+
pos = res.pos;
|
|
3184
|
+
for (; pos < max; pos++) {
|
|
3185
|
+
code2 = state.src.charCodeAt(pos);
|
|
3186
|
+
if (!isSpace(code2) && code2 !== 10) {
|
|
3187
|
+
break;
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
if (pos >= max || state.src.charCodeAt(pos) !== 41) {
|
|
3193
|
+
parseReference = true;
|
|
3194
|
+
}
|
|
3195
|
+
pos++;
|
|
3196
|
+
}
|
|
3197
|
+
if (parseReference) {
|
|
3198
|
+
if (typeof state.env.references === "undefined") {
|
|
3199
|
+
return false;
|
|
3200
|
+
}
|
|
3201
|
+
if (pos < max && state.src.charCodeAt(pos) === 91) {
|
|
3202
|
+
start = pos + 1;
|
|
3203
|
+
pos = state.md.helpers.parseLinkLabel(state, pos);
|
|
3204
|
+
if (pos >= 0) {
|
|
3205
|
+
label = state.src.slice(start, pos++);
|
|
3206
|
+
} else {
|
|
3207
|
+
pos = labelEnd + 1;
|
|
3208
|
+
}
|
|
3209
|
+
} else {
|
|
3210
|
+
pos = labelEnd + 1;
|
|
3211
|
+
}
|
|
3212
|
+
if (!label) {
|
|
3213
|
+
label = state.src.slice(labelStart, labelEnd);
|
|
3214
|
+
}
|
|
3215
|
+
label = normalizeReference(label);
|
|
3216
|
+
ref = state.env.references[label];
|
|
3217
|
+
if (!ref) {
|
|
3218
|
+
state.pos = oldPos;
|
|
3219
|
+
return false;
|
|
3220
|
+
}
|
|
3221
|
+
href = ref.href;
|
|
3222
|
+
title = ref.title;
|
|
3223
|
+
}
|
|
3224
|
+
if (!silent) {
|
|
3225
|
+
state.pos = labelStart;
|
|
3226
|
+
state.posMax = labelEnd;
|
|
3227
|
+
const token_o = state.push("link_open", "a", 1);
|
|
3228
|
+
const attrs = [["href", href]];
|
|
3229
|
+
token_o.attrs = attrs;
|
|
3230
|
+
if (title) {
|
|
3231
|
+
attrs.push(["title", title]);
|
|
3232
|
+
}
|
|
3233
|
+
if (label) {
|
|
3234
|
+
const meta = /* @__PURE__ */ Object.create(null);
|
|
3235
|
+
meta.label = label;
|
|
3236
|
+
token_o.meta = meta;
|
|
3237
|
+
}
|
|
3238
|
+
state.linkLevel++;
|
|
3239
|
+
state.md.inline.tokenize(state);
|
|
3240
|
+
state.linkLevel--;
|
|
3241
|
+
state.push("link_close", "a", -1);
|
|
3242
|
+
}
|
|
3243
|
+
state.pos = pos;
|
|
3244
|
+
state.posMax = max;
|
|
3245
|
+
return true;
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
function image(state, silent) {
|
|
3249
|
+
let code2, content, label, pos, ref, res, title, start;
|
|
3250
|
+
let href = "";
|
|
3251
|
+
const oldPos = state.pos;
|
|
3252
|
+
const max = state.posMax;
|
|
3253
|
+
if (state.src.charCodeAt(state.pos) !== 33) {
|
|
3254
|
+
return false;
|
|
3255
|
+
}
|
|
3256
|
+
if (state.src.charCodeAt(state.pos + 1) !== 91) {
|
|
3257
|
+
return false;
|
|
3258
|
+
}
|
|
3259
|
+
const labelStart = state.pos + 2;
|
|
3260
|
+
const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false);
|
|
3261
|
+
if (labelEnd < 0) {
|
|
3262
|
+
return false;
|
|
3263
|
+
}
|
|
3264
|
+
pos = labelEnd + 1;
|
|
3265
|
+
if (pos < max && state.src.charCodeAt(pos) === 40) {
|
|
3266
|
+
pos++;
|
|
3267
|
+
for (; pos < max; pos++) {
|
|
3268
|
+
code2 = state.src.charCodeAt(pos);
|
|
3269
|
+
if (!isSpace(code2) && code2 !== 10) {
|
|
3270
|
+
break;
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
if (pos >= max) {
|
|
3274
|
+
return false;
|
|
3275
|
+
}
|
|
3276
|
+
start = pos;
|
|
3277
|
+
res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
3278
|
+
if (res.ok) {
|
|
3279
|
+
href = state.md.normalizeLink(res.str);
|
|
3280
|
+
if (state.md.validateLink(href)) {
|
|
3281
|
+
pos = res.pos;
|
|
3282
|
+
} else {
|
|
3283
|
+
href = "";
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
start = pos;
|
|
3287
|
+
for (; pos < max; pos++) {
|
|
3288
|
+
code2 = state.src.charCodeAt(pos);
|
|
3289
|
+
if (!isSpace(code2) && code2 !== 10) {
|
|
3290
|
+
break;
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax);
|
|
3294
|
+
if (pos < max && start !== pos && res.ok) {
|
|
3295
|
+
title = res.str;
|
|
3296
|
+
pos = res.pos;
|
|
3297
|
+
for (; pos < max; pos++) {
|
|
3298
|
+
code2 = state.src.charCodeAt(pos);
|
|
3299
|
+
if (!isSpace(code2) && code2 !== 10) {
|
|
3300
|
+
break;
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
} else {
|
|
3304
|
+
title = "";
|
|
3305
|
+
}
|
|
3306
|
+
if (pos >= max || state.src.charCodeAt(pos) !== 41) {
|
|
3307
|
+
state.pos = oldPos;
|
|
3308
|
+
return false;
|
|
3309
|
+
}
|
|
3310
|
+
pos++;
|
|
3311
|
+
} else {
|
|
3312
|
+
if (typeof state.env.references === "undefined") {
|
|
3313
|
+
return false;
|
|
3314
|
+
}
|
|
3315
|
+
if (pos < max && state.src.charCodeAt(pos) === 91) {
|
|
3316
|
+
start = pos + 1;
|
|
3317
|
+
pos = state.md.helpers.parseLinkLabel(state, pos);
|
|
3318
|
+
if (pos >= 0) {
|
|
3319
|
+
label = state.src.slice(start, pos++);
|
|
3320
|
+
} else {
|
|
3321
|
+
pos = labelEnd + 1;
|
|
3322
|
+
}
|
|
3323
|
+
} else {
|
|
3324
|
+
pos = labelEnd + 1;
|
|
3325
|
+
}
|
|
3326
|
+
if (!label) {
|
|
3327
|
+
label = state.src.slice(labelStart, labelEnd);
|
|
3328
|
+
}
|
|
3329
|
+
label = normalizeReference(label);
|
|
3330
|
+
ref = state.env.references[label];
|
|
3331
|
+
if (!ref) {
|
|
3332
|
+
state.pos = oldPos;
|
|
3333
|
+
return false;
|
|
3334
|
+
}
|
|
3335
|
+
href = ref.href;
|
|
3336
|
+
title = ref.title;
|
|
3337
|
+
}
|
|
3338
|
+
if (!silent) {
|
|
3339
|
+
content = state.src.slice(labelStart, labelEnd);
|
|
3340
|
+
const tokens = [];
|
|
3341
|
+
state.md.inline.parse(
|
|
3342
|
+
content,
|
|
3343
|
+
state.md,
|
|
3344
|
+
state.env,
|
|
3345
|
+
tokens
|
|
3346
|
+
);
|
|
3347
|
+
const token = state.push("image", "img", 0);
|
|
3348
|
+
const attrs = [["src", href], ["alt", ""]];
|
|
3349
|
+
token.attrs = attrs;
|
|
3350
|
+
token.children = tokens;
|
|
3351
|
+
token.content = content;
|
|
3352
|
+
if (title) {
|
|
3353
|
+
attrs.push(["title", title]);
|
|
3354
|
+
}
|
|
3355
|
+
if (label) {
|
|
3356
|
+
const meta = /* @__PURE__ */ Object.create(null);
|
|
3357
|
+
meta.label = label;
|
|
3358
|
+
token.meta = meta;
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
state.pos = pos;
|
|
3362
|
+
state.posMax = max;
|
|
3363
|
+
return true;
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3366
|
+
var EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/;
|
|
3367
|
+
var AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/;
|
|
3368
|
+
function autolink(state, silent) {
|
|
3369
|
+
let pos = state.pos;
|
|
3370
|
+
if (state.src.charCodeAt(pos) !== 60) {
|
|
3371
|
+
return false;
|
|
3372
|
+
}
|
|
3373
|
+
const start = state.pos;
|
|
3374
|
+
const max = state.posMax;
|
|
3375
|
+
for (; ; ) {
|
|
3376
|
+
if (++pos >= max) return false;
|
|
3377
|
+
const ch = state.src.charCodeAt(pos);
|
|
3378
|
+
if (ch === 60) return false;
|
|
3379
|
+
if (ch === 62) break;
|
|
3380
|
+
}
|
|
3381
|
+
const url = state.src.slice(start + 1, pos);
|
|
3382
|
+
if (AUTOLINK_RE.test(url)) {
|
|
3383
|
+
const fullUrl = state.md.normalizeLink(url);
|
|
3384
|
+
if (!state.md.validateLink(fullUrl)) {
|
|
3385
|
+
return false;
|
|
3386
|
+
}
|
|
3387
|
+
if (!silent) {
|
|
3388
|
+
const token_o = state.push("link_open", "a", 1);
|
|
3389
|
+
token_o.attrs = [["href", fullUrl]];
|
|
3390
|
+
token_o.markup = "autolink";
|
|
3391
|
+
token_o.info = "auto";
|
|
3392
|
+
const token_t = state.push("text", "", 0);
|
|
3393
|
+
token_t.content = state.md.normalizeLinkText(url);
|
|
3394
|
+
const token_c = state.push("link_close", "a", -1);
|
|
3395
|
+
token_c.markup = "autolink";
|
|
3396
|
+
token_c.info = "auto";
|
|
3397
|
+
}
|
|
3398
|
+
state.pos += url.length + 2;
|
|
3399
|
+
return true;
|
|
3400
|
+
}
|
|
3401
|
+
if (EMAIL_RE.test(url)) {
|
|
3402
|
+
const fullUrl = state.md.normalizeLink(`mailto:${url}`);
|
|
3403
|
+
if (!state.md.validateLink(fullUrl)) {
|
|
3404
|
+
return false;
|
|
3405
|
+
}
|
|
3406
|
+
if (!silent) {
|
|
3407
|
+
const token_o = state.push("link_open", "a", 1);
|
|
3408
|
+
token_o.attrs = [["href", fullUrl]];
|
|
3409
|
+
token_o.markup = "autolink";
|
|
3410
|
+
token_o.info = "auto";
|
|
3411
|
+
const token_t = state.push("text", "", 0);
|
|
3412
|
+
token_t.content = state.md.normalizeLinkText(url);
|
|
3413
|
+
const token_c = state.push("link_close", "a", -1);
|
|
3414
|
+
token_c.markup = "autolink";
|
|
3415
|
+
token_c.info = "auto";
|
|
3416
|
+
}
|
|
3417
|
+
state.pos += url.length + 2;
|
|
3418
|
+
return true;
|
|
3419
|
+
}
|
|
3420
|
+
return false;
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
function isLinkOpen2(str) {
|
|
3424
|
+
return /^<a[>\s]/i.test(str);
|
|
3425
|
+
}
|
|
3426
|
+
function isLinkClose2(str) {
|
|
3427
|
+
return /^<\/a\s*>/i.test(str);
|
|
3428
|
+
}
|
|
3429
|
+
function isLetter(ch) {
|
|
3430
|
+
const lc = ch | 32;
|
|
3431
|
+
return lc >= 97 && lc <= 122;
|
|
3432
|
+
}
|
|
3433
|
+
function scanSpecial(state, pos) {
|
|
3434
|
+
const src = state.src;
|
|
3435
|
+
let start;
|
|
3436
|
+
let terminator;
|
|
3437
|
+
if (src.startsWith("<!--", pos)) {
|
|
3438
|
+
if (src.startsWith(">", pos + 4)) {
|
|
3439
|
+
return pos + 5;
|
|
3440
|
+
}
|
|
3441
|
+
if (src.startsWith("->", pos + 4)) {
|
|
3442
|
+
return pos + 6;
|
|
3443
|
+
}
|
|
3444
|
+
start = pos + 4;
|
|
3445
|
+
terminator = "-->";
|
|
3446
|
+
} else if (src.startsWith("<![CDATA[", pos)) {
|
|
3447
|
+
start = pos + 9;
|
|
3448
|
+
terminator = "]]>";
|
|
3449
|
+
} else if (src.charCodeAt(pos + 1) === 63) {
|
|
3450
|
+
start = pos + 2;
|
|
3451
|
+
terminator = "?>";
|
|
3452
|
+
} else if (isLetter(src.charCodeAt(pos + 2))) {
|
|
3453
|
+
start = pos + 3;
|
|
3454
|
+
terminator = ">";
|
|
3455
|
+
} else {
|
|
3456
|
+
return -1;
|
|
3457
|
+
}
|
|
3458
|
+
if (state.skipHtmlSpecial) {
|
|
3459
|
+
return -1;
|
|
3460
|
+
}
|
|
3461
|
+
const end = src.indexOf(terminator, start);
|
|
3462
|
+
if (end < 0) {
|
|
3463
|
+
state.skipHtmlSpecial = true;
|
|
3464
|
+
return -1;
|
|
3465
|
+
}
|
|
3466
|
+
return end + terminator.length;
|
|
3467
|
+
}
|
|
3468
|
+
function html_inline(state, silent) {
|
|
3469
|
+
if (!state.md.options.html) {
|
|
3470
|
+
return false;
|
|
3471
|
+
}
|
|
3472
|
+
const max = state.posMax;
|
|
3473
|
+
const pos = state.pos;
|
|
3474
|
+
if (state.src.charCodeAt(pos) !== 60 || pos + 2 >= max) {
|
|
3475
|
+
return false;
|
|
3476
|
+
}
|
|
3477
|
+
let end;
|
|
3478
|
+
const ch = state.src.charCodeAt(pos + 1);
|
|
3479
|
+
if (ch === 33 || ch === 63) {
|
|
3480
|
+
end = scanSpecial(state, pos);
|
|
3481
|
+
} else if (ch === 47 || isLetter(ch)) {
|
|
3482
|
+
const match = state.src.slice(pos).match(HTML_OPEN_CLOSE_TAG_RE);
|
|
3483
|
+
end = match ? pos + match[0].length : -1;
|
|
3484
|
+
} else {
|
|
3485
|
+
return false;
|
|
3486
|
+
}
|
|
3487
|
+
if (end < 0) {
|
|
3488
|
+
return false;
|
|
3489
|
+
}
|
|
3490
|
+
if (!silent) {
|
|
3491
|
+
const token = state.push("html_inline", "", 0);
|
|
3492
|
+
token.content = state.src.slice(pos, end);
|
|
3493
|
+
if (isLinkOpen2(token.content)) state.linkLevel++;
|
|
3494
|
+
if (isLinkClose2(token.content)) state.linkLevel--;
|
|
3495
|
+
}
|
|
3496
|
+
state.pos = end;
|
|
3497
|
+
return true;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
import { decodeHTMLStrict as decodeHTMLStrict2 } from "./entities.mjs";
|
|
3501
|
+
var DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i;
|
|
3502
|
+
var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i;
|
|
3503
|
+
function entity(state, silent) {
|
|
3504
|
+
const pos = state.pos;
|
|
3505
|
+
const max = state.posMax;
|
|
3506
|
+
if (state.src.charCodeAt(pos) !== 38) return false;
|
|
3507
|
+
if (pos + 1 >= max) return false;
|
|
3508
|
+
const ch = state.src.charCodeAt(pos + 1);
|
|
3509
|
+
if (ch === 35) {
|
|
3510
|
+
const match = state.src.slice(pos).match(DIGITAL_RE);
|
|
3511
|
+
if (match) {
|
|
3512
|
+
if (!silent) {
|
|
3513
|
+
const code2 = match[1][0].toLowerCase() === "x" ? parseInt(match[1].slice(1), 16) : parseInt(match[1], 10);
|
|
3514
|
+
const token = state.push("text_special", "", 0);
|
|
3515
|
+
token.content = isValidEntityCode(code2) ? fromCodePoint(code2) : fromCodePoint(65533);
|
|
3516
|
+
token.markup = match[0];
|
|
3517
|
+
token.info = "entity";
|
|
3518
|
+
}
|
|
3519
|
+
state.pos += match[0].length;
|
|
3520
|
+
return true;
|
|
3521
|
+
}
|
|
3522
|
+
} else {
|
|
3523
|
+
const match = state.src.slice(pos).match(NAMED_RE);
|
|
3524
|
+
if (match) {
|
|
3525
|
+
const decoded = decodeHTMLStrict2(match[0]);
|
|
3526
|
+
if (decoded !== match[0]) {
|
|
3527
|
+
if (!silent) {
|
|
3528
|
+
const token = state.push("text_special", "", 0);
|
|
3529
|
+
token.content = decoded;
|
|
3530
|
+
token.markup = match[0];
|
|
3531
|
+
token.info = "entity";
|
|
3532
|
+
}
|
|
3533
|
+
state.pos += match[0].length;
|
|
3534
|
+
return true;
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
return false;
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
function processDelimiters(delimiters) {
|
|
3542
|
+
const openersBottom = {};
|
|
3543
|
+
const max = delimiters.length;
|
|
3544
|
+
if (!max) return;
|
|
3545
|
+
let headerIdx = 0;
|
|
3546
|
+
let lastTokenIdx = -2;
|
|
3547
|
+
const jumps = [];
|
|
3548
|
+
for (let closerIdx = 0; closerIdx < max; closerIdx++) {
|
|
3549
|
+
const closer = delimiters[closerIdx];
|
|
3550
|
+
jumps.push(0);
|
|
3551
|
+
if (delimiters[headerIdx].marker !== closer.marker || lastTokenIdx !== closer.token - 1) {
|
|
3552
|
+
headerIdx = closerIdx;
|
|
3553
|
+
}
|
|
3554
|
+
lastTokenIdx = closer.token;
|
|
3555
|
+
closer.length = closer.length || 0;
|
|
3556
|
+
if (!closer.close) continue;
|
|
3557
|
+
if (!openersBottom.hasOwnProperty(closer.marker)) {
|
|
3558
|
+
openersBottom[closer.marker] = [-1, -1, -1, -1, -1, -1];
|
|
3559
|
+
}
|
|
3560
|
+
const minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + closer.length % 3];
|
|
3561
|
+
let openerIdx = headerIdx - jumps[headerIdx] - 1;
|
|
3562
|
+
let newMinOpenerIdx = openerIdx;
|
|
3563
|
+
for (; openerIdx > minOpenerIdx; openerIdx -= jumps[openerIdx] + 1) {
|
|
3564
|
+
const opener = delimiters[openerIdx];
|
|
3565
|
+
if (opener.marker !== closer.marker) continue;
|
|
3566
|
+
if (opener.open && opener.end < 0) {
|
|
3567
|
+
let isOddMatch = false;
|
|
3568
|
+
if (opener.close || closer.open) {
|
|
3569
|
+
if ((opener.length + closer.length) % 3 === 0) {
|
|
3570
|
+
if (opener.length % 3 !== 0 || closer.length % 3 !== 0) {
|
|
3571
|
+
isOddMatch = true;
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
if (!isOddMatch) {
|
|
3576
|
+
const lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? jumps[openerIdx - 1] + 1 : 0;
|
|
3577
|
+
jumps[closerIdx] = closerIdx - openerIdx + lastJump;
|
|
3578
|
+
jumps[openerIdx] = lastJump;
|
|
3579
|
+
closer.open = false;
|
|
3580
|
+
opener.end = closerIdx;
|
|
3581
|
+
opener.close = false;
|
|
3582
|
+
newMinOpenerIdx = -1;
|
|
3583
|
+
lastTokenIdx = -2;
|
|
3584
|
+
break;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
if (newMinOpenerIdx !== -1) {
|
|
3589
|
+
openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length || 0) % 3] = newMinOpenerIdx;
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
function link_pairs(state) {
|
|
3594
|
+
const tokens_meta = state.tokens_meta;
|
|
3595
|
+
const max = state.tokens_meta.length;
|
|
3596
|
+
processDelimiters(state.delimiters);
|
|
3597
|
+
for (let curr = 0; curr < max; curr++) {
|
|
3598
|
+
const delimiters = tokens_meta[curr]?.delimiters;
|
|
3599
|
+
if (delimiters) {
|
|
3600
|
+
processDelimiters(delimiters);
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3605
|
+
function fragments_join(state) {
|
|
3606
|
+
let curr, last;
|
|
3607
|
+
let level = 0;
|
|
3608
|
+
const tokens = state.tokens;
|
|
3609
|
+
const max = state.tokens.length;
|
|
3610
|
+
for (curr = last = 0; curr < max; curr++) {
|
|
3611
|
+
if (tokens[curr].nesting < 0) level--;
|
|
3612
|
+
tokens[curr].level = level;
|
|
3613
|
+
if (tokens[curr].nesting > 0) level++;
|
|
3614
|
+
if (tokens[curr].type === "text" && curr + 1 < max && tokens[curr + 1].type === "text") {
|
|
3615
|
+
tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content;
|
|
3616
|
+
} else {
|
|
3617
|
+
if (curr !== last) {
|
|
3618
|
+
tokens[last] = tokens[curr];
|
|
3619
|
+
}
|
|
3620
|
+
last++;
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
if (curr !== last) {
|
|
3624
|
+
tokens.length = last;
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
|
|
3628
|
+
var _rules3 = [
|
|
3629
|
+
["text", text],
|
|
3630
|
+
["linkify", linkify2],
|
|
3631
|
+
["newline", newline],
|
|
3632
|
+
["escape", escape],
|
|
3633
|
+
["backticks", backtick],
|
|
3634
|
+
["strikethrough", strikethrough_default.tokenize],
|
|
3635
|
+
["emphasis", emphasis_default.tokenize],
|
|
3636
|
+
["link", link],
|
|
3637
|
+
["image", image],
|
|
3638
|
+
["autolink", autolink],
|
|
3639
|
+
["html_inline", html_inline],
|
|
3640
|
+
["entity", entity]
|
|
3641
|
+
];
|
|
3642
|
+
var _rules22 = [
|
|
3643
|
+
["balance_pairs", link_pairs],
|
|
3644
|
+
["strikethrough", strikethrough_default.postProcess],
|
|
3645
|
+
["emphasis", emphasis_default.postProcess],
|
|
3646
|
+
["fragments_join", fragments_join]
|
|
3647
|
+
];
|
|
3648
|
+
var ParserInline = class {
|
|
3649
|
+
ruler = new ruler_default();
|
|
3650
|
+
ruler2 = new ruler_default();
|
|
3651
|
+
State = state_inline_default;
|
|
3652
|
+
constructor() {
|
|
3653
|
+
for (let i = 0; i < _rules3.length; i++) {
|
|
3654
|
+
this.ruler.push(_rules3[i][0], _rules3[i][1]);
|
|
3655
|
+
}
|
|
3656
|
+
for (let i = 0; i < _rules22.length; i++) {
|
|
3657
|
+
this.ruler2.push(_rules22[i][0], _rules22[i][1]);
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
skipToken(state) {
|
|
3661
|
+
const pos = state.pos;
|
|
3662
|
+
const rules = this.ruler.getRules("");
|
|
3663
|
+
const len = rules.length;
|
|
3664
|
+
const maxNesting = state.md.options.maxNesting;
|
|
3665
|
+
const cache = state.cache;
|
|
3666
|
+
if (typeof cache[pos] !== "undefined") {
|
|
3667
|
+
state.pos = cache[pos];
|
|
3668
|
+
return;
|
|
3669
|
+
}
|
|
3670
|
+
let ok = false;
|
|
3671
|
+
if (state.level < maxNesting) {
|
|
3672
|
+
for (let i = 0; i < len; i++) {
|
|
3673
|
+
state.level++;
|
|
3674
|
+
ok = rules[i](state, true);
|
|
3675
|
+
state.level--;
|
|
3676
|
+
if (ok) {
|
|
3677
|
+
if (pos >= state.pos) {
|
|
3678
|
+
throw new Error("inline rule didn't increment state.pos");
|
|
3679
|
+
}
|
|
3680
|
+
break;
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
} else {
|
|
3684
|
+
state.pos = state.posMax;
|
|
3685
|
+
}
|
|
3686
|
+
if (!ok) {
|
|
3687
|
+
state.pos++;
|
|
3688
|
+
}
|
|
3689
|
+
cache[pos] = state.pos;
|
|
3690
|
+
}
|
|
3691
|
+
tokenize(state) {
|
|
3692
|
+
const rules = this.ruler.getRules("");
|
|
3693
|
+
const len = rules.length;
|
|
3694
|
+
const end = state.posMax;
|
|
3695
|
+
const maxNesting = state.md.options.maxNesting;
|
|
3696
|
+
while (state.pos < end) {
|
|
3697
|
+
const prevPos = state.pos;
|
|
3698
|
+
let ok = false;
|
|
3699
|
+
if (state.level < maxNesting) {
|
|
3700
|
+
for (let i = 0; i < len; i++) {
|
|
3701
|
+
ok = rules[i](state, false);
|
|
3702
|
+
if (ok) {
|
|
3703
|
+
if (prevPos >= state.pos) {
|
|
3704
|
+
throw new Error("inline rule didn't increment state.pos");
|
|
3705
|
+
}
|
|
3706
|
+
break;
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
if (ok) {
|
|
3711
|
+
if (state.pos >= end) {
|
|
3712
|
+
break;
|
|
3713
|
+
}
|
|
3714
|
+
continue;
|
|
3715
|
+
}
|
|
3716
|
+
state.pending += state.src[state.pos++];
|
|
3717
|
+
}
|
|
3718
|
+
if (state.pending) {
|
|
3719
|
+
state.pushPending();
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
parse(str, md, env, outTokens) {
|
|
3723
|
+
const state = new this.State(str, md, env, outTokens);
|
|
3724
|
+
this.tokenize(state);
|
|
3725
|
+
const rules = this.ruler2.getRules("");
|
|
3726
|
+
const len = rules.length;
|
|
3727
|
+
for (let i = 0; i < len; i++) {
|
|
3728
|
+
rules[i](state);
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
};
|
|
3732
|
+
var parser_inline_default = ParserInline;
|
|
3733
|
+
|
|
3734
|
+
import { LinkifyIt } from "./linkify-it.mjs";
|
|
3735
|
+
import * as mdurl2 from "./mdurl/index.mjs";
|
|
3736
|
+
import punycode from "./punycode.mjs";
|
|
3737
|
+
|
|
3738
|
+
var options = {
|
|
3739
|
+
html: false,
|
|
3740
|
+
xhtmlOut: false,
|
|
3741
|
+
breaks: false,
|
|
3742
|
+
langPrefix: "language-",
|
|
3743
|
+
linkify: false,
|
|
3744
|
+
typographer: false,
|
|
3745
|
+
quotes: "\u201C\u201D\u2018\u2019",
|
|
3746
|
+
highlight: null,
|
|
3747
|
+
maxNesting: 100
|
|
3748
|
+
};
|
|
3749
|
+
var default_default = {
|
|
3750
|
+
options,
|
|
3751
|
+
components: {
|
|
3752
|
+
core: {},
|
|
3753
|
+
block: {},
|
|
3754
|
+
inline: {}
|
|
3755
|
+
}
|
|
3756
|
+
};
|
|
3757
|
+
|
|
3758
|
+
var options2 = {
|
|
3759
|
+
html: false,
|
|
3760
|
+
xhtmlOut: false,
|
|
3761
|
+
breaks: false,
|
|
3762
|
+
langPrefix: "language-",
|
|
3763
|
+
linkify: false,
|
|
3764
|
+
typographer: false,
|
|
3765
|
+
quotes: "\u201C\u201D\u2018\u2019",
|
|
3766
|
+
highlight: null,
|
|
3767
|
+
maxNesting: 20
|
|
3768
|
+
};
|
|
3769
|
+
var zero_default = {
|
|
3770
|
+
options: options2,
|
|
3771
|
+
components: {
|
|
3772
|
+
core: {
|
|
3773
|
+
rules: [
|
|
3774
|
+
"normalize",
|
|
3775
|
+
"block",
|
|
3776
|
+
"strip_references",
|
|
3777
|
+
"inline",
|
|
3778
|
+
"text_join"
|
|
3779
|
+
]
|
|
3780
|
+
},
|
|
3781
|
+
block: {
|
|
3782
|
+
rules: [
|
|
3783
|
+
"paragraph"
|
|
3784
|
+
]
|
|
3785
|
+
},
|
|
3786
|
+
inline: {
|
|
3787
|
+
rules: [
|
|
3788
|
+
"text"
|
|
3789
|
+
],
|
|
3790
|
+
rules2: [
|
|
3791
|
+
"balance_pairs",
|
|
3792
|
+
"fragments_join"
|
|
3793
|
+
]
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
};
|
|
3797
|
+
|
|
3798
|
+
var options3 = {
|
|
3799
|
+
html: true,
|
|
3800
|
+
xhtmlOut: true,
|
|
3801
|
+
breaks: false,
|
|
3802
|
+
langPrefix: "language-",
|
|
3803
|
+
linkify: false,
|
|
3804
|
+
typographer: false,
|
|
3805
|
+
quotes: "\u201C\u201D\u2018\u2019",
|
|
3806
|
+
highlight: null,
|
|
3807
|
+
maxNesting: 20
|
|
3808
|
+
};
|
|
3809
|
+
var commonmark_default = {
|
|
3810
|
+
options: options3,
|
|
3811
|
+
components: {
|
|
3812
|
+
core: {
|
|
3813
|
+
rules: [
|
|
3814
|
+
"normalize",
|
|
3815
|
+
"block",
|
|
3816
|
+
"strip_references",
|
|
3817
|
+
"inline",
|
|
3818
|
+
"text_join"
|
|
3819
|
+
]
|
|
3820
|
+
},
|
|
3821
|
+
block: {
|
|
3822
|
+
rules: [
|
|
3823
|
+
"blockquote",
|
|
3824
|
+
"code",
|
|
3825
|
+
"fence",
|
|
3826
|
+
"heading",
|
|
3827
|
+
"hr",
|
|
3828
|
+
"html_block",
|
|
3829
|
+
"lheading",
|
|
3830
|
+
"list",
|
|
3831
|
+
"reference",
|
|
3832
|
+
"paragraph"
|
|
3833
|
+
]
|
|
3834
|
+
},
|
|
3835
|
+
inline: {
|
|
3836
|
+
rules: [
|
|
3837
|
+
"autolink",
|
|
3838
|
+
"backticks",
|
|
3839
|
+
"emphasis",
|
|
3840
|
+
"entity",
|
|
3841
|
+
"escape",
|
|
3842
|
+
"html_inline",
|
|
3843
|
+
"image",
|
|
3844
|
+
"link",
|
|
3845
|
+
"newline",
|
|
3846
|
+
"text"
|
|
3847
|
+
],
|
|
3848
|
+
rules2: [
|
|
3849
|
+
"balance_pairs",
|
|
3850
|
+
"emphasis",
|
|
3851
|
+
"fragments_join"
|
|
3852
|
+
]
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
};
|
|
3856
|
+
|
|
3857
|
+
var config = {
|
|
3858
|
+
default: default_default,
|
|
3859
|
+
zero: zero_default,
|
|
3860
|
+
commonmark: commonmark_default
|
|
3861
|
+
};
|
|
3862
|
+
var BAD_PROTO_RE = /^(vbscript|javascript|file|data):/;
|
|
3863
|
+
var GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/;
|
|
3864
|
+
var RECODE_HOSTNAME_FOR = ["http:", "https:", "mailto:"];
|
|
3865
|
+
var MarkdownIt = class {
|
|
3866
|
+
inline = new parser_inline_default();
|
|
3867
|
+
block = new parser_block_default();
|
|
3868
|
+
core = new parser_core_default();
|
|
3869
|
+
renderer = new renderer_default();
|
|
3870
|
+
linkify = new LinkifyIt();
|
|
3871
|
+
validateLink(url) {
|
|
3872
|
+
const str = url.trim().toLowerCase();
|
|
3873
|
+
return BAD_PROTO_RE.test(str) ? GOOD_DATA_RE.test(str) : true;
|
|
3874
|
+
}
|
|
3875
|
+
normalizeLink(url) {
|
|
3876
|
+
const parsed = mdurl2.parse(url, true);
|
|
3877
|
+
if (parsed.hostname) {
|
|
3878
|
+
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
|
|
3879
|
+
try {
|
|
3880
|
+
parsed.hostname = punycode.toASCII(parsed.hostname);
|
|
3881
|
+
} catch (er) {
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
if (parsed.auth) parsed.auth = mdurl2.encode(parsed.auth);
|
|
3886
|
+
if (parsed.hostname) parsed.hostname = mdurl2.encode(parsed.hostname);
|
|
3887
|
+
if (parsed.pathname) parsed.pathname = mdurl2.encode(parsed.pathname);
|
|
3888
|
+
if (parsed.search) parsed.search = mdurl2.encode(parsed.search);
|
|
3889
|
+
if (parsed.hash) parsed.hash = mdurl2.encode(parsed.hash);
|
|
3890
|
+
return mdurl2.format(parsed);
|
|
3891
|
+
}
|
|
3892
|
+
normalizeLinkText(url) {
|
|
3893
|
+
const parsed = mdurl2.parse(url, true);
|
|
3894
|
+
if (parsed.hostname) {
|
|
3895
|
+
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
|
|
3896
|
+
try {
|
|
3897
|
+
parsed.hostname = punycode.toUnicode(parsed.hostname);
|
|
3898
|
+
} catch (er) {
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
return mdurl2.decode(mdurl2.format(parsed), mdurl2.decode.defaultChars + "%");
|
|
3903
|
+
}
|
|
3904
|
+
utils = utils_exports;
|
|
3905
|
+
helpers = Object.assign({}, helpers_exports);
|
|
3906
|
+
constructor(...args) {
|
|
3907
|
+
const [presetNameOrOptions, options4] = args;
|
|
3908
|
+
if (typeof presetNameOrOptions === "string") {
|
|
3909
|
+
this.configure(presetNameOrOptions);
|
|
3910
|
+
if (options4) {
|
|
3911
|
+
this.set(options4);
|
|
3912
|
+
}
|
|
3913
|
+
} else {
|
|
3914
|
+
this.configure("default");
|
|
3915
|
+
this.set(presetNameOrOptions || {});
|
|
3916
|
+
}
|
|
3917
|
+
}
|
|
3918
|
+
set(options4) {
|
|
3919
|
+
Object.assign(this.options, options4);
|
|
3920
|
+
return this;
|
|
3921
|
+
}
|
|
3922
|
+
configure(presets) {
|
|
3923
|
+
let p;
|
|
3924
|
+
if (typeof presets === "string") {
|
|
3925
|
+
const presetName = presets;
|
|
3926
|
+
p = config[presetName];
|
|
3927
|
+
if (!p) {
|
|
3928
|
+
throw new Error(`Wrong 'markdown-it' preset "${presetName}", check name`);
|
|
3929
|
+
}
|
|
3930
|
+
} else {
|
|
3931
|
+
p = presets;
|
|
3932
|
+
}
|
|
3933
|
+
if (!p) {
|
|
3934
|
+
throw new Error("Wrong `markdown-it` preset, can't be empty");
|
|
3935
|
+
}
|
|
3936
|
+
if (p.options) {
|
|
3937
|
+
this.options = { ...p.options };
|
|
3938
|
+
}
|
|
3939
|
+
const components = p.components;
|
|
3940
|
+
if (components) {
|
|
3941
|
+
const componentNames = ["core", "block", "inline"];
|
|
3942
|
+
componentNames.forEach((name) => {
|
|
3943
|
+
const rules = components[name]?.rules;
|
|
3944
|
+
if (rules) {
|
|
3945
|
+
this[name].ruler.enableOnly(rules);
|
|
3946
|
+
}
|
|
3947
|
+
});
|
|
3948
|
+
const rules2 = components.inline?.rules2;
|
|
3949
|
+
if (rules2) {
|
|
3950
|
+
this.inline.ruler2.enableOnly(rules2);
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
return this;
|
|
3954
|
+
}
|
|
3955
|
+
enable(list2, ignoreInvalid = false) {
|
|
3956
|
+
let result = [];
|
|
3957
|
+
if (!Array.isArray(list2)) {
|
|
3958
|
+
list2 = [list2];
|
|
3959
|
+
}
|
|
3960
|
+
const chains = ["core", "block", "inline"];
|
|
3961
|
+
chains.forEach((chain) => {
|
|
3962
|
+
result = result.concat(this[chain].ruler.enable(list2, true));
|
|
3963
|
+
});
|
|
3964
|
+
result = result.concat(this.inline.ruler2.enable(list2, true));
|
|
3965
|
+
const missed = list2.filter((name) => result.indexOf(name) < 0);
|
|
3966
|
+
if (missed.length && !ignoreInvalid) {
|
|
3967
|
+
throw new Error(`MarkdownIt. Failed to enable unknown rule(s): ${missed}`);
|
|
3968
|
+
}
|
|
3969
|
+
return this;
|
|
3970
|
+
}
|
|
3971
|
+
disable(list2, ignoreInvalid = false) {
|
|
3972
|
+
let result = [];
|
|
3973
|
+
if (!Array.isArray(list2)) {
|
|
3974
|
+
list2 = [list2];
|
|
3975
|
+
}
|
|
3976
|
+
const chains = ["core", "block", "inline"];
|
|
3977
|
+
chains.forEach((chain) => {
|
|
3978
|
+
result = result.concat(this[chain].ruler.disable(list2, true));
|
|
3979
|
+
});
|
|
3980
|
+
result = result.concat(this.inline.ruler2.disable(list2, true));
|
|
3981
|
+
const missed = list2.filter((name) => result.indexOf(name) < 0);
|
|
3982
|
+
if (missed.length && !ignoreInvalid) {
|
|
3983
|
+
throw new Error(`MarkdownIt. Failed to disable unknown rule(s): ${missed}`);
|
|
3984
|
+
}
|
|
3985
|
+
return this;
|
|
3986
|
+
}
|
|
3987
|
+
use(plugin, ...params) {
|
|
3988
|
+
plugin.apply(plugin, [this, ...params]);
|
|
3989
|
+
return this;
|
|
3990
|
+
}
|
|
3991
|
+
parse(src, env) {
|
|
3992
|
+
if (typeof src !== "string") {
|
|
3993
|
+
throw new Error("Input data should be a String");
|
|
3994
|
+
}
|
|
3995
|
+
const state = new this.core.State(src, this, env);
|
|
3996
|
+
this.core.process(state);
|
|
3997
|
+
return state.tokens;
|
|
3998
|
+
}
|
|
3999
|
+
render(src, env = {}) {
|
|
4000
|
+
return this.renderer.render(this.parse(src, env), this.options, env);
|
|
4001
|
+
}
|
|
4002
|
+
parseInline(src, env) {
|
|
4003
|
+
const state = new this.core.State(src, this, env);
|
|
4004
|
+
state.inlineMode = true;
|
|
4005
|
+
this.core.process(state);
|
|
4006
|
+
return state.tokens;
|
|
4007
|
+
}
|
|
4008
|
+
renderInline(src, env = {}) {
|
|
4009
|
+
return this.renderer.render(this.parseInline(src, env), this.options, env);
|
|
4010
|
+
}
|
|
4011
|
+
static Token = token_default;
|
|
4012
|
+
static Ruler = ruler_default;
|
|
4013
|
+
static Renderer = renderer_default;
|
|
4014
|
+
static ParserCore = parser_core_default;
|
|
4015
|
+
static StateCore = state_core_default;
|
|
4016
|
+
static ParserBlock = parser_block_default;
|
|
4017
|
+
static StateBlock = state_block_default;
|
|
4018
|
+
static ParserInline = parser_inline_default;
|
|
4019
|
+
static StateInline = state_inline_default;
|
|
4020
|
+
};
|
|
4021
|
+
var markdownit_default = MarkdownIt;
|
|
4022
|
+
|
|
4023
|
+
var MarkdownItCallable = callable(markdownit_default);
|
|
4024
|
+
var index_default = MarkdownItCallable;
|
|
4025
|
+
export {
|
|
4026
|
+
index_default as default
|
|
4027
|
+
};
|