@depup/markdown-it 14.3.0-depup.39 → 15.0.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +5 -9
  2. package/bin/markdown-it.mjs +2 -2
  3. package/changes.json +3 -19
  4. package/dist/browser/markdown-it.esm.min.mjs +2972 -0
  5. package/dist/browser/markdown-it.esm.min.mjs.map +1 -0
  6. package/dist/browser/markdown-it.umd.min.js +14 -0
  7. package/dist/browser/markdown-it.umd.min.js.map +1 -0
  8. package/dist/markdown-it.cjs.js +4412 -0
  9. package/dist/markdown-it.cjs.js.map +1 -0
  10. package/dist/markdown-it.d.cts +19 -0
  11. package/dist/markdown-it.d.mts +979 -0
  12. package/dist/{index.cjs.js → markdown-it.mjs} +1437 -1466
  13. package/dist/markdown-it.mjs.map +1 -0
  14. package/package.json +48 -46
  15. package/dist/index.cjs.js.map +0 -1
  16. package/dist/markdown-it.js +0 -3975
  17. package/dist/markdown-it.js.map +0 -1
  18. package/dist/markdown-it.min.js +0 -3
  19. package/dist/markdown-it.min.js.map +0 -1
  20. package/index.mjs +0 -1
  21. package/lib/common/html_blocks.mjs +0 -67
  22. package/lib/common/html_re.mjs +0 -25
  23. package/lib/common/utils.mjs +0 -324
  24. package/lib/helpers/index.mjs +0 -11
  25. package/lib/helpers/parse_link_destination.mjs +0 -77
  26. package/lib/helpers/parse_link_label.mjs +0 -49
  27. package/lib/helpers/parse_link_title.mjs +0 -66
  28. package/lib/index.mjs +0 -565
  29. package/lib/parser_block.mjs +0 -134
  30. package/lib/parser_core.mjs +0 -62
  31. package/lib/parser_inline.mjs +0 -197
  32. package/lib/presets/commonmark.mjs +0 -88
  33. package/lib/presets/default.mjs +0 -47
  34. package/lib/presets/zero.mjs +0 -70
  35. package/lib/renderer.mjs +0 -322
  36. package/lib/ruler.mjs +0 -340
  37. package/lib/rules_block/blockquote.mjs +0 -209
  38. package/lib/rules_block/code.mjs +0 -30
  39. package/lib/rules_block/fence.mjs +0 -94
  40. package/lib/rules_block/heading.mjs +0 -51
  41. package/lib/rules_block/hr.mjs +0 -40
  42. package/lib/rules_block/html_block.mjs +0 -80
  43. package/lib/rules_block/lheading.mjs +0 -85
  44. package/lib/rules_block/list.mjs +0 -331
  45. package/lib/rules_block/paragraph.mjs +0 -48
  46. package/lib/rules_block/reference.mjs +0 -212
  47. package/lib/rules_block/state_block.mjs +0 -220
  48. package/lib/rules_block/table.mjs +0 -228
  49. package/lib/rules_core/block.mjs +0 -13
  50. package/lib/rules_core/inline.mjs +0 -11
  51. package/lib/rules_core/linkify.mjs +0 -134
  52. package/lib/rules_core/normalize.mjs +0 -17
  53. package/lib/rules_core/replacements.mjs +0 -101
  54. package/lib/rules_core/smartquotes.mjs +0 -209
  55. package/lib/rules_core/state_core.mjs +0 -17
  56. package/lib/rules_core/text_join.mjs +0 -43
  57. package/lib/rules_inline/autolink.mjs +0 -72
  58. package/lib/rules_inline/backticks.mjs +0 -60
  59. package/lib/rules_inline/balance_pairs.mjs +0 -124
  60. package/lib/rules_inline/emphasis.mjs +0 -123
  61. package/lib/rules_inline/entity.mjs +0 -51
  62. package/lib/rules_inline/escape.mjs +0 -83
  63. package/lib/rules_inline/fragments_join.mjs +0 -38
  64. package/lib/rules_inline/html_inline.mjs +0 -50
  65. package/lib/rules_inline/image.mjs +0 -138
  66. package/lib/rules_inline/link.mjs +0 -139
  67. package/lib/rules_inline/linkify.mjs +0 -63
  68. package/lib/rules_inline/newline.mjs +0 -42
  69. package/lib/rules_inline/state_inline.mjs +0 -154
  70. package/lib/rules_inline/strikethrough.mjs +0 -127
  71. package/lib/rules_inline/text.mjs +0 -86
  72. package/lib/token.mjs +0 -191
@@ -1,10 +1,11 @@
1
+ /*! markdown-it 15.0.0 https://github.com/markdown-it/markdown-it @license MIT */
2
+ import * as mdurl from "mdurl";
3
+ import * as ucmicro from "uc.micro";
4
+ import { decodeHTMLStrict } from "entities";
5
+ import { LinkifyIt } from "linkify-it";
6
+ import punycode from "punycode.js";
1
7
  //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
9
  var __exportAll = (all, no_symbols) => {
9
10
  let target = {};
10
11
  for (var name in all) __defProp(target, name, {
@@ -14,44 +15,24 @@ var __exportAll = (all, no_symbols) => {
14
15
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
16
  return target;
16
17
  };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
- key = keys[i];
20
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
- get: ((k) => from[k]).bind(null, key),
22
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
- });
24
- }
25
- return to;
26
- };
27
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
18
  //#endregion
32
- let mdurl = require("mdurl");
33
- mdurl = __toESM(mdurl, 1);
34
- let uc_micro = require("uc.micro");
35
- uc_micro = __toESM(uc_micro, 1);
36
- let entities = require("entities");
37
- let linkify_it = require("linkify-it");
38
- linkify_it = __toESM(linkify_it, 1);
39
- let punycode_js = require("punycode.js");
40
- punycode_js = __toESM(punycode_js, 1);
41
- //#region lib/common/utils.mjs
19
+ //#region src/common/utils.ts
20
+ /**
21
+ * Common utility functions exposed through `md.utils` for use by plugins.
22
+ *
23
+ * @module md.utils
24
+ */
42
25
  var utils_exports = /* @__PURE__ */ __exportAll({
43
26
  arrayReplaceAt: () => arrayReplaceAt,
44
27
  asciiTrim: () => asciiTrim,
45
- assign: () => assign,
28
+ callable: () => callable,
46
29
  escapeHtml: () => escapeHtml,
47
30
  escapeRE: () => escapeRE,
48
31
  fromCodePoint: () => fromCodePoint,
49
- has: () => has,
50
32
  isMdAsciiPunct: () => isMdAsciiPunct,
51
33
  isPunctChar: () => isPunctChar,
52
34
  isPunctCharCode: () => isPunctCharCode,
53
35
  isSpace: () => isSpace,
54
- isString: () => isString,
55
36
  isValidEntityCode: () => isValidEntityCode,
56
37
  isWhiteSpace: () => isWhiteSpace,
57
38
  lib: () => lib,
@@ -59,29 +40,24 @@ var utils_exports = /* @__PURE__ */ __exportAll({
59
40
  unescapeAll: () => unescapeAll,
60
41
  unescapeMd: () => unescapeMd
61
42
  });
62
- function _class(obj) {
63
- return Object.prototype.toString.call(obj);
64
- }
65
- function isString(obj) {
66
- return _class(obj) === "[object String]";
67
- }
68
- var _hasOwnProperty = Object.prototype.hasOwnProperty;
69
- function has(object, key) {
70
- return _hasOwnProperty.call(object, key);
71
- }
72
- function assign(obj) {
73
- Array.prototype.slice.call(arguments, 1).forEach(function(source) {
74
- if (!source) return;
75
- if (typeof source !== "object") throw new TypeError(source + "must be object");
76
- Object.keys(source).forEach(function(key) {
77
- obj[key] = source[key];
78
- });
79
- });
80
- return obj;
43
+ function callable(cls) {
44
+ const wrapper = function(...args) {
45
+ return Reflect.construct(cls, args, new.target && new.target !== wrapper ? new.target : cls);
46
+ };
47
+ Object.defineProperty(wrapper, "name", { value: cls.name });
48
+ Object.setPrototypeOf(wrapper, cls);
49
+ wrapper.prototype = cls.prototype;
50
+ return wrapper;
81
51
  }
52
+ /**
53
+ * Returns a copy of a token array with the token at `pos` replaced by
54
+ * `newElements`. Used to transform token streams without modifying the
55
+ * original array.
56
+ */
82
57
  function arrayReplaceAt(src, pos, newElements) {
83
58
  return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1));
84
59
  }
60
+ /** Checks whether a code point can be decoded from a numeric HTML entity. */
85
61
  function isValidEntityCode(c) {
86
62
  if (c >= 55296 && c <= 57343) return false;
87
63
  if (c >= 64976 && c <= 65007) return false;
@@ -93,6 +69,10 @@ function isValidEntityCode(c) {
93
69
  if (c > 1114111) return false;
94
70
  return true;
95
71
  }
72
+ /**
73
+ * Converts a Unicode code point to a string, like `String.fromCodePoint()`,
74
+ * but does not throw for invalid input.
75
+ */
96
76
  function fromCodePoint(c) {
97
77
  if (c > 65535) {
98
78
  c -= 65536;
@@ -103,7 +83,7 @@ function fromCodePoint(c) {
103
83
  return String.fromCharCode(c);
104
84
  }
105
85
  var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
106
- var UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + "|" + /&([a-z#][a-z0-9]{1,31});/gi.source, "gi");
86
+ var UNESCAPE_ALL_RE = new RegExp(`${UNESCAPE_MD_RE.source}|${/&([a-z#][a-z0-9]{1,31});/gi.source}`, "gi");
107
87
  var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i;
108
88
  function replaceEntityPattern(match, name) {
109
89
  if (name.charCodeAt(0) === 35 && DIGITAL_ENTITY_TEST_RE.test(name)) {
@@ -111,14 +91,19 @@ function replaceEntityPattern(match, name) {
111
91
  if (isValidEntityCode(code)) return fromCodePoint(code);
112
92
  return match;
113
93
  }
114
- const decoded = (0, entities.decodeHTML)(match);
94
+ const decoded = decodeHTMLStrict(match);
115
95
  if (decoded !== match) return decoded;
116
96
  return match;
117
97
  }
98
+ /** Decodes Markdown backslash escapes. */
118
99
  function unescapeMd(str) {
119
100
  if (str.indexOf("\\") < 0) return str;
120
101
  return str.replace(UNESCAPE_MD_RE, "$1");
121
102
  }
103
+ /**
104
+ * Decodes Markdown backslash escapes and HTML character references in link
105
+ * destinations, link titles, and fenced code info strings.
106
+ */
122
107
  function unescapeAll(str) {
123
108
  if (str.indexOf("\\") < 0 && str.indexOf("&") < 0) return str;
124
109
  return str.replace(UNESCAPE_ALL_RE, function(match, escaped, entity) {
@@ -137,14 +122,17 @@ var HTML_REPLACEMENTS = {
137
122
  function replaceUnsafeChar(ch) {
138
123
  return HTML_REPLACEMENTS[ch];
139
124
  }
125
+ /** Escapes HTML special characters in a string. */
140
126
  function escapeHtml(str) {
141
127
  if (HTML_ESCAPE_TEST_RE.test(str)) return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
142
128
  return str;
143
129
  }
144
130
  var REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g;
131
+ /** Escapes regular expression metacharacters in a string. */
145
132
  function escapeRE(str) {
146
133
  return str.replace(REGEXP_ESCAPE_RE, "\\$&");
147
134
  }
135
+ /** Checks whether a character code is an ASCII space or tab. */
148
136
  function isSpace(code) {
149
137
  switch (code) {
150
138
  case 9:
@@ -152,6 +140,11 @@ function isSpace(code) {
152
140
  }
153
141
  return false;
154
142
  }
143
+ /**
144
+ * Checks whether a character code is whitespace recognized by Markdown.
145
+ *
146
+ * Matches the Unicode `Zs` category or `\t`, `\f`, `\v`, `\r`, `\n`.
147
+ */
155
148
  function isWhiteSpace(code) {
156
149
  if (code >= 8192 && code <= 8202) return true;
157
150
  switch (code) {
@@ -169,12 +162,29 @@ function isWhiteSpace(code) {
169
162
  }
170
163
  return false;
171
164
  }
165
+ /**
166
+ * Checks whether a character is Unicode punctuation or a symbol.
167
+ *
168
+ * Does not support astral characters.
169
+ */
172
170
  function isPunctChar(ch) {
173
- return uc_micro.P.test(ch) || uc_micro.S.test(ch);
171
+ return ucmicro.P.test(ch) || ucmicro.S.test(ch);
174
172
  }
173
+ /** Checks whether a Unicode code point is punctuation or a symbol. */
175
174
  function isPunctCharCode(code) {
176
175
  return isPunctChar(fromCodePoint(code));
177
176
  }
177
+ /**
178
+ * Markdown ASCII punctuation characters.
179
+ *
180
+ * !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @,
181
+ * [, \, ], ^, _, `, {, |, }, or ~
182
+ *
183
+ * http://spec.commonmark.org/0.15/#ascii-punctuation-character
184
+ *
185
+ * Don't confuse with Unicode punctuation. It lacks some characters in the
186
+ * ASCII range.
187
+ */
178
188
  function isMdAsciiPunct(ch) {
179
189
  switch (ch) {
180
190
  case 33:
@@ -212,16 +222,18 @@ function isMdAsciiPunct(ch) {
212
222
  default: return false;
213
223
  }
214
224
  }
225
+ /** Normalizes `[reference labels]` for case-insensitive lookup. */
215
226
  function normalizeReference(str) {
216
227
  str = str.trim().replace(/\s+/g, " ");
217
- if ("ẞ".toLowerCase() === "Ṿ")
218
- /* c8 ignore next 2 */
219
- str = str.replace(/ẞ/g, "ß");
220
228
  return str.toLowerCase().toUpperCase();
221
229
  }
222
230
  function isAsciiTrimmable(c) {
223
231
  return c === 32 || c === 9 || c === 10 || c === 13;
224
232
  }
233
+ /**
234
+ * "Light" `.trim()` for blocks (headings, paragraphs), where Unicode spaces
235
+ * should be preserved.
236
+ */
225
237
  function asciiTrim(str) {
226
238
  let start = 0;
227
239
  for (; start < str.length; start++) if (!isAsciiTrimmable(str.charCodeAt(start))) break;
@@ -229,12 +241,17 @@ function asciiTrim(str) {
229
241
  for (; end >= start; end--) if (!isAsciiTrimmable(str.charCodeAt(end))) break;
230
242
  return str.slice(start, end + 1);
231
243
  }
244
+ /**
245
+ * Libraries commonly used by markdown-it and its plugins, re-exported to
246
+ * reduce duplicate dependencies in browser bundles.
247
+ */
232
248
  var lib = {
233
249
  mdurl,
234
- ucmicro: uc_micro
250
+ ucmicro
235
251
  };
236
252
  //#endregion
237
- //#region lib/helpers/parse_link_label.mjs
253
+ //#region src/helpers/parse_link_label.ts
254
+ /** Finds the end of a link or image label (`[label]`). */
238
255
  function parseLinkLabel(state, start, disableNested) {
239
256
  let level, found, marker, prevPos;
240
257
  const max = state.posMax;
@@ -266,7 +283,8 @@ function parseLinkLabel(state, start, disableNested) {
266
283
  return labelEnd;
267
284
  }
268
285
  //#endregion
269
- //#region lib/helpers/parse_link_destination.mjs
286
+ //#region src/helpers/parse_link_destination.ts
287
+ /** Parses the destination in `[label](destination "title")`. */
270
288
  function parseLinkDestination(str, start, max) {
271
289
  let code;
272
290
  let pos = start;
@@ -301,7 +319,10 @@ function parseLinkDestination(str, start, max) {
301
319
  if (code === 32) break;
302
320
  if (code < 32 || code === 127) break;
303
321
  if (code === 92 && pos + 1 < max) {
304
- if (str.charCodeAt(pos + 1) === 32) break;
322
+ if (str.charCodeAt(pos + 1) === 32) {
323
+ pos++;
324
+ continue;
325
+ }
305
326
  pos += 2;
306
327
  continue;
307
328
  }
@@ -323,7 +344,13 @@ function parseLinkDestination(str, start, max) {
323
344
  return result;
324
345
  }
325
346
  //#endregion
326
- //#region lib/helpers/parse_link_title.mjs
347
+ //#region src/helpers/parse_link_title.ts
348
+ /**
349
+ * Parses the optional title in `[label](destination "title")` or
350
+ * `[label]: destination "title"`.
351
+ *
352
+ * `prev_state` continues a reference title on the next source line.
353
+ */
327
354
  function parseLinkTitle(str, start, max, prev_state) {
328
355
  let code;
329
356
  let pos = start;
@@ -362,29 +389,435 @@ function parseLinkTitle(str, start, max, prev_state) {
362
389
  return state;
363
390
  }
364
391
  //#endregion
365
- //#region lib/helpers/index.mjs
392
+ //#region src/helpers/index.ts
393
+ /**
394
+ * Functions used to parse links and images, split out of parser rules because
395
+ * of their size.
396
+ *
397
+ * @module md.helpers
398
+ */
366
399
  var helpers_exports = /* @__PURE__ */ __exportAll({
367
400
  parseLinkDestination: () => parseLinkDestination,
368
401
  parseLinkLabel: () => parseLinkLabel,
369
402
  parseLinkTitle: () => parseLinkTitle
370
403
  });
371
404
  //#endregion
372
- //#region lib/renderer.mjs
405
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
406
+ function _typeof(o) {
407
+ "@babel/helpers - typeof";
408
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
409
+ return typeof o;
410
+ } : function(o) {
411
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
412
+ }, _typeof(o);
413
+ }
414
+ //#endregion
415
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
416
+ function toPrimitive(t, r) {
417
+ if ("object" != _typeof(t) || !t) return t;
418
+ var e = t[Symbol.toPrimitive];
419
+ if (void 0 !== e) {
420
+ var i = e.call(t, r || "default");
421
+ if ("object" != _typeof(i)) return i;
422
+ throw new TypeError("@@toPrimitive must return a primitive value.");
423
+ }
424
+ return ("string" === r ? String : Number)(t);
425
+ }
426
+ //#endregion
427
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
428
+ function toPropertyKey(t) {
429
+ var i = toPrimitive(t, "string");
430
+ return "symbol" == _typeof(i) ? i : i + "";
431
+ }
432
+ //#endregion
433
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
434
+ function _defineProperty(e, r, t) {
435
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
436
+ value: t,
437
+ enumerable: !0,
438
+ configurable: !0,
439
+ writable: !0
440
+ }) : e[r] = t, e;
441
+ }
442
+ //#endregion
443
+ //#region src/token.ts
444
+ /**
445
+ * Represents one item in the parsed token stream, storing parsed data and
446
+ * providing helpers for managing HTML attributes.
447
+ */
448
+ var Token = class {
449
+ constructor(type, tag, nesting) {
450
+ _defineProperty(
451
+ this,
452
+ /**
453
+ * Source map info. Format: `[ line_begin, line_end ]`
454
+ */
455
+ "map",
456
+ null
457
+ );
458
+ _defineProperty(
459
+ this,
460
+ /**
461
+ * nesting level, the same as `state.level`
462
+ */
463
+ "level",
464
+ 0
465
+ );
466
+ _defineProperty(
467
+ this,
468
+ /**
469
+ * An array of child nodes (inline and img tokens)
470
+ */
471
+ "children",
472
+ null
473
+ );
474
+ _defineProperty(
475
+ this,
476
+ /**
477
+ * In a case of self-closing tag (code, html, fence, etc.),
478
+ * it has contents of this tag.
479
+ */
480
+ "content",
481
+ ""
482
+ );
483
+ _defineProperty(
484
+ this,
485
+ /**
486
+ * '*' or '_' for emphasis, fence string for fence, etc.
487
+ */
488
+ "markup",
489
+ ""
490
+ );
491
+ _defineProperty(
492
+ this,
493
+ /**
494
+ * Additional information:
495
+ *
496
+ * - Info string for "fence" tokens
497
+ * - The value "auto" for autolink "link_open" and "link_close" tokens
498
+ * - The string value of the item marker for ordered-list "list_item_open" tokens
499
+ */
500
+ "info",
501
+ ""
502
+ );
503
+ _defineProperty(
504
+ this,
505
+ /**
506
+ * True for block-level tokens, false for inline tokens.
507
+ * Used in renderer to calculate line breaks
508
+ */
509
+ "block",
510
+ false
511
+ );
512
+ _defineProperty(
513
+ this,
514
+ /**
515
+ * If it's true, ignore this element when rendering. Used for tight lists
516
+ * to hide paragraphs.
517
+ */
518
+ "hidden",
519
+ false
520
+ );
521
+ this.type = type;
522
+ this.tag = tag;
523
+ this.attrs = null;
524
+ this.nesting = nesting;
525
+ this.meta = null;
526
+ }
527
+ /**
528
+ * Search attribute index by name.
529
+ */
530
+ attrIndex(name) {
531
+ if (!this.attrs) return -1;
532
+ const attrs = this.attrs;
533
+ for (let i = 0, len = attrs.length; i < len; i++) if (attrs[i][0] === name) return i;
534
+ return -1;
535
+ }
536
+ /**
537
+ * Add `[ name, value ]` attribute to list. Init attrs if necessary
538
+ */
539
+ attrPush(attrData) {
540
+ if (this.attrs) this.attrs.push(attrData);
541
+ else this.attrs = [attrData];
542
+ }
543
+ /**
544
+ * Set `name` attribute to `value`. Override old value if exists.
545
+ */
546
+ attrSet(name, value) {
547
+ const idx = this.attrIndex(name);
548
+ const attrData = [name, value];
549
+ if (idx < 0) this.attrPush(attrData);
550
+ else this.attrs[idx] = attrData;
551
+ }
552
+ /**
553
+ * Get the value of attribute `name`, or null if it does not exist.
554
+ */
555
+ attrGet(name) {
556
+ const idx = this.attrIndex(name);
557
+ let value = null;
558
+ if (idx >= 0) value = this.attrs[idx][1];
559
+ return value;
560
+ }
561
+ /**
562
+ * Join value to existing attribute via space. Or create new attribute if not
563
+ * exists. Useful to operate with token classes.
564
+ */
565
+ attrJoin(name, value) {
566
+ const idx = this.attrIndex(name);
567
+ if (idx < 0) this.attrPush([name, value]);
568
+ else this.attrs[idx][1] = `${this.attrs[idx][1]} ${value}`;
569
+ }
570
+ };
571
+ //#endregion
572
+ //#region src/ruler.ts
373
573
  /**
374
- * class Renderer
574
+ * Helper class, used by {@link MarkdownIt.core}, {@link MarkdownIt.block} and
575
+ * {@link MarkdownIt.inline} to manage sequences of functions (rules):
375
576
  *
376
- * Generates HTML from parsed token stream. Each instance has independent
377
- * copy of rules. Those can be rewritten with ease. Also, you can add new
378
- * rules if you create plugin and adds new token types.
379
- **/
577
+ * - keep rules in defined order
578
+ * - assign the name to each rule
579
+ * - enable/disable rules
580
+ * - add/replace rules
581
+ * - allow assign rules to additional named chains (in the same)
582
+ * - cacheing lists of active rules
583
+ *
584
+ * You will not need use this class directly until write plugins. For simple
585
+ * rules control use {@link MarkdownIt.disable}, {@link MarkdownIt.enable} and
586
+ * {@link MarkdownIt.use}.
587
+ */
588
+ var Ruler = class {
589
+ constructor() {
590
+ _defineProperty(this, "__rules__", []);
591
+ _defineProperty(this, "__cache__", null);
592
+ }
593
+ __find__(name) {
594
+ for (let i = 0; i < this.__rules__.length; i++) if (this.__rules__[i].name === name) return i;
595
+ return -1;
596
+ }
597
+ __compile__() {
598
+ const chains = /* @__PURE__ */ new Set();
599
+ this.__rules__.forEach((rule) => {
600
+ if (!rule.enabled) return;
601
+ rule.alt.forEach((altName) => {
602
+ if (altName) chains.add(altName);
603
+ });
604
+ });
605
+ this.__cache__ = Object.create(null);
606
+ this.__cache__[""] = [];
607
+ this.__rules__.forEach((rule) => {
608
+ if (rule.enabled) this.__cache__[""].push(rule.fn);
609
+ });
610
+ chains.forEach((chain) => {
611
+ this.__cache__[chain] = [];
612
+ this.__rules__.forEach((rule) => {
613
+ if (rule.enabled && rule.alt.indexOf(chain) >= 0) this.__cache__[chain].push(rule.fn);
614
+ });
615
+ });
616
+ }
617
+ /**
618
+ * Replace rule by name with new function & options. Throws error if name not
619
+ * found.
620
+ *
621
+ * @param name Rule name to replace.
622
+ * @param fn New rule function.
623
+ * @param options Rule options. `alt` is an array with names of "alternate"
624
+ * chains.
625
+ *
626
+ * @example Replace existing typographer replacement rule with new one
627
+ * ```javascript
628
+ * import MarkdownIt from 'markdown-it'
629
+ * const md = new MarkdownIt()
630
+ *
631
+ * md.core.ruler.at('replacements', function replace(state) {
632
+ * //...
633
+ * });
634
+ * ```
635
+ */
636
+ at(name, fn, options = {}) {
637
+ const index = this.__find__(name);
638
+ if (index === -1) throw new Error(`Parser rule not found: ${name}`);
639
+ this.__rules__[index].fn = fn;
640
+ this.__rules__[index].alt = options.alt || [];
641
+ this.__cache__ = null;
642
+ }
643
+ /**
644
+ * Add new rule to chain before one with given name. See also
645
+ * {@link Ruler.after}, {@link Ruler.push}.
646
+ *
647
+ * @param beforeName New rule will be added before this one.
648
+ * @param ruleName Name of added rule.
649
+ * @param fn Rule function.
650
+ * @param options Rule options. `alt` is an array with names of "alternate"
651
+ * chains.
652
+ *
653
+ * @example
654
+ * ```javascript
655
+ * import MarkdownIt from 'markdown-it'
656
+ * const md = new MarkdownIt()
657
+ *
658
+ * md.block.ruler.before('paragraph', 'my_rule', function replace(state) {
659
+ * //...
660
+ * });
661
+ * ```
662
+ */
663
+ before(beforeName, ruleName, fn, options = {}) {
664
+ const index = this.__find__(beforeName);
665
+ if (index === -1) throw new Error(`Parser rule not found: ${beforeName}`);
666
+ this.__rules__.splice(index, 0, {
667
+ name: ruleName,
668
+ enabled: true,
669
+ fn,
670
+ alt: options.alt || []
671
+ });
672
+ this.__cache__ = null;
673
+ }
674
+ /**
675
+ * Add new rule to chain after one with given name. See also
676
+ * {@link Ruler.before}, {@link Ruler.push}.
677
+ *
678
+ * @param afterName New rule will be added after this one.
679
+ * @param ruleName Name of added rule.
680
+ * @param fn Rule function.
681
+ * @param options Rule options. `alt` is an array with names of "alternate"
682
+ * chains.
683
+ *
684
+ * @example
685
+ * ```javascript
686
+ * import MarkdownIt from 'markdown-it'
687
+ * const md = new MarkdownIt()
688
+ *
689
+ * md.inline.ruler.after('text', 'my_rule', function replace(state) {
690
+ * //...
691
+ * });
692
+ * ```
693
+ */
694
+ after(afterName, ruleName, fn, options = {}) {
695
+ const index = this.__find__(afterName);
696
+ if (index === -1) throw new Error(`Parser rule not found: ${afterName}`);
697
+ this.__rules__.splice(index + 1, 0, {
698
+ name: ruleName,
699
+ enabled: true,
700
+ fn,
701
+ alt: options.alt || []
702
+ });
703
+ this.__cache__ = null;
704
+ }
705
+ /**
706
+ * Push new rule to the end of chain. See also
707
+ * {@link Ruler.before}, {@link Ruler.after}.
708
+ *
709
+ * @param ruleName Name of added rule.
710
+ * @param fn Rule function.
711
+ * @param options Rule options. `alt` is an array with names of "alternate"
712
+ * chains.
713
+ *
714
+ * @example
715
+ * ```javascript
716
+ * import MarkdownIt from 'markdown-it'
717
+ * const md = new MarkdownIt()
718
+ *
719
+ * md.core.ruler.push('my_rule', function replace(state) {
720
+ * //...
721
+ * });
722
+ * ```
723
+ */
724
+ push(ruleName, fn, options = {}) {
725
+ this.__rules__.push({
726
+ name: ruleName,
727
+ enabled: true,
728
+ fn,
729
+ alt: options.alt || []
730
+ });
731
+ this.__cache__ = null;
732
+ }
733
+ /**
734
+ * Enable rules with given names. If any rule name not found - throw Error.
735
+ * Errors can be disabled by second param.
736
+ *
737
+ * See also {@link Ruler.disable}, {@link Ruler.enableOnly}.
738
+ *
739
+ * @param list List of rule names to enable.
740
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
741
+ * @returns List of found rule names (if no exception happened).
742
+ */
743
+ enable(list, ignoreInvalid = false) {
744
+ if (!Array.isArray(list)) list = [list];
745
+ const result = [];
746
+ list.forEach((name) => {
747
+ const idx = this.__find__(name);
748
+ if (idx < 0) {
749
+ if (ignoreInvalid) return;
750
+ throw new Error(`Rules manager: invalid rule name ${name}`);
751
+ }
752
+ this.__rules__[idx].enabled = true;
753
+ result.push(name);
754
+ });
755
+ this.__cache__ = null;
756
+ return result;
757
+ }
758
+ /**
759
+ * Enable rules with given names, and disable everything else. If any rule name
760
+ * not found - throw Error. Errors can be disabled by second param.
761
+ *
762
+ * See also {@link Ruler.disable}, {@link Ruler.enable}.
763
+ *
764
+ * @param list List of rule names to enable (whitelist).
765
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
766
+ */
767
+ enableOnly(list, ignoreInvalid = false) {
768
+ if (!Array.isArray(list)) list = [list];
769
+ this.__rules__.forEach((rule) => {
770
+ rule.enabled = false;
771
+ });
772
+ this.enable(list, ignoreInvalid);
773
+ }
774
+ /**
775
+ * Disable rules with given names. If any rule name not found - throw Error.
776
+ * Errors can be disabled by second param.
777
+ *
778
+ * See also {@link Ruler.enable}, {@link Ruler.enableOnly}.
779
+ *
780
+ * @param list List of rule names to disable.
781
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
782
+ * @returns List of found rule names (if no exception happened).
783
+ */
784
+ disable(list, ignoreInvalid = false) {
785
+ if (!Array.isArray(list)) list = [list];
786
+ const result = [];
787
+ list.forEach((name) => {
788
+ const idx = this.__find__(name);
789
+ if (idx < 0) {
790
+ if (ignoreInvalid) return;
791
+ throw new Error(`Rules manager: invalid rule name ${name}`);
792
+ }
793
+ this.__rules__[idx].enabled = false;
794
+ result.push(name);
795
+ });
796
+ this.__cache__ = null;
797
+ return result;
798
+ }
799
+ /**
800
+ * Return array of active functions (rules) for given chain name. It analyzes
801
+ * rules configuration, compiles caches if not exists and returns result.
802
+ *
803
+ * Default chain name is `''` (empty string). It can't be skipped. That's
804
+ * done intentionally, to keep signature monomorphic for high speed.
805
+ */
806
+ getRules(chainName) {
807
+ if (!this.__cache__) this.__compile__();
808
+ return this.__cache__[chainName] || [];
809
+ }
810
+ };
811
+ //#endregion
812
+ //#region src/renderer.ts
380
813
  var default_rules = {};
381
814
  default_rules.code_inline = function(tokens, idx, options, env, slf) {
382
815
  const token = tokens[idx];
383
- return "<code" + slf.renderAttrs(token) + ">" + escapeHtml(token.content) + "</code>";
816
+ return `<code${slf.renderAttrs(token)}>${escapeHtml(token.content)}</code>`;
384
817
  };
385
818
  default_rules.code_block = function(tokens, idx, options, env, slf) {
386
819
  const token = tokens[idx];
387
- return "<pre" + slf.renderAttrs(token) + "><code>" + escapeHtml(tokens[idx].content) + "</code></pre>\n";
820
+ return `<pre${slf.renderAttrs(token)}><code>${escapeHtml(tokens[idx].content)}</code></pre>\n`;
388
821
  };
389
822
  default_rules.fence = function(tokens, idx, options, env, slf) {
390
823
  const token = tokens[idx];
@@ -403,10 +836,10 @@ default_rules.fence = function(tokens, idx, options, env, slf) {
403
836
  if (info) {
404
837
  const i = token.attrIndex("class");
405
838
  const tmpAttrs = token.attrs ? token.attrs.slice() : [];
406
- if (i < 0) tmpAttrs.push(["class", options.langPrefix + langName]);
839
+ if (i < 0) tmpAttrs.push(["class", `${options.langPrefix}${langName}`]);
407
840
  else {
408
- tmpAttrs[i] = tmpAttrs[i].slice();
409
- tmpAttrs[i][1] += " " + options.langPrefix + langName;
841
+ tmpAttrs[i] = [tmpAttrs[i][0], tmpAttrs[i][1]];
842
+ tmpAttrs[i][1] += ` ${options.langPrefix}${langName}`;
410
843
  }
411
844
  const tmpToken = { attrs: tmpAttrs };
412
845
  return `<pre><code${slf.renderAttrs(tmpToken)}>${highlighted}</code></pre>\n`;
@@ -434,590 +867,169 @@ default_rules.html_inline = function(tokens, idx) {
434
867
  return tokens[idx].content;
435
868
  };
436
869
  /**
437
- * new Renderer()
438
- *
439
- * Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults.
440
- **/
441
- function Renderer() {
442
- /**
443
- * Renderer#rules -> Object
444
- *
445
- * Contains render rules for tokens. Can be updated and extended.
446
- *
447
- * ##### Example
448
- *
449
- * ```javascript
450
- * var md = require('markdown-it')();
451
- *
452
- * md.renderer.rules.strong_open = function () { return '<b>'; };
453
- * md.renderer.rules.strong_close = function () { return '</b>'; };
454
- *
455
- * var result = md.renderInline(...);
456
- * ```
457
- *
458
- * Each rule is called as independent static function with fixed signature:
459
- *
460
- * ```javascript
461
- * function my_token_render(tokens, idx, options, env, renderer) {
462
- * // ...
463
- * return renderedHTML;
464
- * }
465
- * ```
466
- *
467
- * See [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs)
468
- * for more details and examples.
469
- **/
470
- this.rules = assign({}, default_rules);
471
- }
472
- /**
473
- * Renderer.renderAttrs(token) -> String
474
- *
475
- * Render token attributes to string.
476
- **/
477
- Renderer.prototype.renderAttrs = function renderAttrs(token) {
478
- let i, l, result;
479
- if (!token.attrs) return "";
480
- result = "";
481
- for (i = 0, l = token.attrs.length; i < l; i++) result += " " + escapeHtml(token.attrs[i][0]) + "=\"" + escapeHtml(token.attrs[i][1]) + "\"";
482
- return result;
483
- };
484
- /**
485
- * Renderer.renderToken(tokens, idx, options) -> String
486
- * - tokens (Array): list of tokens
487
- * - idx (Numbed): token index to render
488
- * - options (Object): params of parser instance
489
- *
490
- * Default token renderer. Can be overriden by custom function
491
- * in [[Renderer#rules]].
492
- **/
493
- Renderer.prototype.renderToken = function renderToken(tokens, idx, options) {
494
- const token = tokens[idx];
495
- let result = "";
496
- if (token.hidden) return "";
497
- if (token.block && token.nesting !== -1 && idx && tokens[idx - 1].hidden) result += "\n";
498
- result += (token.nesting === -1 ? "</" : "<") + token.tag;
499
- result += this.renderAttrs(token);
500
- if (token.nesting === 0 && options.xhtmlOut) result += " /";
501
- let needLf = false;
502
- if (token.block) {
503
- needLf = true;
504
- if (token.nesting === 1) {
505
- if (idx + 1 < tokens.length) {
506
- const nextToken = tokens[idx + 1];
507
- if (nextToken.type === "inline" || nextToken.hidden) needLf = false;
508
- else if (nextToken.nesting === -1 && nextToken.tag === token.tag) needLf = false;
509
- }
510
- }
511
- }
512
- result += needLf ? ">\n" : ">";
513
- return result;
514
- };
515
- /**
516
- * Renderer.renderInline(tokens, options, env) -> String
517
- * - tokens (Array): list on block tokens to render
518
- * - options (Object): params of parser instance
519
- * - env (Object): additional data from parsed input (references, for example)
520
- *
521
- * The same as [[Renderer.render]], but for single token of `inline` type.
522
- **/
523
- Renderer.prototype.renderInline = function(tokens, options, env) {
524
- let result = "";
525
- const rules = this.rules;
526
- for (let i = 0, len = tokens.length; i < len; i++) {
527
- const type = tokens[i].type;
528
- if (typeof rules[type] !== "undefined") result += rules[type](tokens, i, options, env, this);
529
- else result += this.renderToken(tokens, i, options);
530
- }
531
- return result;
532
- };
533
- /** internal
534
- * Renderer.renderInlineAsText(tokens, options, env) -> String
535
- * - tokens (Array): list on block tokens to render
536
- * - options (Object): params of parser instance
537
- * - env (Object): additional data from parsed input (references, for example)
538
- *
539
- * Special kludge for image `alt` attributes to conform CommonMark spec.
540
- * Don't try to use it! Spec requires to show `alt` content with stripped markup,
541
- * instead of simple escaping.
542
- **/
543
- Renderer.prototype.renderInlineAsText = function(tokens, options, env) {
544
- let result = "";
545
- for (let i = 0, len = tokens.length; i < len; i++) switch (tokens[i].type) {
546
- case "text":
547
- result += tokens[i].content;
548
- break;
549
- case "image":
550
- result += this.renderInlineAsText(tokens[i].children, options, env);
551
- break;
552
- case "html_inline":
553
- case "html_block":
554
- result += tokens[i].content;
555
- break;
556
- case "softbreak":
557
- case "hardbreak":
558
- result += "\n";
559
- break;
560
- default:
561
- }
562
- return result;
563
- };
564
- /**
565
- * Renderer.render(tokens, options, env) -> String
566
- * - tokens (Array): list on block tokens to render
567
- * - options (Object): params of parser instance
568
- * - env (Object): additional data from parsed input (references, for example)
569
- *
570
- * Takes token stream and generates HTML. Probably, you will never need to call
571
- * this method directly.
572
- **/
573
- Renderer.prototype.render = function(tokens, options, env) {
574
- let result = "";
575
- const rules = this.rules;
576
- for (let i = 0, len = tokens.length; i < len; i++) {
577
- const type = tokens[i].type;
578
- if (type === "inline") result += this.renderInline(tokens[i].children, options, env);
579
- else if (typeof rules[type] !== "undefined") result += rules[type](tokens, i, options, env, this);
580
- else result += this.renderToken(tokens, i, options, env);
581
- }
582
- return result;
583
- };
584
- //#endregion
585
- //#region lib/ruler.mjs
586
- /**
587
- * class Ruler
588
- *
589
- * Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and
590
- * [[MarkdownIt#inline]] to manage sequences of functions (rules):
591
- *
592
- * - keep rules in defined order
593
- * - assign the name to each rule
594
- * - enable/disable rules
595
- * - add/replace rules
596
- * - allow assign rules to additional named chains (in the same)
597
- * - cacheing lists of active rules
598
- *
599
- * You will not need use this class directly until write plugins. For simple
600
- * rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and
601
- * [[MarkdownIt.use]].
602
- **/
603
- /**
604
- * new Ruler()
605
- **/
606
- function Ruler() {
607
- this.__rules__ = [];
608
- this.__cache__ = null;
609
- }
610
- Ruler.prototype.__find__ = function(name) {
611
- for (let i = 0; i < this.__rules__.length; i++) if (this.__rules__[i].name === name) return i;
612
- return -1;
613
- };
614
- Ruler.prototype.__compile__ = function() {
615
- const self = this;
616
- const chains = [""];
617
- self.__rules__.forEach(function(rule) {
618
- if (!rule.enabled) return;
619
- rule.alt.forEach(function(altName) {
620
- if (chains.indexOf(altName) < 0) chains.push(altName);
621
- });
622
- });
623
- self.__cache__ = {};
624
- chains.forEach(function(chain) {
625
- self.__cache__[chain] = [];
626
- self.__rules__.forEach(function(rule) {
627
- if (!rule.enabled) return;
628
- if (chain && rule.alt.indexOf(chain) < 0) return;
629
- self.__cache__[chain].push(rule.fn);
630
- });
631
- });
632
- };
633
- /**
634
- * Ruler.at(name, fn [, options])
635
- * - name (String): rule name to replace.
636
- * - fn (Function): new rule function.
637
- * - options (Object): new rule options (not mandatory).
638
- *
639
- * Replace rule by name with new function & options. Throws error if name not
640
- * found.
641
- *
642
- * ##### Options:
643
- *
644
- * - __alt__ - array with names of "alternate" chains.
645
- *
646
- * ##### Example
647
- *
648
- * Replace existing typographer replacement rule with new one:
649
- *
650
- * ```javascript
651
- * var md = require('markdown-it')();
652
- *
653
- * md.core.ruler.at('replacements', function replace(state) {
654
- * //...
655
- * });
656
- * ```
657
- **/
658
- Ruler.prototype.at = function(name, fn, options) {
659
- const index = this.__find__(name);
660
- const opt = options || {};
661
- if (index === -1) throw new Error("Parser rule not found: " + name);
662
- this.__rules__[index].fn = fn;
663
- this.__rules__[index].alt = opt.alt || [];
664
- this.__cache__ = null;
665
- };
666
- /**
667
- * Ruler.before(beforeName, ruleName, fn [, options])
668
- * - beforeName (String): new rule will be added before this one.
669
- * - ruleName (String): name of added rule.
670
- * - fn (Function): rule function.
671
- * - options (Object): rule options (not mandatory).
672
- *
673
- * Add new rule to chain before one with given name. See also
674
- * [[Ruler.after]], [[Ruler.push]].
675
- *
676
- * ##### Options:
677
- *
678
- * - __alt__ - array with names of "alternate" chains.
679
- *
680
- * ##### Example
681
- *
682
- * ```javascript
683
- * var md = require('markdown-it')();
684
- *
685
- * md.block.ruler.before('paragraph', 'my_rule', function replace(state) {
686
- * //...
687
- * });
688
- * ```
689
- **/
690
- Ruler.prototype.before = function(beforeName, ruleName, fn, options) {
691
- const index = this.__find__(beforeName);
692
- const opt = options || {};
693
- if (index === -1) throw new Error("Parser rule not found: " + beforeName);
694
- this.__rules__.splice(index, 0, {
695
- name: ruleName,
696
- enabled: true,
697
- fn,
698
- alt: opt.alt || []
699
- });
700
- this.__cache__ = null;
701
- };
702
- /**
703
- * Ruler.after(afterName, ruleName, fn [, options])
704
- * - afterName (String): new rule will be added after this one.
705
- * - ruleName (String): name of added rule.
706
- * - fn (Function): rule function.
707
- * - options (Object): rule options (not mandatory).
708
- *
709
- * Add new rule to chain after one with given name. See also
710
- * [[Ruler.before]], [[Ruler.push]].
711
- *
712
- * ##### Options:
713
- *
714
- * - __alt__ - array with names of "alternate" chains.
715
- *
716
- * ##### Example
717
- *
718
- * ```javascript
719
- * var md = require('markdown-it')();
720
- *
721
- * md.inline.ruler.after('text', 'my_rule', function replace(state) {
722
- * //...
723
- * });
724
- * ```
725
- **/
726
- Ruler.prototype.after = function(afterName, ruleName, fn, options) {
727
- const index = this.__find__(afterName);
728
- const opt = options || {};
729
- if (index === -1) throw new Error("Parser rule not found: " + afterName);
730
- this.__rules__.splice(index + 1, 0, {
731
- name: ruleName,
732
- enabled: true,
733
- fn,
734
- alt: opt.alt || []
735
- });
736
- this.__cache__ = null;
737
- };
738
- /**
739
- * Ruler.push(ruleName, fn [, options])
740
- * - ruleName (String): name of added rule.
741
- * - fn (Function): rule function.
742
- * - options (Object): rule options (not mandatory).
743
- *
744
- * Push new rule to the end of chain. See also
745
- * [[Ruler.before]], [[Ruler.after]].
746
- *
747
- * ##### Options:
748
- *
749
- * - __alt__ - array with names of "alternate" chains.
750
- *
751
- * ##### Example
752
- *
753
- * ```javascript
754
- * var md = require('markdown-it')();
755
- *
756
- * md.core.ruler.push('my_rule', function replace(state) {
757
- * //...
758
- * });
759
- * ```
760
- **/
761
- Ruler.prototype.push = function(ruleName, fn, options) {
762
- const opt = options || {};
763
- this.__rules__.push({
764
- name: ruleName,
765
- enabled: true,
766
- fn,
767
- alt: opt.alt || []
768
- });
769
- this.__cache__ = null;
770
- };
771
- /**
772
- * Ruler.enable(list [, ignoreInvalid]) -> Array
773
- * - list (String|Array): list of rule names to enable.
774
- * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
775
- *
776
- * Enable rules with given names. If any rule name not found - throw Error.
777
- * Errors can be disabled by second param.
778
- *
779
- * Returns list of found rule names (if no exception happened).
780
- *
781
- * See also [[Ruler.disable]], [[Ruler.enableOnly]].
782
- **/
783
- Ruler.prototype.enable = function(list, ignoreInvalid) {
784
- if (!Array.isArray(list)) list = [list];
785
- const result = [];
786
- list.forEach(function(name) {
787
- const idx = this.__find__(name);
788
- if (idx < 0) {
789
- if (ignoreInvalid) return;
790
- throw new Error("Rules manager: invalid rule name " + name);
791
- }
792
- this.__rules__[idx].enabled = true;
793
- result.push(name);
794
- }, this);
795
- this.__cache__ = null;
796
- return result;
797
- };
798
- /**
799
- * Ruler.enableOnly(list [, ignoreInvalid])
800
- * - list (String|Array): list of rule names to enable (whitelist).
801
- * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
802
- *
803
- * Enable rules with given names, and disable everything else. If any rule name
804
- * not found - throw Error. Errors can be disabled by second param.
805
- *
806
- * See also [[Ruler.disable]], [[Ruler.enable]].
807
- **/
808
- Ruler.prototype.enableOnly = function(list, ignoreInvalid) {
809
- if (!Array.isArray(list)) list = [list];
810
- this.__rules__.forEach(function(rule) {
811
- rule.enabled = false;
812
- });
813
- this.enable(list, ignoreInvalid);
814
- };
815
- /**
816
- * Ruler.disable(list [, ignoreInvalid]) -> Array
817
- * - list (String|Array): list of rule names to disable.
818
- * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
819
- *
820
- * Disable rules with given names. If any rule name not found - throw Error.
821
- * Errors can be disabled by second param.
822
- *
823
- * Returns list of found rule names (if no exception happened).
824
- *
825
- * See also [[Ruler.enable]], [[Ruler.enableOnly]].
826
- **/
827
- Ruler.prototype.disable = function(list, ignoreInvalid) {
828
- if (!Array.isArray(list)) list = [list];
829
- const result = [];
830
- list.forEach(function(name) {
831
- const idx = this.__find__(name);
832
- if (idx < 0) {
833
- if (ignoreInvalid) return;
834
- throw new Error("Rules manager: invalid rule name " + name);
835
- }
836
- this.__rules__[idx].enabled = false;
837
- result.push(name);
838
- }, this);
839
- this.__cache__ = null;
840
- return result;
841
- };
842
- /**
843
- * Ruler.getRules(chainName) -> Array
844
- *
845
- * Return array of active functions (rules) for given chain name. It analyzes
846
- * rules configuration, compiles caches if not exists and returns result.
847
- *
848
- * Default chain name is `''` (empty string). It can't be skipped. That's
849
- * done intentionally, to keep signature monomorphic for high speed.
850
- **/
851
- Ruler.prototype.getRules = function(chainName) {
852
- if (this.__cache__ === null) this.__compile__();
853
- return this.__cache__[chainName] || [];
854
- };
855
- //#endregion
856
- //#region lib/token.mjs
857
- /**
858
- * class Token
859
- **/
860
- /**
861
- * new Token(type, tag, nesting)
870
+ * Generates HTML from parsed token stream. Each instance has independent
871
+ * copy of rules. Those can be rewritten with ease. Also, you can add new
872
+ * rules if you create plugin and adds new token types.
862
873
  *
863
- * Create new token and fill passed properties.
864
- **/
865
- function Token(type, tag, nesting) {
866
- /**
867
- * Token#type -> String
868
- *
869
- * Type of the token (string, e.g. "paragraph_open")
870
- **/
871
- this.type = type;
872
- /**
873
- * Token#tag -> String
874
- *
875
- * html tag name, e.g. "p"
876
- **/
877
- this.tag = tag;
878
- /**
879
- * Token#attrs -> Array
880
- *
881
- * Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]`
882
- **/
883
- this.attrs = null;
884
- /**
885
- * Token#map -> Array
886
- *
887
- * Source map info. Format: `[ line_begin, line_end ]`
888
- **/
889
- this.map = null;
890
- /**
891
- * Token#nesting -> Number
892
- *
893
- * Level change (number in {-1, 0, 1} set), where:
894
- *
895
- * - `1` means the tag is opening
896
- * - `0` means the tag is self-closing
897
- * - `-1` means the tag is closing
898
- **/
899
- this.nesting = nesting;
900
- /**
901
- * Token#level -> Number
902
- *
903
- * nesting level, the same as `state.level`
904
- **/
905
- this.level = 0;
906
- /**
907
- * Token#children -> Array
908
- *
909
- * An array of child nodes (inline and img tokens)
910
- **/
911
- this.children = null;
912
- /**
913
- * Token#content -> String
914
- *
915
- * In a case of self-closing tag (code, html, fence, etc.),
916
- * it has contents of this tag.
917
- **/
918
- this.content = "";
874
+ * Creates new renderer instance and fills {@link Renderer.rules} with defaults.
875
+ */
876
+ var Renderer = class {
877
+ constructor() {
878
+ _defineProperty(
879
+ this,
880
+ /**
881
+ * Contains render rules for tokens. Can be updated and extended.
882
+ *
883
+ * See [source code](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts)
884
+ * for more details and examples.
885
+ *
886
+ * @example Custom render rules
887
+ * ```javascript
888
+ * import MarkdownIt from 'markdown-it'
889
+ * const md = new MarkdownIt()
890
+ *
891
+ * md.renderer.rules.strong_open = function () { return '<b>'; };
892
+ * md.renderer.rules.strong_close = function () { return '</b>'; };
893
+ *
894
+ * const result = md.renderInline(...);
895
+ * ```
896
+ *
897
+ * @example Each rule is called as independent static function with fixed signature
898
+ * ```javascript
899
+ * function my_token_render(tokens, idx, options, env, renderer) {
900
+ * // ...
901
+ * return renderedHTML;
902
+ * }
903
+ * ```
904
+ */
905
+ "rules",
906
+ Object.assign({}, default_rules)
907
+ );
908
+ }
919
909
  /**
920
- * Token#markup -> String
921
- *
922
- * '*' or '_' for emphasis, fence string for fence, etc.
923
- **/
924
- this.markup = "";
910
+ * Render token attributes to string.
911
+ */
912
+ renderAttrs(token) {
913
+ let i, l, result;
914
+ if (!token.attrs) return "";
915
+ result = "";
916
+ for (i = 0, l = token.attrs.length; i < l; i++) result += ` ${escapeHtml(token.attrs[i][0])}="${escapeHtml(String(token.attrs[i][1]))}"`;
917
+ return result;
918
+ }
925
919
  /**
926
- * Token#info -> String
920
+ * Default token renderer. Can be overriden by custom function
921
+ * in {@link Renderer.rules}.
927
922
  *
928
- * Additional information:
929
- *
930
- * - Info string for "fence" tokens
931
- * - The value "auto" for autolink "link_open" and "link_close" tokens
932
- * - The string value of the item marker for ordered-list "list_item_open" tokens
933
- **/
934
- this.info = "";
923
+ * @param tokens List of tokens.
924
+ * @param idx Token index to render.
925
+ * @param options Params of parser instance.
926
+ */
927
+ renderToken(tokens, idx, options) {
928
+ const token = tokens[idx];
929
+ let result = "";
930
+ if (token.hidden) return "";
931
+ let prev = idx - 1;
932
+ while (prev >= 0 && tokens[prev].hidden && tokens[prev].nesting === 0) prev--;
933
+ if (token.block && token.nesting !== -1 && prev >= 0 && tokens[prev].hidden && tokens[prev].nesting === -1) result += "\n";
934
+ result += (token.nesting === -1 ? "</" : "<") + token.tag;
935
+ result += this.renderAttrs(token);
936
+ if (token.nesting === 0 && options.xhtmlOut) result += " /";
937
+ let needLf = false;
938
+ if (token.block) {
939
+ needLf = true;
940
+ if (token.nesting === 1) {
941
+ let next = idx + 1;
942
+ while (next < tokens.length && tokens[next].hidden && tokens[next].nesting === 0) next++;
943
+ if (next < tokens.length) {
944
+ const nextToken = tokens[next];
945
+ if (nextToken.type === "inline" || nextToken.hidden) needLf = false;
946
+ else if (nextToken.nesting === -1 && nextToken.tag === token.tag) needLf = false;
947
+ }
948
+ }
949
+ }
950
+ result += needLf ? ">\n" : ">";
951
+ return result;
952
+ }
935
953
  /**
936
- * Token#meta -> Object
954
+ * The same as {@link Renderer.render}, but for single token of `inline` type.
937
955
  *
938
- * A place for plugins to store an arbitrary data
939
- **/
940
- this.meta = null;
956
+ * @param tokens List on block tokens to render.
957
+ * @param options Params of parser instance.
958
+ * @param env Additional data from parsed input (references, for example).
959
+ */
960
+ renderInline(tokens, options, env) {
961
+ let result = "";
962
+ const rules = this.rules;
963
+ for (let i = 0, len = tokens.length; i < len; i++) {
964
+ const type = tokens[i].type;
965
+ if (typeof rules[type] !== "undefined") result += rules[type](tokens, i, options, env, this);
966
+ else result += this.renderToken(tokens, i, options);
967
+ }
968
+ return result;
969
+ }
941
970
  /**
942
- * Token#block -> Boolean
971
+ * Special kludge for image `alt` attributes to conform CommonMark spec.
972
+ * Don't try to use it! Spec requires to show `alt` content with stripped markup,
973
+ * instead of simple escaping.
943
974
  *
944
- * True for block-level tokens, false for inline tokens.
945
- * Used in renderer to calculate line breaks
946
- **/
947
- this.block = false;
975
+ * @param tokens List on block tokens to render.
976
+ * @param options Params of parser instance.
977
+ * @param env Additional data from parsed input (references, for example).
978
+ */
979
+ renderInlineAsText(tokens, options, env) {
980
+ let result = "";
981
+ for (let i = 0, len = tokens.length; i < len; i++) switch (tokens[i].type) {
982
+ case "text":
983
+ case "code_inline":
984
+ result += tokens[i].content;
985
+ break;
986
+ case "image":
987
+ result += this.renderInlineAsText(tokens[i].children, options, env);
988
+ break;
989
+ case "html_inline":
990
+ case "html_block":
991
+ result += tokens[i].content;
992
+ break;
993
+ case "softbreak":
994
+ case "hardbreak": result += "\n";
995
+ }
996
+ return result;
997
+ }
948
998
  /**
949
- * Token#hidden -> Boolean
999
+ * Takes token stream and generates HTML. Probably, you will never need to call
1000
+ * this method directly.
950
1001
  *
951
- * If it's true, ignore this element when rendering. Used for tight lists
952
- * to hide paragraphs.
953
- **/
954
- this.hidden = false;
955
- }
956
- /**
957
- * Token.attrIndex(name) -> Number
958
- *
959
- * Search attribute index by name.
960
- **/
961
- Token.prototype.attrIndex = function attrIndex(name) {
962
- if (!this.attrs) return -1;
963
- const attrs = this.attrs;
964
- for (let i = 0, len = attrs.length; i < len; i++) if (attrs[i][0] === name) return i;
965
- return -1;
966
- };
967
- /**
968
- * Token.attrPush(attrData)
969
- *
970
- * Add `[ name, value ]` attribute to list. Init attrs if necessary
971
- **/
972
- Token.prototype.attrPush = function attrPush(attrData) {
973
- if (this.attrs) this.attrs.push(attrData);
974
- else this.attrs = [attrData];
975
- };
976
- /**
977
- * Token.attrSet(name, value)
978
- *
979
- * Set `name` attribute to `value`. Override old value if exists.
980
- **/
981
- Token.prototype.attrSet = function attrSet(name, value) {
982
- const idx = this.attrIndex(name);
983
- const attrData = [name, value];
984
- if (idx < 0) this.attrPush(attrData);
985
- else this.attrs[idx] = attrData;
986
- };
987
- /**
988
- * Token.attrGet(name)
989
- *
990
- * Get the value of attribute `name`, or null if it does not exist.
991
- **/
992
- Token.prototype.attrGet = function attrGet(name) {
993
- const idx = this.attrIndex(name);
994
- let value = null;
995
- if (idx >= 0) value = this.attrs[idx][1];
996
- return value;
997
- };
998
- /**
999
- * Token.attrJoin(name, value)
1000
- *
1001
- * Join value to existing attribute via space. Or create new attribute if not
1002
- * exists. Useful to operate with token classes.
1003
- **/
1004
- Token.prototype.attrJoin = function attrJoin(name, value) {
1005
- const idx = this.attrIndex(name);
1006
- if (idx < 0) this.attrPush([name, value]);
1007
- else this.attrs[idx][1] = this.attrs[idx][1] + " " + value;
1002
+ * @param tokens List on block tokens to render.
1003
+ * @param options Params of parser instance.
1004
+ * @param env Additional data from parsed input (references, for example).
1005
+ */
1006
+ render(tokens, options, env) {
1007
+ let result = "";
1008
+ const rules = this.rules;
1009
+ for (let i = 0, len = tokens.length; i < len; i++) {
1010
+ const type = tokens[i].type;
1011
+ if (type === "inline") result += this.renderInline(tokens[i].children, options, env);
1012
+ else if (typeof rules[type] !== "undefined") result += rules[type](tokens, i, options, env, this);
1013
+ else result += this.renderToken(tokens, i, options);
1014
+ }
1015
+ return result;
1016
+ }
1008
1017
  };
1009
1018
  //#endregion
1010
- //#region lib/rules_core/state_core.mjs
1011
- function StateCore(src, md, env) {
1012
- this.src = src;
1013
- this.env = env;
1014
- this.tokens = [];
1015
- this.inlineMode = false;
1016
- this.md = md;
1017
- }
1018
- StateCore.prototype.Token = Token;
1019
+ //#region src/rules_core/state_core.ts
1020
+ /** Mutable state passed through the core rules chain. */
1021
+ var StateCore = class {
1022
+ constructor(src, md, env) {
1023
+ _defineProperty(this, "tokens", []);
1024
+ _defineProperty(this, "inlineMode", false);
1025
+ _defineProperty(this, "Token", Token);
1026
+ this.src = src;
1027
+ this.env = env;
1028
+ this.md = md;
1029
+ }
1030
+ };
1019
1031
  //#endregion
1020
- //#region lib/rules_core/normalize.mjs
1032
+ //#region src/rules_core/normalize.ts
1021
1033
  var NEWLINES_RE = /\r\n?|\n/g;
1022
1034
  var NULL_RE = /\0/g;
1023
1035
  function normalize(state) {
@@ -1027,7 +1039,7 @@ function normalize(state) {
1027
1039
  state.src = str;
1028
1040
  }
1029
1041
  //#endregion
1030
- //#region lib/rules_core/block.mjs
1042
+ //#region src/rules_core/block.ts
1031
1043
  function block(state) {
1032
1044
  let token;
1033
1045
  if (state.inlineMode) {
@@ -1039,7 +1051,19 @@ function block(state) {
1039
1051
  } else state.md.block.parse(state.src, state.md, state.env, state.tokens);
1040
1052
  }
1041
1053
  //#endregion
1042
- //#region lib/rules_core/inline.mjs
1054
+ //#region src/rules_core/strip_references.ts
1055
+ function strip_references(state) {
1056
+ const tokens = state.tokens;
1057
+ let last = 0;
1058
+ for (let curr = 0; curr < tokens.length; curr++) {
1059
+ if (tokens[curr].type === "reference_definition") continue;
1060
+ if (curr !== last) tokens[last] = tokens[curr];
1061
+ last++;
1062
+ }
1063
+ if (tokens.length !== last) tokens.length = last;
1064
+ }
1065
+ //#endregion
1066
+ //#region src/rules_core/inline.ts
1043
1067
  function inline(state) {
1044
1068
  const tokens = state.tokens;
1045
1069
  for (let i = 0, l = tokens.length; i < l; i++) {
@@ -1048,7 +1072,7 @@ function inline(state) {
1048
1072
  }
1049
1073
  }
1050
1074
  //#endregion
1051
- //#region lib/rules_core/linkify.mjs
1075
+ //#region src/rules_core/linkify.ts
1052
1076
  function isLinkOpen$1(str) {
1053
1077
  return /^<a[>\s]/i.test(str);
1054
1078
  }
@@ -1059,7 +1083,7 @@ function linkify$1(state) {
1059
1083
  const blockTokens = state.tokens;
1060
1084
  if (!state.md.options.linkify) return;
1061
1085
  for (let j = 0, l = blockTokens.length; j < l; j++) {
1062
- if (blockTokens[j].type !== "inline" || !state.md.linkify.pretest(blockTokens[j].content)) continue;
1086
+ if (blockTokens[j].type !== "inline" || !state.md.linkify.test(blockTokens[j].content)) continue;
1063
1087
  let tokens = blockTokens[j].children;
1064
1088
  let htmlLinkLevel = 0;
1065
1089
  for (let i = tokens.length - 1; i >= 0; i--) {
@@ -1086,8 +1110,8 @@ function linkify$1(state) {
1086
1110
  const fullUrl = state.md.normalizeLink(url);
1087
1111
  if (!state.md.validateLink(fullUrl)) continue;
1088
1112
  let urlText = links[ln].text;
1089
- if (!links[ln].schema) urlText = state.md.normalizeLinkText("http://" + urlText).replace(/^http:\/\//, "");
1090
- else if (links[ln].schema === "mailto:" && !/^mailto:/i.test(urlText)) urlText = state.md.normalizeLinkText("mailto:" + urlText).replace(/^mailto:/, "");
1113
+ if (!links[ln].schema) urlText = state.md.normalizeLinkText(`http://${urlText}`).replace(/^http:\/\//, "");
1114
+ else if (links[ln].schema === "mailto:" && !/^mailto:/i.test(urlText)) urlText = state.md.normalizeLinkText(`mailto:${urlText}`).replace(/^mailto:/, "");
1091
1115
  else urlText = state.md.normalizeLinkText(urlText);
1092
1116
  const pos = links[ln].index;
1093
1117
  if (pos > lastPos) {
@@ -1125,7 +1149,7 @@ function linkify$1(state) {
1125
1149
  }
1126
1150
  }
1127
1151
  //#endregion
1128
- //#region lib/rules_core/replacements.mjs
1152
+ //#region src/rules_core/replacements.ts
1129
1153
  var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/;
1130
1154
  var SCOPED_ABBR_TEST_RE = /\((c|tm|r)\)/i;
1131
1155
  var SCOPED_ABBR_RE = /\((c|tm|r)\)/gi;
@@ -1167,7 +1191,7 @@ function replace(state) {
1167
1191
  }
1168
1192
  }
1169
1193
  //#endregion
1170
- //#region lib/rules_core/smartquotes.mjs
1194
+ //#region src/rules_core/smartquotes.ts
1171
1195
  var QUOTE_TEST_RE = /['"]/;
1172
1196
  var QUOTE_RE = /['"]/g;
1173
1197
  var APOSTROPHE = "’";
@@ -1279,7 +1303,8 @@ function process_inlines(tokens, state) {
1279
1303
  }
1280
1304
  }
1281
1305
  Object.keys(replacements).forEach(function(tokenIdx) {
1282
- tokens[tokenIdx].content = applyReplacements(tokens[tokenIdx].content, replacements[tokenIdx]);
1306
+ const idx = Number(tokenIdx);
1307
+ tokens[idx].content = applyReplacements(tokens[idx].content, replacements[tokenIdx]);
1283
1308
  });
1284
1309
  }
1285
1310
  function smartquotes(state) {
@@ -1290,7 +1315,18 @@ function smartquotes(state) {
1290
1315
  }
1291
1316
  }
1292
1317
  //#endregion
1293
- //#region lib/rules_core/text_join.mjs
1318
+ //#region src/rules_core/text_join.ts
1319
+ function join_alt(tokens) {
1320
+ let curr, last;
1321
+ const max = tokens.length;
1322
+ for (curr = 0; curr < max; curr++) if (tokens[curr].type === "text_special") tokens[curr].type = "text";
1323
+ for (curr = last = 0; curr < max; curr++) if (tokens[curr].type === "text" && curr + 1 < max && tokens[curr + 1].type === "text") tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content;
1324
+ else {
1325
+ if (curr !== last) tokens[last] = tokens[curr];
1326
+ last++;
1327
+ }
1328
+ if (curr !== last) tokens.length = last;
1329
+ }
1294
1330
  function text_join(state) {
1295
1331
  let curr, last;
1296
1332
  const blockTokens = state.tokens;
@@ -1299,7 +1335,10 @@ function text_join(state) {
1299
1335
  if (blockTokens[j].type !== "inline") continue;
1300
1336
  const tokens = blockTokens[j].children;
1301
1337
  const max = tokens.length;
1302
- for (curr = 0; curr < max; curr++) if (tokens[curr].type === "text_special") tokens[curr].type = "text";
1338
+ for (curr = 0; curr < max; curr++) {
1339
+ if (tokens[curr].type === "text_special") tokens[curr].type = "text";
1340
+ if (tokens[curr].children) join_alt(tokens[curr].children);
1341
+ }
1303
1342
  for (curr = last = 0; curr < max; curr++) if (tokens[curr].type === "text" && curr + 1 < max && tokens[curr + 1].type === "text") tokens[curr + 1].content = tokens[curr].content + tokens[curr + 1].content;
1304
1343
  else {
1305
1344
  if (curr !== last) tokens[last] = tokens[curr];
@@ -1309,16 +1348,11 @@ function text_join(state) {
1309
1348
  }
1310
1349
  }
1311
1350
  //#endregion
1312
- //#region lib/parser_core.mjs
1313
- /** internal
1314
- * class Core
1315
- *
1316
- * Top-level rules executor. Glues block/inline parsers and does intermediate
1317
- * transformations.
1318
- **/
1351
+ //#region src/parser_core.ts
1319
1352
  var _rules$2 = [
1320
1353
  ["normalize", normalize],
1321
1354
  ["block", block],
1355
+ ["strip_references", strip_references],
1322
1356
  ["inline", inline],
1323
1357
  ["linkify", linkify$1],
1324
1358
  ["replacements", replace],
@@ -1326,136 +1360,141 @@ var _rules$2 = [
1326
1360
  ["text_join", text_join]
1327
1361
  ];
1328
1362
  /**
1329
- * new Core()
1330
- **/
1331
- function Core() {
1363
+ * Top-level rules executor. Glues block/inline parsers and does intermediate
1364
+ * transformations.
1365
+ */
1366
+ var ParserCore = class {
1367
+ constructor() {
1368
+ _defineProperty(
1369
+ this,
1370
+ /**
1371
+ * {@link Ruler} instance. Keep configuration of core rules.
1372
+ */
1373
+ "ruler",
1374
+ new Ruler()
1375
+ );
1376
+ _defineProperty(this, "State", StateCore);
1377
+ for (let i = 0; i < _rules$2.length; i++) this.ruler.push(_rules$2[i][0], _rules$2[i][1]);
1378
+ }
1332
1379
  /**
1333
- * Core#ruler -> Ruler
1334
- *
1335
- * [[Ruler]] instance. Keep configuration of core rules.
1336
- **/
1337
- this.ruler = new Ruler();
1338
- for (let i = 0; i < _rules$2.length; i++) this.ruler.push(_rules$2[i][0], _rules$2[i][1]);
1339
- }
1340
- /**
1341
- * Core.process(state)
1342
- *
1343
- * Executes core chain rules.
1344
- **/
1345
- Core.prototype.process = function(state) {
1346
- const rules = this.ruler.getRules("");
1347
- for (let i = 0, l = rules.length; i < l; i++) rules[i](state);
1380
+ * Executes core chain rules.
1381
+ */
1382
+ process(state) {
1383
+ const rules = this.ruler.getRules("");
1384
+ for (let i = 0, l = rules.length; i < l; i++) rules[i](state);
1385
+ }
1348
1386
  };
1349
- Core.prototype.State = StateCore;
1350
1387
  //#endregion
1351
- //#region lib/rules_block/state_block.mjs
1352
- function StateBlock(src, md, env, tokens) {
1353
- this.src = src;
1354
- this.md = md;
1355
- this.env = env;
1356
- this.tokens = tokens;
1357
- this.bMarks = [];
1358
- this.eMarks = [];
1359
- this.tShift = [];
1360
- this.sCount = [];
1361
- this.bsCount = [];
1362
- this.blkIndent = 0;
1363
- this.line = 0;
1364
- this.lineMax = 0;
1365
- this.tight = false;
1366
- this.ddIndent = -1;
1367
- this.listIndent = -1;
1368
- this.parentType = "root";
1369
- this.level = 0;
1370
- const s = this.src;
1371
- for (let start = 0, pos = 0, indent = 0, offset = 0, len = s.length, indent_found = false; pos < len; pos++) {
1372
- const ch = s.charCodeAt(pos);
1373
- if (!indent_found) if (isSpace(ch)) {
1374
- indent++;
1375
- if (ch === 9) offset += 4 - offset % 4;
1376
- else offset++;
1377
- continue;
1378
- } else indent_found = true;
1379
- if (ch === 10 || pos === len - 1) {
1380
- if (ch !== 10) pos++;
1381
- this.bMarks.push(start);
1382
- this.eMarks.push(pos);
1383
- this.tShift.push(indent);
1384
- this.sCount.push(offset);
1385
- this.bsCount.push(0);
1386
- indent_found = false;
1387
- indent = 0;
1388
- offset = 0;
1389
- start = pos + 1;
1388
+ //#region src/rules_block/state_block.ts
1389
+ /** Mutable state passed to block rules while tokenizing a source document. */
1390
+ var StateBlock = class {
1391
+ constructor(src, md, env, tokens) {
1392
+ _defineProperty(this, "bMarks", []);
1393
+ _defineProperty(this, "eMarks", []);
1394
+ _defineProperty(this, "tShift", []);
1395
+ _defineProperty(this, "sCount", []);
1396
+ _defineProperty(this, "bsCount", []);
1397
+ _defineProperty(this, "blkIndent", 0);
1398
+ _defineProperty(this, "line", 0);
1399
+ _defineProperty(this, "lineMax", 0);
1400
+ _defineProperty(this, "tight", false);
1401
+ _defineProperty(this, "listIndent", -1);
1402
+ _defineProperty(this, "parentType", "root");
1403
+ _defineProperty(this, "level", 0);
1404
+ _defineProperty(this, "Token", Token);
1405
+ this.src = src;
1406
+ this.md = md;
1407
+ this.env = env;
1408
+ this.tokens = tokens;
1409
+ const s = this.src;
1410
+ for (let start = 0, pos = 0, indent = 0, offset = 0, len = s.length, indent_found = false; pos < len; pos++) {
1411
+ const ch = s.charCodeAt(pos);
1412
+ if (!indent_found) if (isSpace(ch)) {
1413
+ indent++;
1414
+ if (ch === 9) offset += 4 - offset % 4;
1415
+ else offset++;
1416
+ continue;
1417
+ } else indent_found = true;
1418
+ if (ch === 10 || pos === len - 1) {
1419
+ if (ch !== 10) pos++;
1420
+ this.bMarks.push(start);
1421
+ this.eMarks.push(pos);
1422
+ this.tShift.push(indent);
1423
+ this.sCount.push(offset);
1424
+ this.bsCount.push(0);
1425
+ indent_found = false;
1426
+ indent = 0;
1427
+ offset = 0;
1428
+ start = pos + 1;
1429
+ }
1390
1430
  }
1391
- }
1392
- this.bMarks.push(s.length);
1393
- this.eMarks.push(s.length);
1394
- this.tShift.push(0);
1395
- this.sCount.push(0);
1396
- this.bsCount.push(0);
1397
- this.lineMax = this.bMarks.length - 1;
1398
- }
1399
- StateBlock.prototype.push = function(type, tag, nesting) {
1400
- const token = new Token(type, tag, nesting);
1401
- token.block = true;
1402
- if (nesting < 0) this.level--;
1403
- token.level = this.level;
1404
- if (nesting > 0) this.level++;
1405
- this.tokens.push(token);
1406
- return token;
1407
- };
1408
- StateBlock.prototype.isEmpty = function isEmpty(line) {
1409
- return this.bMarks[line] + this.tShift[line] >= this.eMarks[line];
1410
- };
1411
- StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) {
1412
- for (let max = this.lineMax; from < max; from++) if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) break;
1413
- return from;
1414
- };
1415
- StateBlock.prototype.skipSpaces = function skipSpaces(pos) {
1416
- for (let max = this.src.length; pos < max; pos++) if (!isSpace(this.src.charCodeAt(pos))) break;
1417
- return pos;
1418
- };
1419
- StateBlock.prototype.skipSpacesBack = function skipSpacesBack(pos, min) {
1420
- if (pos <= min) return pos;
1421
- while (pos > min) if (!isSpace(this.src.charCodeAt(--pos))) return pos + 1;
1422
- return pos;
1423
- };
1424
- StateBlock.prototype.skipChars = function skipChars(pos, code) {
1425
- for (let max = this.src.length; pos < max; pos++) if (this.src.charCodeAt(pos) !== code) break;
1426
- return pos;
1427
- };
1428
- StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
1429
- if (pos <= min) return pos;
1430
- while (pos > min) if (code !== this.src.charCodeAt(--pos)) return pos + 1;
1431
- return pos;
1432
- };
1433
- StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
1434
- if (begin >= end) return "";
1435
- const queue = new Array(end - begin);
1436
- for (let i = 0, line = begin; line < end; line++, i++) {
1437
- let lineIndent = 0;
1438
- const lineStart = this.bMarks[line];
1439
- let first = lineStart;
1440
- let last;
1441
- if (line + 1 < end || keepLastLF) last = this.eMarks[line] + 1;
1442
- else last = this.eMarks[line];
1443
- while (first < last && lineIndent < indent) {
1444
- const ch = this.src.charCodeAt(first);
1445
- if (isSpace(ch)) if (ch === 9) lineIndent += 4 - (lineIndent + this.bsCount[line]) % 4;
1446
- else lineIndent++;
1447
- else if (first - lineStart < this.tShift[line]) lineIndent++;
1448
- else break;
1449
- first++;
1431
+ this.bMarks.push(s.length);
1432
+ this.eMarks.push(s.length);
1433
+ this.tShift.push(0);
1434
+ this.sCount.push(0);
1435
+ this.bsCount.push(0);
1436
+ this.lineMax = this.bMarks.length - 1;
1437
+ }
1438
+ push(type, tag, nesting) {
1439
+ const token = new Token(type, tag, nesting);
1440
+ token.block = true;
1441
+ if (nesting < 0) this.level--;
1442
+ token.level = this.level;
1443
+ if (nesting > 0) this.level++;
1444
+ this.tokens.push(token);
1445
+ return token;
1446
+ }
1447
+ isEmpty(line) {
1448
+ return this.bMarks[line] + this.tShift[line] >= this.eMarks[line];
1449
+ }
1450
+ skipEmptyLines(from) {
1451
+ for (let max = this.lineMax; from < max; from++) if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) break;
1452
+ return from;
1453
+ }
1454
+ skipSpaces(pos) {
1455
+ for (let max = this.src.length; pos < max; pos++) if (!isSpace(this.src.charCodeAt(pos))) break;
1456
+ return pos;
1457
+ }
1458
+ skipSpacesBack(pos, min) {
1459
+ if (pos <= min) return pos;
1460
+ while (pos > min) if (!isSpace(this.src.charCodeAt(--pos))) return pos + 1;
1461
+ return pos;
1462
+ }
1463
+ skipChars(pos, code) {
1464
+ for (let max = this.src.length; pos < max; pos++) if (this.src.charCodeAt(pos) !== code) break;
1465
+ return pos;
1466
+ }
1467
+ skipCharsBack(pos, code, min) {
1468
+ if (pos <= min) return pos;
1469
+ while (pos > min) if (code !== this.src.charCodeAt(--pos)) return pos + 1;
1470
+ return pos;
1471
+ }
1472
+ getLines(begin, end, indent, keepLastLF) {
1473
+ if (begin >= end) return "";
1474
+ const queue = new Array(end - begin);
1475
+ for (let i = 0, line = begin; line < end; line++, i++) {
1476
+ let lineIndent = 0;
1477
+ const lineStart = this.bMarks[line];
1478
+ let first = lineStart;
1479
+ let last;
1480
+ if (line + 1 < end || keepLastLF) last = this.eMarks[line] + 1;
1481
+ else last = this.eMarks[line];
1482
+ while (first < last && lineIndent < indent) {
1483
+ const ch = this.src.charCodeAt(first);
1484
+ if (isSpace(ch)) if (ch === 9) lineIndent += 4 - (lineIndent + this.bsCount[line]) % 4;
1485
+ else lineIndent++;
1486
+ else if (first - lineStart < this.tShift[line]) lineIndent++;
1487
+ else break;
1488
+ first++;
1489
+ }
1490
+ if (lineIndent > indent) queue[i] = new Array(lineIndent - indent + 1).join(" ") + this.src.slice(first, last);
1491
+ else queue[i] = this.src.slice(first, last);
1450
1492
  }
1451
- if (lineIndent > indent) queue[i] = new Array(lineIndent - indent + 1).join(" ") + this.src.slice(first, last);
1452
- else queue[i] = this.src.slice(first, last);
1493
+ return queue.join("");
1453
1494
  }
1454
- return queue.join("");
1455
1495
  };
1456
- StateBlock.prototype.Token = Token;
1457
1496
  //#endregion
1458
- //#region lib/rules_block/table.mjs
1497
+ //#region src/rules_block/table.ts
1459
1498
  var MAX_AUTOCOMPLETED_CELLS = 65536;
1460
1499
  function getLine(state, line) {
1461
1500
  const pos = state.bMarks[line] + state.tShift[line];
@@ -1537,7 +1576,7 @@ function table(state, startLine, endLine, silent) {
1537
1576
  token_htro.map = [startLine, startLine + 1];
1538
1577
  for (let i = 0; i < columns.length; i++) {
1539
1578
  const token_ho = state.push("th_open", "th", 1);
1540
- if (aligns[i]) token_ho.attrs = [["style", "text-align:" + aligns[i]]];
1579
+ if (aligns[i]) token_ho.attrs = [["style", `text-align:${aligns[i]}`]];
1541
1580
  const token_il = state.push("inline", "", 0);
1542
1581
  token_il.content = columns[i].trim();
1543
1582
  token_il.children = [];
@@ -1571,7 +1610,7 @@ function table(state, startLine, endLine, silent) {
1571
1610
  token_tro.map = [nextLine, nextLine + 1];
1572
1611
  for (let i = 0; i < columnCount; i++) {
1573
1612
  const token_tdo = state.push("td_open", "td", 1);
1574
- if (aligns[i]) token_tdo.attrs = [["style", "text-align:" + aligns[i]]];
1613
+ if (aligns[i]) token_tdo.attrs = [["style", `text-align:${aligns[i]}`]];
1575
1614
  const token_il = state.push("inline", "", 0);
1576
1615
  token_il.content = columns[i] ? columns[i].trim() : "";
1577
1616
  token_il.children = [];
@@ -1590,7 +1629,7 @@ function table(state, startLine, endLine, silent) {
1590
1629
  return true;
1591
1630
  }
1592
1631
  //#endregion
1593
- //#region lib/rules_block/code.mjs
1632
+ //#region src/rules_block/code.ts
1594
1633
  function code(state, startLine, endLine) {
1595
1634
  if (state.sCount[startLine] - state.blkIndent < 4) return false;
1596
1635
  let nextLine = startLine + 1;
@@ -1614,7 +1653,7 @@ function code(state, startLine, endLine) {
1614
1653
  return true;
1615
1654
  }
1616
1655
  //#endregion
1617
- //#region lib/rules_block/fence.mjs
1656
+ //#region src/rules_block/fence.ts
1618
1657
  function fence(state, startLine, endLine, silent) {
1619
1658
  let pos = state.bMarks[startLine] + state.tShift[startLine];
1620
1659
  let max = state.eMarks[startLine];
@@ -1659,7 +1698,7 @@ function fence(state, startLine, endLine, silent) {
1659
1698
  return true;
1660
1699
  }
1661
1700
  //#endregion
1662
- //#region lib/rules_block/blockquote.mjs
1701
+ //#region src/rules_block/blockquote.ts
1663
1702
  function blockquote(state, startLine, endLine, silent) {
1664
1703
  let pos = state.bMarks[startLine] + state.tShift[startLine];
1665
1704
  let max = state.eMarks[startLine];
@@ -1762,7 +1801,7 @@ function blockquote(state, startLine, endLine, silent) {
1762
1801
  return true;
1763
1802
  }
1764
1803
  //#endregion
1765
- //#region lib/rules_block/hr.mjs
1804
+ //#region src/rules_block/hr.ts
1766
1805
  function hr(state, startLine, endLine, silent) {
1767
1806
  const max = state.eMarks[startLine];
1768
1807
  if (state.sCount[startLine] - state.blkIndent >= 4) return false;
@@ -1784,7 +1823,7 @@ function hr(state, startLine, endLine, silent) {
1784
1823
  return true;
1785
1824
  }
1786
1825
  //#endregion
1787
- //#region lib/rules_block/list.mjs
1826
+ //#region src/rules_block/list.ts
1788
1827
  function skipBulletListMarker(state, startLine) {
1789
1828
  const max = state.eMarks[startLine];
1790
1829
  let pos = state.bMarks[startLine] + state.tShift[startLine];
@@ -1896,7 +1935,7 @@ function list(state, startLine, endLine, silent) {
1896
1935
  state.tShift[nextLine] = contentStart - state.bMarks[nextLine];
1897
1936
  state.sCount[nextLine] = offset;
1898
1937
  if (contentStart >= max && state.isEmpty(nextLine + 1)) state.line = Math.min(state.line + 2, endLine);
1899
- else state.md.block.tokenize(state, nextLine, endLine, true);
1938
+ else state.md.block.tokenize(state, nextLine, endLine);
1900
1939
  if (!state.tight || prevEmptyEnd) tight = false;
1901
1940
  prevEmptyEnd = state.line - nextLine > 1 && state.isEmpty(state.line - 1);
1902
1941
  state.blkIndent = state.listIndent;
@@ -1937,7 +1976,7 @@ function list(state, startLine, endLine, silent) {
1937
1976
  return true;
1938
1977
  }
1939
1978
  //#endregion
1940
- //#region lib/rules_block/reference.mjs
1979
+ //#region src/rules_block/reference.ts
1941
1980
  function reference(state, startLine, _endLine, silent) {
1942
1981
  let pos = state.bMarks[startLine] + state.tShift[startLine];
1943
1982
  let max = state.eMarks[startLine];
@@ -2069,11 +2108,17 @@ function reference(state, startLine, _endLine, silent) {
2069
2108
  title,
2070
2109
  href
2071
2110
  };
2111
+ const token = state.push("reference_definition", "", 0);
2112
+ token.map = [startLine, nextLine];
2113
+ token.hidden = true;
2114
+ const meta = Object.create(null);
2115
+ meta.label = label;
2116
+ token.meta = meta;
2072
2117
  state.line = nextLine;
2073
2118
  return true;
2074
2119
  }
2075
2120
  //#endregion
2076
- //#region lib/common/html_blocks.mjs
2121
+ //#region src/common/html_blocks.ts
2077
2122
  var html_blocks_default = [
2078
2123
  "address",
2079
2124
  "article",
@@ -2139,11 +2184,13 @@ var html_blocks_default = [
2139
2184
  "ul"
2140
2185
  ];
2141
2186
  //#endregion
2142
- //#region lib/common/html_re.mjs
2143
- var HTML_TAG_RE = /* @__PURE__ */ new RegExp("^(?:<[A-Za-z][A-Za-z0-9\\-]*(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^\"'=<>`\\x00-\\x20]+|'[^']*'|\"[^\"]*\"))?)*\\s*\\/?>|<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>|<!---?>|<!--(?:[^-]|-[^-]|--[^>])*-->|<[?][\\s\\S]*?[?]>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)");
2144
- var HTML_OPEN_CLOSE_TAG_RE = /* @__PURE__ */ new RegExp("^(?:<[A-Za-z][A-Za-z0-9\\-]*(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^\"'=<>`\\x00-\\x20]+|'[^']*'|\"[^\"]*\"))?)*\\s*\\/?>|<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>)");
2187
+ //#region src/common/html_re.ts
2188
+ var open_tag = `<[A-Za-z][A-Za-z0-9\\-]*(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^"'=<>\`\\x00-\\x20]+|'[^']*'|"[^"]*"))?)*\\s*\\/?>`;
2189
+ var close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>";
2190
+ var HTML_TAG_RE = new RegExp(`^(?:${open_tag}|${close_tag}|<!---?>|<!--(?:[^-]|-[^-]|--[^>])*-->|<[?][\\s\\S]*?[?]>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
2191
+ var HTML_OPEN_CLOSE_TAG_RE = new RegExp(`^(?:${open_tag}|${close_tag})`);
2145
2192
  //#endregion
2146
- //#region lib/rules_block/html_block.mjs
2193
+ //#region src/rules_block/html_block.ts
2147
2194
  var HTML_SEQUENCES = [
2148
2195
  [
2149
2196
  /^<(script|pre|style|textarea)(?=(\s|>|$))/i,
@@ -2161,7 +2208,7 @@ var HTML_SEQUENCES = [
2161
2208
  true
2162
2209
  ],
2163
2210
  [
2164
- /^<![A-Z]/,
2211
+ /^<![A-Za-z]/,
2165
2212
  />/,
2166
2213
  true
2167
2214
  ],
@@ -2171,12 +2218,12 @@ var HTML_SEQUENCES = [
2171
2218
  true
2172
2219
  ],
2173
2220
  [
2174
- new RegExp("^</?(" + html_blocks_default.join("|") + ")(?=(\\s|/?>|$))", "i"),
2221
+ new RegExp(`^</?(${html_blocks_default.join("|")})(?=(\\s|/?>|$))`, "i"),
2175
2222
  /^$/,
2176
2223
  true
2177
2224
  ],
2178
2225
  [
2179
- new RegExp(HTML_OPEN_CLOSE_TAG_RE.source + "\\s*$"),
2226
+ new RegExp(`${HTML_OPEN_CLOSE_TAG_RE.source}\\s*$`),
2180
2227
  /^$/,
2181
2228
  false
2182
2229
  ]
@@ -2213,7 +2260,7 @@ function html_block(state, startLine, endLine, silent) {
2213
2260
  return true;
2214
2261
  }
2215
2262
  //#endregion
2216
- //#region lib/rules_block/heading.mjs
2263
+ //#region src/rules_block/heading.ts
2217
2264
  function heading(state, startLine, endLine, silent) {
2218
2265
  let pos = state.bMarks[startLine] + state.tShift[startLine];
2219
2266
  let max = state.eMarks[startLine];
@@ -2232,19 +2279,19 @@ function heading(state, startLine, endLine, silent) {
2232
2279
  const tmp = state.skipCharsBack(max, 35, pos);
2233
2280
  if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) max = tmp;
2234
2281
  state.line = startLine + 1;
2235
- const token_o = state.push("heading_open", "h" + String(level), 1);
2282
+ const token_o = state.push("heading_open", `h${level}`, 1);
2236
2283
  token_o.markup = "########".slice(0, level);
2237
2284
  token_o.map = [startLine, state.line];
2238
2285
  const token_i = state.push("inline", "", 0);
2239
2286
  token_i.content = asciiTrim(state.src.slice(pos, max));
2240
2287
  token_i.map = [startLine, state.line];
2241
2288
  token_i.children = [];
2242
- const token_c = state.push("heading_close", "h" + String(level), -1);
2289
+ const token_c = state.push("heading_close", `h${level}`, -1);
2243
2290
  token_c.markup = "########".slice(0, level);
2244
2291
  return true;
2245
2292
  }
2246
2293
  //#endregion
2247
- //#region lib/rules_block/lheading.mjs
2294
+ //#region src/rules_block/lheading.ts
2248
2295
  function lheading(state, startLine, endLine) {
2249
2296
  const terminatorRules = state.md.block.ruler.getRules("paragraph");
2250
2297
  if (state.sCount[startLine] - state.blkIndent >= 4) return false;
@@ -2284,20 +2331,20 @@ function lheading(state, startLine, endLine) {
2284
2331
  }
2285
2332
  const content = asciiTrim(state.getLines(startLine, nextLine, state.blkIndent, false));
2286
2333
  state.line = nextLine + 1;
2287
- const token_o = state.push("heading_open", "h" + String(level), 1);
2334
+ const token_o = state.push("heading_open", `h${level}`, 1);
2288
2335
  token_o.markup = String.fromCharCode(marker);
2289
2336
  token_o.map = [startLine, state.line];
2290
2337
  const token_i = state.push("inline", "", 0);
2291
2338
  token_i.content = content;
2292
2339
  token_i.map = [startLine, state.line - 1];
2293
2340
  token_i.children = [];
2294
- const token_c = state.push("heading_close", "h" + String(level), -1);
2341
+ const token_c = state.push("heading_close", `h${level}`, -1);
2295
2342
  token_c.markup = String.fromCharCode(marker);
2296
2343
  state.parentType = oldParentType;
2297
2344
  return true;
2298
2345
  }
2299
2346
  //#endregion
2300
- //#region lib/rules_block/paragraph.mjs
2347
+ //#region src/rules_block/paragraph.ts
2301
2348
  function paragraph(state, startLine, endLine) {
2302
2349
  const terminatorRules = state.md.block.ruler.getRules("paragraph");
2303
2350
  const oldParentType = state.parentType;
@@ -2326,12 +2373,7 @@ function paragraph(state, startLine, endLine) {
2326
2373
  return true;
2327
2374
  }
2328
2375
  //#endregion
2329
- //#region lib/parser_block.mjs
2330
- /** internal
2331
- * class ParserBlock
2332
- *
2333
- * Block-level tokenizer.
2334
- **/
2376
+ //#region src/parser_block.ts
2335
2377
  var _rules$1 = [
2336
2378
  [
2337
2379
  "table",
@@ -2401,148 +2443,153 @@ var _rules$1 = [
2401
2443
  ["paragraph", paragraph]
2402
2444
  ];
2403
2445
  /**
2404
- * new ParserBlock()
2405
- **/
2406
- function ParserBlock() {
2407
- /**
2408
- * ParserBlock#ruler -> Ruler
2409
- *
2410
- * [[Ruler]] instance. Keep configuration of block rules.
2411
- **/
2412
- this.ruler = new Ruler();
2413
- for (let i = 0; i < _rules$1.length; i++) this.ruler.push(_rules$1[i][0], _rules$1[i][1], { alt: (_rules$1[i][2] || []).slice() });
2414
- }
2415
- ParserBlock.prototype.tokenize = function(state, startLine, endLine) {
2416
- const rules = this.ruler.getRules("");
2417
- const len = rules.length;
2418
- const maxNesting = state.md.options.maxNesting;
2419
- let line = startLine;
2420
- let hasEmptyLines = false;
2421
- while (line < endLine) {
2422
- state.line = line = state.skipEmptyLines(line);
2423
- if (line >= endLine) break;
2424
- if (state.sCount[line] < state.blkIndent) break;
2425
- if (state.level >= maxNesting) {
2426
- state.line = endLine;
2427
- break;
2428
- }
2429
- const prevLine = state.line;
2430
- let ok = false;
2431
- for (let i = 0; i < len; i++) {
2432
- ok = rules[i](state, line, endLine, false);
2433
- if (ok) {
2434
- if (prevLine >= state.line) throw new Error("block rule didn't increment state.line");
2446
+ * Block-level tokenizer.
2447
+ */
2448
+ var ParserBlock = class {
2449
+ constructor() {
2450
+ _defineProperty(
2451
+ this,
2452
+ /**
2453
+ * {@link Ruler} instance. Keep configuration of block rules.
2454
+ */
2455
+ "ruler",
2456
+ new Ruler()
2457
+ );
2458
+ _defineProperty(this, "State", StateBlock);
2459
+ for (let i = 0; i < _rules$1.length; i++) this.ruler.push(_rules$1[i][0], _rules$1[i][1], { alt: (_rules$1[i][2] || []).slice() });
2460
+ }
2461
+ tokenize(state, startLine, endLine) {
2462
+ const rules = this.ruler.getRules("");
2463
+ const len = rules.length;
2464
+ const maxNesting = state.md.options.maxNesting;
2465
+ let line = startLine;
2466
+ let hasEmptyLines = false;
2467
+ while (line < endLine) {
2468
+ state.line = line = state.skipEmptyLines(line);
2469
+ if (line >= endLine) break;
2470
+ if (state.sCount[line] < state.blkIndent) break;
2471
+ if (state.level >= maxNesting) {
2472
+ state.line = endLine;
2435
2473
  break;
2436
2474
  }
2437
- }
2438
- if (!ok) throw new Error("none of the block rules matched");
2439
- state.tight = !hasEmptyLines;
2440
- if (state.isEmpty(state.line - 1)) hasEmptyLines = true;
2441
- line = state.line;
2442
- if (line < endLine && state.isEmpty(line)) {
2443
- hasEmptyLines = true;
2444
- line++;
2445
- state.line = line;
2475
+ const prevLine = state.line;
2476
+ let ok = false;
2477
+ for (let i = 0; i < len; i++) {
2478
+ ok = rules[i](state, line, endLine, false);
2479
+ if (ok) {
2480
+ if (prevLine >= state.line) throw new Error("block rule didn't increment state.line");
2481
+ break;
2482
+ }
2483
+ }
2484
+ if (!ok) throw new Error("none of the block rules matched");
2485
+ state.tight = !hasEmptyLines;
2486
+ if (state.isEmpty(state.line - 1)) hasEmptyLines = true;
2487
+ line = state.line;
2488
+ if (line < endLine && state.isEmpty(line)) {
2489
+ hasEmptyLines = true;
2490
+ line++;
2491
+ state.line = line;
2492
+ }
2446
2493
  }
2447
2494
  }
2495
+ /**
2496
+ * Process input string and push block tokens into `outTokens`
2497
+ */
2498
+ parse(src, md, env, outTokens) {
2499
+ if (!src) return;
2500
+ const state = new this.State(src, md, env, outTokens);
2501
+ this.tokenize(state, state.line, state.lineMax);
2502
+ }
2448
2503
  };
2449
- /**
2450
- * ParserBlock.parse(str, md, env, outTokens)
2451
- *
2452
- * Process input string and push block tokens into `outTokens`
2453
- **/
2454
- ParserBlock.prototype.parse = function(src, md, env, outTokens) {
2455
- if (!src) return;
2456
- const state = new this.State(src, md, env, outTokens);
2457
- this.tokenize(state, state.line, state.lineMax);
2458
- };
2459
- ParserBlock.prototype.State = StateBlock;
2460
2504
  //#endregion
2461
- //#region lib/rules_inline/state_inline.mjs
2462
- function StateInline(src, md, env, outTokens) {
2463
- this.src = src;
2464
- this.env = env;
2465
- this.md = md;
2466
- this.tokens = outTokens;
2467
- this.tokens_meta = Array(outTokens.length);
2468
- this.pos = 0;
2469
- this.posMax = this.src.length;
2470
- this.level = 0;
2471
- this.pending = "";
2472
- this.pendingLevel = 0;
2473
- this.cache = {};
2474
- this.delimiters = [];
2475
- this._prev_delimiters = [];
2476
- this.backticks = {};
2477
- this.backticksScanned = false;
2478
- this.linkLevel = 0;
2479
- }
2480
- StateInline.prototype.pushPending = function() {
2481
- const token = new Token("text", "", 0);
2482
- token.content = this.pending;
2483
- token.level = this.pendingLevel;
2484
- this.tokens.push(token);
2485
- this.pending = "";
2486
- return token;
2487
- };
2488
- StateInline.prototype.push = function(type, tag, nesting) {
2489
- if (this.pending) this.pushPending();
2490
- const token = new Token(type, tag, nesting);
2491
- let token_meta = null;
2492
- if (nesting < 0) {
2493
- this.level--;
2494
- this.delimiters = this._prev_delimiters.pop();
2495
- }
2496
- token.level = this.level;
2497
- if (nesting > 0) {
2498
- this.level++;
2499
- this._prev_delimiters.push(this.delimiters);
2500
- this.delimiters = [];
2501
- token_meta = { delimiters: this.delimiters };
2502
- }
2503
- this.pendingLevel = this.level;
2504
- this.tokens.push(token);
2505
- this.tokens_meta.push(token_meta);
2506
- return token;
2507
- };
2508
- StateInline.prototype.scanDelims = function(start, canSplitWord) {
2509
- const max = this.posMax;
2510
- const marker = this.src.charCodeAt(start);
2511
- let lastChar;
2512
- if (start === 0) lastChar = 32;
2513
- else if (start === 1) {
2514
- lastChar = this.src.charCodeAt(0);
2515
- if ((lastChar & 63488) === 55296) lastChar = 65533;
2516
- } else {
2517
- lastChar = this.src.charCodeAt(start - 1);
2518
- if ((lastChar & 64512) === 56320) {
2519
- const highSurr = this.src.charCodeAt(start - 2);
2520
- lastChar = (highSurr & 64512) === 55296 ? 65536 + (highSurr - 55296 << 10) + (lastChar - 56320) : 65533;
2521
- } else if ((lastChar & 64512) === 55296) lastChar = 65533;
2505
+ //#region src/rules_inline/state_inline.ts
2506
+ /** Mutable state passed to inline rules while tokenizing inline content. */
2507
+ var StateInline = class {
2508
+ constructor(src, md, env, outTokens) {
2509
+ _defineProperty(this, "pos", 0);
2510
+ _defineProperty(this, "level", 0);
2511
+ _defineProperty(this, "pending", "");
2512
+ _defineProperty(this, "pendingLevel", 0);
2513
+ _defineProperty(this, "cache", {});
2514
+ _defineProperty(this, "backticks", {});
2515
+ _defineProperty(this, "backticksScanned", false);
2516
+ _defineProperty(this, "linkLevel", 0);
2517
+ _defineProperty(this, "delimiters", []);
2518
+ _defineProperty(this, "_prev_delimiters", []);
2519
+ _defineProperty(this, "Token", Token);
2520
+ this.src = src;
2521
+ this.env = env;
2522
+ this.md = md;
2523
+ this.tokens = outTokens;
2524
+ this.tokens_meta = Array(outTokens.length);
2525
+ this.posMax = this.src.length;
2526
+ }
2527
+ pushPending() {
2528
+ const token = new Token("text", "", 0);
2529
+ token.content = this.pending;
2530
+ token.level = this.pendingLevel;
2531
+ this.tokens.push(token);
2532
+ this.pending = "";
2533
+ return token;
2534
+ }
2535
+ push(type, tag, nesting) {
2536
+ if (this.pending) this.pushPending();
2537
+ const token = new Token(type, tag, nesting);
2538
+ let token_meta = void 0;
2539
+ if (nesting < 0) {
2540
+ this.level--;
2541
+ this.delimiters = this._prev_delimiters.pop();
2542
+ }
2543
+ token.level = this.level;
2544
+ if (nesting > 0) {
2545
+ this.level++;
2546
+ this._prev_delimiters.push(this.delimiters);
2547
+ this.delimiters = [];
2548
+ token_meta = { delimiters: this.delimiters };
2549
+ }
2550
+ this.pendingLevel = this.level;
2551
+ this.tokens.push(token);
2552
+ this.tokens_meta.push(token_meta);
2553
+ return token;
2554
+ }
2555
+ scanDelims(start, canSplitWord) {
2556
+ const max = this.posMax;
2557
+ const marker = this.src.charCodeAt(start);
2558
+ let lastChar;
2559
+ if (start === 0) lastChar = 32;
2560
+ else if (start === 1) {
2561
+ lastChar = this.src.charCodeAt(0);
2562
+ if ((lastChar & 63488) === 55296) lastChar = 65533;
2563
+ } else {
2564
+ lastChar = this.src.charCodeAt(start - 1);
2565
+ if ((lastChar & 64512) === 56320) {
2566
+ const highSurr = this.src.charCodeAt(start - 2);
2567
+ lastChar = (highSurr & 64512) === 55296 ? 65536 + (highSurr - 55296 << 10) + (lastChar - 56320) : 65533;
2568
+ } else if ((lastChar & 64512) === 55296) lastChar = 65533;
2569
+ }
2570
+ let pos = start;
2571
+ while (pos < max && this.src.charCodeAt(pos) === marker) pos++;
2572
+ const count = pos - start;
2573
+ let nextChar = pos < max ? this.src.charCodeAt(pos) : 32;
2574
+ if ((nextChar & 64512) === 55296) {
2575
+ const lowSurr = this.src.charCodeAt(pos + 1);
2576
+ nextChar = (lowSurr & 64512) === 56320 ? 65536 + (nextChar - 55296 << 10) + (lowSurr - 56320) : 65533;
2577
+ } else if ((nextChar & 64512) === 56320) nextChar = 65533;
2578
+ const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar);
2579
+ const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar);
2580
+ const isLastWhiteSpace = isWhiteSpace(lastChar);
2581
+ const isNextWhiteSpace = isWhiteSpace(nextChar);
2582
+ const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar);
2583
+ const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar);
2584
+ return {
2585
+ can_open: left_flanking && (canSplitWord || !right_flanking || isLastPunctChar),
2586
+ can_close: right_flanking && (canSplitWord || !left_flanking || isNextPunctChar),
2587
+ length: count
2588
+ };
2522
2589
  }
2523
- let pos = start;
2524
- while (pos < max && this.src.charCodeAt(pos) === marker) pos++;
2525
- const count = pos - start;
2526
- let nextChar = pos < max ? this.src.charCodeAt(pos) : 32;
2527
- if ((nextChar & 64512) === 55296) {
2528
- const lowSurr = this.src.charCodeAt(pos + 1);
2529
- nextChar = (lowSurr & 64512) === 56320 ? 65536 + (nextChar - 55296 << 10) + (lowSurr - 56320) : 65533;
2530
- } else if ((nextChar & 64512) === 56320) nextChar = 65533;
2531
- const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar);
2532
- const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar);
2533
- const isLastWhiteSpace = isWhiteSpace(lastChar);
2534
- const isNextWhiteSpace = isWhiteSpace(nextChar);
2535
- const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar);
2536
- const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar);
2537
- return {
2538
- can_open: left_flanking && (canSplitWord || !right_flanking || isLastPunctChar),
2539
- can_close: right_flanking && (canSplitWord || !left_flanking || isNextPunctChar),
2540
- length: count
2541
- };
2542
2590
  };
2543
- StateInline.prototype.Token = Token;
2544
2591
  //#endregion
2545
- //#region lib/rules_inline/text.mjs
2592
+ //#region src/rules_inline/text.ts
2546
2593
  function isTerminatorChar(ch) {
2547
2594
  switch (ch) {
2548
2595
  case 10:
@@ -2580,7 +2627,7 @@ function text(state, silent) {
2580
2627
  return true;
2581
2628
  }
2582
2629
  //#endregion
2583
- //#region lib/rules_inline/linkify.mjs
2630
+ //#region src/rules_inline/linkify.ts
2584
2631
  var SCHEME_RE = /(?:^|[^a-z0-9.+-])([a-z][a-z0-9.+-]*)$/i;
2585
2632
  function linkify(state, silent) {
2586
2633
  if (!state.md.options.linkify) return false;
@@ -2619,7 +2666,7 @@ function linkify(state, silent) {
2619
2666
  return true;
2620
2667
  }
2621
2668
  //#endregion
2622
- //#region lib/rules_inline/newline.mjs
2669
+ //#region src/rules_inline/newline.ts
2623
2670
  function newline(state, silent) {
2624
2671
  let pos = state.pos;
2625
2672
  if (state.src.charCodeAt(pos) !== 10) return false;
@@ -2641,7 +2688,7 @@ function newline(state, silent) {
2641
2688
  return true;
2642
2689
  }
2643
2690
  //#endregion
2644
- //#region lib/rules_inline/escape.mjs
2691
+ //#region src/rules_inline/escape.ts
2645
2692
  var ESCAPED = [];
2646
2693
  for (let i = 0; i < 256; i++) ESCAPED.push(0);
2647
2694
  "\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(ch) {
@@ -2695,7 +2742,7 @@ function escape(state, silent) {
2695
2742
  return true;
2696
2743
  }
2697
2744
  //#endregion
2698
- //#region lib/rules_inline/backticks.mjs
2745
+ //#region src/rules_inline/backticks.ts
2699
2746
  function backtick(state, silent) {
2700
2747
  let pos = state.pos;
2701
2748
  if (state.src.charCodeAt(pos) !== 96) return false;
@@ -2733,7 +2780,7 @@ function backtick(state, silent) {
2733
2780
  return true;
2734
2781
  }
2735
2782
  //#endregion
2736
- //#region lib/rules_inline/strikethrough.mjs
2783
+ //#region src/rules_inline/strikethrough.ts
2737
2784
  function strikethrough_tokenize(state, silent) {
2738
2785
  const start = state.pos;
2739
2786
  const marker = state.src.charCodeAt(start);
@@ -2803,14 +2850,18 @@ function strikethrough_postProcess(state) {
2803
2850
  const tokens_meta = state.tokens_meta;
2804
2851
  const max = state.tokens_meta.length;
2805
2852
  postProcess$1(state, state.delimiters);
2806
- for (let curr = 0; curr < max; curr++) if (tokens_meta[curr] && tokens_meta[curr].delimiters) postProcess$1(state, tokens_meta[curr].delimiters);
2853
+ for (let curr = 0; curr < max; curr++) {
2854
+ var _tokens_meta$curr;
2855
+ const delimiters = (_tokens_meta$curr = tokens_meta[curr]) === null || _tokens_meta$curr === void 0 ? void 0 : _tokens_meta$curr.delimiters;
2856
+ if (delimiters) postProcess$1(state, delimiters);
2857
+ }
2807
2858
  }
2808
2859
  var strikethrough_default = {
2809
2860
  tokenize: strikethrough_tokenize,
2810
2861
  postProcess: strikethrough_postProcess
2811
2862
  };
2812
2863
  //#endregion
2813
- //#region lib/rules_inline/emphasis.mjs
2864
+ //#region src/rules_inline/emphasis.ts
2814
2865
  function emphasis_tokenize(state, silent) {
2815
2866
  const start = state.pos;
2816
2867
  const marker = state.src.charCodeAt(start);
@@ -2864,14 +2915,18 @@ function emphasis_post_process(state) {
2864
2915
  const tokens_meta = state.tokens_meta;
2865
2916
  const max = state.tokens_meta.length;
2866
2917
  postProcess(state, state.delimiters);
2867
- for (let curr = 0; curr < max; curr++) if (tokens_meta[curr] && tokens_meta[curr].delimiters) postProcess(state, tokens_meta[curr].delimiters);
2918
+ for (let curr = 0; curr < max; curr++) {
2919
+ var _tokens_meta$curr;
2920
+ const delimiters = (_tokens_meta$curr = tokens_meta[curr]) === null || _tokens_meta$curr === void 0 ? void 0 : _tokens_meta$curr.delimiters;
2921
+ if (delimiters) postProcess(state, delimiters);
2922
+ }
2868
2923
  }
2869
2924
  var emphasis_default = {
2870
2925
  tokenize: emphasis_tokenize,
2871
2926
  postProcess: emphasis_post_process
2872
2927
  };
2873
2928
  //#endregion
2874
- //#region lib/rules_inline/link.mjs
2929
+ //#region src/rules_inline/link.ts
2875
2930
  function link(state, silent) {
2876
2931
  let code, label, res, ref;
2877
2932
  let href = "";
@@ -2926,7 +2981,8 @@ function link(state, silent) {
2926
2981
  else pos = labelEnd + 1;
2927
2982
  } else pos = labelEnd + 1;
2928
2983
  if (!label) label = state.src.slice(labelStart, labelEnd);
2929
- ref = state.env.references[normalizeReference(label)];
2984
+ label = normalizeReference(label);
2985
+ ref = state.env.references[label];
2930
2986
  if (!ref) {
2931
2987
  state.pos = oldPos;
2932
2988
  return false;
@@ -2941,6 +2997,11 @@ function link(state, silent) {
2941
2997
  const attrs = [["href", href]];
2942
2998
  token_o.attrs = attrs;
2943
2999
  if (title) attrs.push(["title", title]);
3000
+ if (label) {
3001
+ const meta = Object.create(null);
3002
+ meta.label = label;
3003
+ token_o.meta = meta;
3004
+ }
2944
3005
  state.linkLevel++;
2945
3006
  state.md.inline.tokenize(state);
2946
3007
  state.linkLevel--;
@@ -2951,7 +3012,7 @@ function link(state, silent) {
2951
3012
  return true;
2952
3013
  }
2953
3014
  //#endregion
2954
- //#region lib/rules_inline/image.mjs
3015
+ //#region src/rules_inline/image.ts
2955
3016
  function image(state, silent) {
2956
3017
  let code, content, label, pos, ref, res, title, start;
2957
3018
  let href = "";
@@ -3005,7 +3066,8 @@ function image(state, silent) {
3005
3066
  else pos = labelEnd + 1;
3006
3067
  } else pos = labelEnd + 1;
3007
3068
  if (!label) label = state.src.slice(labelStart, labelEnd);
3008
- ref = state.env.references[normalizeReference(label)];
3069
+ label = normalizeReference(label);
3070
+ ref = state.env.references[label];
3009
3071
  if (!ref) {
3010
3072
  state.pos = oldPos;
3011
3073
  return false;
@@ -3023,13 +3085,18 @@ function image(state, silent) {
3023
3085
  token.children = tokens;
3024
3086
  token.content = content;
3025
3087
  if (title) attrs.push(["title", title]);
3088
+ if (label) {
3089
+ const meta = Object.create(null);
3090
+ meta.label = label;
3091
+ token.meta = meta;
3092
+ }
3026
3093
  }
3027
3094
  state.pos = pos;
3028
3095
  state.posMax = max;
3029
3096
  return true;
3030
3097
  }
3031
3098
  //#endregion
3032
- //#region lib/rules_inline/autolink.mjs
3099
+ //#region src/rules_inline/autolink.ts
3033
3100
  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])?)*)$/;
3034
3101
  var AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/;
3035
3102
  function autolink(state, silent) {
@@ -3062,7 +3129,7 @@ function autolink(state, silent) {
3062
3129
  return true;
3063
3130
  }
3064
3131
  if (EMAIL_RE.test(url)) {
3065
- const fullUrl = state.md.normalizeLink("mailto:" + url);
3132
+ const fullUrl = state.md.normalizeLink(`mailto:${url}`);
3066
3133
  if (!state.md.validateLink(fullUrl)) return false;
3067
3134
  if (!silent) {
3068
3135
  const token_o = state.push("link_open", "a", 1);
@@ -3081,7 +3148,7 @@ function autolink(state, silent) {
3081
3148
  return false;
3082
3149
  }
3083
3150
  //#endregion
3084
- //#region lib/rules_inline/html_inline.mjs
3151
+ //#region src/rules_inline/html_inline.ts
3085
3152
  function isLinkOpen(str) {
3086
3153
  return /^<a[>\s]/i.test(str);
3087
3154
  }
@@ -3111,7 +3178,7 @@ function html_inline(state, silent) {
3111
3178
  return true;
3112
3179
  }
3113
3180
  //#endregion
3114
- //#region lib/rules_inline/entity.mjs
3181
+ //#region src/rules_inline/entity.ts
3115
3182
  var DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i;
3116
3183
  var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i;
3117
3184
  function entity(state, silent) {
@@ -3135,7 +3202,7 @@ function entity(state, silent) {
3135
3202
  } else {
3136
3203
  const match = state.src.slice(pos).match(NAMED_RE);
3137
3204
  if (match) {
3138
- const decoded = (0, entities.decodeHTMLStrict)(match[0]);
3205
+ const decoded = decodeHTMLStrict(match[0]);
3139
3206
  if (decoded !== match[0]) {
3140
3207
  if (!silent) {
3141
3208
  const token = state.push("text_special", "", 0);
@@ -3151,7 +3218,7 @@ function entity(state, silent) {
3151
3218
  return false;
3152
3219
  }
3153
3220
  //#endregion
3154
- //#region lib/rules_inline/balance_pairs.mjs
3221
+ //#region src/rules_inline/balance_pairs.ts
3155
3222
  function processDelimiters(delimiters) {
3156
3223
  const openersBottom = {};
3157
3224
  const max = delimiters.length;
@@ -3207,10 +3274,14 @@ function link_pairs(state) {
3207
3274
  const tokens_meta = state.tokens_meta;
3208
3275
  const max = state.tokens_meta.length;
3209
3276
  processDelimiters(state.delimiters);
3210
- for (let curr = 0; curr < max; curr++) if (tokens_meta[curr] && tokens_meta[curr].delimiters) processDelimiters(tokens_meta[curr].delimiters);
3277
+ for (let curr = 0; curr < max; curr++) {
3278
+ var _tokens_meta$curr;
3279
+ const delimiters = (_tokens_meta$curr = tokens_meta[curr]) === null || _tokens_meta$curr === void 0 ? void 0 : _tokens_meta$curr.delimiters;
3280
+ if (delimiters) processDelimiters(delimiters);
3281
+ }
3211
3282
  }
3212
3283
  //#endregion
3213
- //#region lib/rules_inline/fragments_join.mjs
3284
+ //#region src/rules_inline/fragments_join.ts
3214
3285
  function fragments_join(state) {
3215
3286
  let curr, last;
3216
3287
  let level = 0;
@@ -3229,12 +3300,7 @@ function fragments_join(state) {
3229
3300
  if (curr !== last) tokens.length = last;
3230
3301
  }
3231
3302
  //#endregion
3232
- //#region lib/parser_inline.mjs
3233
- /** internal
3234
- * class ParserInline
3235
- *
3236
- * Tokenizes paragraph content.
3237
- **/
3303
+ //#region src/parser_inline.ts
3238
3304
  var _rules = [
3239
3305
  ["text", text],
3240
3306
  ["linkify", linkify],
@@ -3256,87 +3322,91 @@ var _rules2 = [
3256
3322
  ["fragments_join", fragments_join]
3257
3323
  ];
3258
3324
  /**
3259
- * new ParserInline()
3260
- **/
3261
- function ParserInline() {
3262
- /**
3263
- * ParserInline#ruler -> Ruler
3264
- *
3265
- * [[Ruler]] instance. Keep configuration of inline rules.
3266
- **/
3267
- this.ruler = new Ruler();
3268
- for (let i = 0; i < _rules.length; i++) this.ruler.push(_rules[i][0], _rules[i][1]);
3269
- /**
3270
- * ParserInline#ruler2 -> Ruler
3271
- *
3272
- * [[Ruler]] instance. Second ruler used for post-processing
3273
- * (e.g. in emphasis-like rules).
3274
- **/
3275
- this.ruler2 = new Ruler();
3276
- for (let i = 0; i < _rules2.length; i++) this.ruler2.push(_rules2[i][0], _rules2[i][1]);
3277
- }
3278
- ParserInline.prototype.skipToken = function(state) {
3279
- const pos = state.pos;
3280
- const rules = this.ruler.getRules("");
3281
- const len = rules.length;
3282
- const maxNesting = state.md.options.maxNesting;
3283
- const cache = state.cache;
3284
- if (typeof cache[pos] !== "undefined") {
3285
- state.pos = cache[pos];
3286
- return;
3287
- }
3288
- let ok = false;
3289
- if (state.level < maxNesting) for (let i = 0; i < len; i++) {
3290
- state.level++;
3291
- ok = rules[i](state, true);
3292
- state.level--;
3293
- if (ok) {
3294
- if (pos >= state.pos) throw new Error("inline rule didn't increment state.pos");
3295
- break;
3325
+ * Tokenizes paragraph content.
3326
+ */
3327
+ var ParserInline = class {
3328
+ constructor() {
3329
+ _defineProperty(
3330
+ this,
3331
+ /**
3332
+ * {@link Ruler} instance. Keep configuration of inline rules.
3333
+ */
3334
+ "ruler",
3335
+ new Ruler()
3336
+ );
3337
+ _defineProperty(
3338
+ this,
3339
+ /**
3340
+ * {@link Ruler} instance. Second ruler used for post-processing
3341
+ * (e.g. in emphasis-like rules).
3342
+ */
3343
+ "ruler2",
3344
+ new Ruler()
3345
+ );
3346
+ _defineProperty(this, "State", StateInline);
3347
+ for (let i = 0; i < _rules.length; i++) this.ruler.push(_rules[i][0], _rules[i][1]);
3348
+ for (let i = 0; i < _rules2.length; i++) this.ruler2.push(_rules2[i][0], _rules2[i][1]);
3349
+ }
3350
+ skipToken(state) {
3351
+ const pos = state.pos;
3352
+ const rules = this.ruler.getRules("");
3353
+ const len = rules.length;
3354
+ const maxNesting = state.md.options.maxNesting;
3355
+ const cache = state.cache;
3356
+ if (typeof cache[pos] !== "undefined") {
3357
+ state.pos = cache[pos];
3358
+ return;
3296
3359
  }
3297
- }
3298
- else state.pos = state.posMax;
3299
- if (!ok) state.pos++;
3300
- cache[pos] = state.pos;
3301
- };
3302
- ParserInline.prototype.tokenize = function(state) {
3303
- const rules = this.ruler.getRules("");
3304
- const len = rules.length;
3305
- const end = state.posMax;
3306
- const maxNesting = state.md.options.maxNesting;
3307
- while (state.pos < end) {
3308
- const prevPos = state.pos;
3309
3360
  let ok = false;
3310
3361
  if (state.level < maxNesting) for (let i = 0; i < len; i++) {
3311
- ok = rules[i](state, false);
3362
+ state.level++;
3363
+ ok = rules[i](state, true);
3364
+ state.level--;
3312
3365
  if (ok) {
3313
- if (prevPos >= state.pos) throw new Error("inline rule didn't increment state.pos");
3366
+ if (pos >= state.pos) throw new Error("inline rule didn't increment state.pos");
3314
3367
  break;
3315
3368
  }
3316
3369
  }
3317
- if (ok) {
3318
- if (state.pos >= end) break;
3319
- continue;
3370
+ else state.pos = state.posMax;
3371
+ if (!ok) state.pos++;
3372
+ cache[pos] = state.pos;
3373
+ }
3374
+ tokenize(state) {
3375
+ const rules = this.ruler.getRules("");
3376
+ const len = rules.length;
3377
+ const end = state.posMax;
3378
+ const maxNesting = state.md.options.maxNesting;
3379
+ while (state.pos < end) {
3380
+ const prevPos = state.pos;
3381
+ let ok = false;
3382
+ if (state.level < maxNesting) for (let i = 0; i < len; i++) {
3383
+ ok = rules[i](state, false);
3384
+ if (ok) {
3385
+ if (prevPos >= state.pos) throw new Error("inline rule didn't increment state.pos");
3386
+ break;
3387
+ }
3388
+ }
3389
+ if (ok) {
3390
+ if (state.pos >= end) break;
3391
+ continue;
3392
+ }
3393
+ state.pending += state.src[state.pos++];
3320
3394
  }
3321
- state.pending += state.src[state.pos++];
3395
+ if (state.pending) state.pushPending();
3396
+ }
3397
+ /**
3398
+ * Process input string and push inline tokens into `outTokens`
3399
+ */
3400
+ parse(str, md, env, outTokens) {
3401
+ const state = new this.State(str, md, env, outTokens);
3402
+ this.tokenize(state);
3403
+ const rules = this.ruler2.getRules("");
3404
+ const len = rules.length;
3405
+ for (let i = 0; i < len; i++) rules[i](state);
3322
3406
  }
3323
- if (state.pending) state.pushPending();
3324
- };
3325
- /**
3326
- * ParserInline.parse(str, md, env, outTokens)
3327
- *
3328
- * Process input string and push inline tokens into `outTokens`
3329
- **/
3330
- ParserInline.prototype.parse = function(str, md, env, outTokens) {
3331
- const state = new this.State(str, md, env, outTokens);
3332
- this.tokenize(state);
3333
- const rules = this.ruler2.getRules("");
3334
- const len = rules.length;
3335
- for (let i = 0; i < len; i++) rules[i](state);
3336
3407
  };
3337
- ParserInline.prototype.State = StateInline;
3338
3408
  //#endregion
3339
- //#region lib/index.mjs
3409
+ //#region src/markdownit.ts
3340
3410
  var config = {
3341
3411
  default: {
3342
3412
  options: {
@@ -3372,6 +3442,7 @@ var config = {
3372
3442
  core: { rules: [
3373
3443
  "normalize",
3374
3444
  "block",
3445
+ "strip_references",
3375
3446
  "inline",
3376
3447
  "text_join"
3377
3448
  ] },
@@ -3398,6 +3469,7 @@ var config = {
3398
3469
  core: { rules: [
3399
3470
  "normalize",
3400
3471
  "block",
3472
+ "strip_references",
3401
3473
  "inline",
3402
3474
  "text_join"
3403
3475
  ] },
@@ -3437,465 +3509,364 @@ var config = {
3437
3509
  };
3438
3510
  var BAD_PROTO_RE = /^(vbscript|javascript|file|data):/;
3439
3511
  var GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/;
3440
- function validateLink(url) {
3441
- const str = url.trim().toLowerCase();
3442
- return BAD_PROTO_RE.test(str) ? GOOD_DATA_RE.test(str) : true;
3443
- }
3444
3512
  var RECODE_HOSTNAME_FOR = [
3445
3513
  "http:",
3446
3514
  "https:",
3447
3515
  "mailto:"
3448
3516
  ];
3449
- function normalizeLink(url) {
3450
- const parsed = mdurl.parse(url, true);
3451
- if (parsed.hostname) {
3452
- if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) try {
3453
- parsed.hostname = punycode_js.default.toASCII(parsed.hostname);
3454
- } catch (er) {}
3455
- }
3456
- return mdurl.encode(mdurl.format(parsed));
3457
- }
3458
- function normalizeLinkText(url) {
3459
- const parsed = mdurl.parse(url, true);
3460
- if (parsed.hostname) {
3461
- if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) try {
3462
- parsed.hostname = punycode_js.default.toUnicode(parsed.hostname);
3463
- } catch (er) {}
3464
- }
3465
- return mdurl.decode(mdurl.format(parsed), mdurl.decode.defaultChars + "%");
3466
- }
3467
- /**
3468
- * class MarkdownIt
3469
- *
3470
- * Main parser/renderer class.
3471
- *
3472
- * ##### Usage
3473
- *
3474
- * ```javascript
3475
- * // node.js, "classic" way:
3476
- * var MarkdownIt = require('markdown-it'),
3477
- * md = new MarkdownIt();
3478
- * var result = md.render('# markdown-it rulezz!');
3479
- *
3480
- * // node.js, the same, but with sugar:
3481
- * var md = require('markdown-it')();
3482
- * var result = md.render('# markdown-it rulezz!');
3483
- *
3484
- * // browser without AMD, added to "window" on script load
3485
- * // Note, there are no dash.
3486
- * var md = window.markdownit();
3487
- * var result = md.render('# markdown-it rulezz!');
3488
- * ```
3489
- *
3490
- * Single line rendering, without paragraph wrap:
3491
- *
3492
- * ```javascript
3493
- * var md = require('markdown-it')();
3494
- * var result = md.renderInline('__markdown-it__ rulezz!');
3495
- * ```
3496
- **/
3497
3517
  /**
3498
- * new MarkdownIt([presetName, options])
3499
- * - presetName (String): optional, `commonmark` / `zero`
3500
- * - options (Object)
3501
- *
3502
- * Creates parser instanse with given config. Can be called without `new`.
3503
- *
3504
- * ##### presetName
3505
- *
3506
- * MarkdownIt provides named presets as a convenience to quickly
3507
- * enable/disable active syntax rules and options for common use cases.
3508
- *
3509
- * - ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.mjs) -
3510
- * configures parser to strict [CommonMark](http://commonmark.org/) mode.
3511
- * - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.mjs) -
3512
- * similar to GFM, used when no preset name given. Enables all available rules,
3513
- * but still without html, typographer & autolinker.
3514
- * - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.mjs) -
3515
- * all rules disabled. Useful to quickly setup your config via `.enable()`.
3516
- * For example, when you need only `bold` and `italic` markup and nothing else.
3517
- *
3518
- * ##### options:
3519
- *
3520
- * - __html__ - `false`. Set `true` to enable HTML tags in source. Be careful!
3521
- * That's not safe! You may need external sanitizer to protect output from XSS.
3522
- * It's better to extend features via plugins, instead of enabling HTML.
3523
- * - __xhtmlOut__ - `false`. Set `true` to add '/' when closing single tags
3524
- * (`<br />`). This is needed only for full CommonMark compatibility. In real
3525
- * world you will need HTML output.
3526
- * - __breaks__ - `false`. Set `true` to convert `\n` in paragraphs into `<br>`.
3527
- * - __langPrefix__ - `language-`. CSS language class prefix for fenced blocks.
3528
- * Can be useful for external highlighters.
3529
- * - __linkify__ - `false`. Set `true` to autoconvert URL-like text to links.
3530
- * - __typographer__ - `false`. Set `true` to enable [some language-neutral
3531
- * replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.mjs) +
3532
- * quotes beautification (smartquotes).
3533
- * - __quotes__ - `“”‘’`, String or Array. Double + single quotes replacement
3534
- * pairs, when typographer enabled and smartquotes on. For example, you can
3535
- * use `'«»„“'` for Russian, `'„“‚‘'` for German, and
3536
- * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp).
3537
- * - __highlight__ - `null`. Highlighter function for fenced code blocks.
3538
- * Highlighter `function (str, lang)` should return escaped HTML. It can also
3539
- * return empty string if the source was not changed and should be escaped
3540
- * externaly. If result starts with <pre... internal wrapper is skipped.
3541
- *
3542
- * ##### Example
3543
- *
3544
- * ```javascript
3545
- * // commonmark mode
3546
- * var md = require('markdown-it')('commonmark');
3547
- *
3548
- * // default mode
3549
- * var md = require('markdown-it')();
3550
- *
3551
- * // enable everything
3552
- * var md = require('markdown-it')({
3553
- * html: true,
3554
- * linkify: true,
3555
- * typographer: true
3556
- * });
3557
- * ```
3558
- *
3559
- * ##### Syntax highlighting
3560
- *
3561
- * ```js
3562
- * var hljs = require('highlight.js') // https://highlightjs.org/
3563
- *
3564
- * var md = require('markdown-it')({
3565
- * highlight: function (str, lang) {
3566
- * if (lang && hljs.getLanguage(lang)) {
3567
- * try {
3568
- * return hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
3569
- * } catch (__) {}
3570
- * }
3518
+ * Parses Markdown into tokens and renders them to HTML.
3571
3519
  *
3572
- * return ''; // use external default escaping
3573
- * }
3574
- * });
3575
- * ```
3576
- *
3577
- * Or with full wrapper override (if you need assign class to `<pre>` or `<code>`):
3578
- *
3579
- * ```javascript
3580
- * var hljs = require('highlight.js') // https://highlightjs.org/
3581
- *
3582
- * // Actual default values
3583
- * var md = require('markdown-it')({
3584
- * highlight: function (str, lang) {
3585
- * if (lang && hljs.getLanguage(lang)) {
3586
- * try {
3587
- * return '<pre><code class="hljs">' +
3588
- * hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
3589
- * '</code></pre>';
3590
- * } catch (__) {}
3591
- * }
3592
- *
3593
- * return '<pre><code class="hljs">' + md.utils.escapeHtml(str) + '</code></pre>';
3594
- * }
3595
- * });
3596
- * ```
3597
- *
3598
- **/
3599
- function MarkdownIt(presetName, options) {
3600
- if (!(this instanceof MarkdownIt)) return new MarkdownIt(presetName, options);
3601
- if (!options) {
3602
- if (!isString(presetName)) {
3603
- options = presetName || {};
3604
- presetName = "default";
3520
+ * @category Main
3521
+ */
3522
+ var MarkdownIt = class {
3523
+ /**
3524
+ * Link validation function. CommonMark allows too much in links. By default
3525
+ * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas
3526
+ * except some embedded image types.
3527
+ *
3528
+ * You can change this behaviour:
3529
+ *
3530
+ * @example
3531
+ * ```javascript
3532
+ * import MarkdownIt from 'markdown-it'
3533
+ * const md = new MarkdownIt()
3534
+ *
3535
+ * // enable everything
3536
+ * md.validateLink = function () { return true; }
3537
+ * ```
3538
+ */
3539
+ validateLink(url) {
3540
+ const str = url.trim().toLowerCase();
3541
+ return BAD_PROTO_RE.test(str) ? GOOD_DATA_RE.test(str) : true;
3542
+ }
3543
+ /**
3544
+ * Function used to encode link url to a machine-readable format,
3545
+ * which includes url-encoding, punycode, etc.
3546
+ */
3547
+ normalizeLink(url) {
3548
+ const parsed = mdurl.parse(url, true);
3549
+ if (parsed.hostname) {
3550
+ if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) try {
3551
+ parsed.hostname = punycode.toASCII(parsed.hostname);
3552
+ } catch (er) {}
3605
3553
  }
3554
+ return mdurl.encode(mdurl.format(parsed));
3606
3555
  }
3607
3556
  /**
3608
- * MarkdownIt#inline -> ParserInline
3609
- *
3610
- * Instance of [[ParserInline]]. You may need it to add new rules when
3611
- * writing plugins. For simple rules control use [[MarkdownIt.disable]] and
3612
- * [[MarkdownIt.enable]].
3613
- **/
3614
- this.inline = new ParserInline();
3557
+ * Function used to decode link url to a human-readable format`
3558
+ */
3559
+ normalizeLinkText(url) {
3560
+ const parsed = mdurl.parse(url, true);
3561
+ if (parsed.hostname) {
3562
+ if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) try {
3563
+ parsed.hostname = punycode.toUnicode(parsed.hostname);
3564
+ } catch (er) {}
3565
+ }
3566
+ return mdurl.decode(mdurl.format(parsed), mdurl.decode.defaultChars + "%");
3567
+ }
3568
+ constructor(...args) {
3569
+ _defineProperty(
3570
+ this,
3571
+ /**
3572
+ * Instance of {@link ParserInline}. You may need it to add new rules when
3573
+ * writing plugins. For simple rules control use {@link MarkdownIt.disable}
3574
+ * and {@link MarkdownIt.enable}.
3575
+ */
3576
+ "inline",
3577
+ new ParserInline()
3578
+ );
3579
+ _defineProperty(
3580
+ this,
3581
+ /**
3582
+ * Instance of {@link ParserBlock}. You may need it to add new rules when
3583
+ * writing plugins. For simple rules control use {@link MarkdownIt.disable}
3584
+ * and {@link MarkdownIt.enable}.
3585
+ */
3586
+ "block",
3587
+ new ParserBlock()
3588
+ );
3589
+ _defineProperty(
3590
+ this,
3591
+ /**
3592
+ * Instance of {@link ParserCore} chain executor. You may need it to add new
3593
+ * rules when writing plugins. For simple rules control use
3594
+ * {@link MarkdownIt.disable} and {@link MarkdownIt.enable}.
3595
+ */
3596
+ "core",
3597
+ new ParserCore()
3598
+ );
3599
+ _defineProperty(
3600
+ this,
3601
+ /**
3602
+ * Instance of {@link Renderer}. Use it to modify output look. Or to add rendering
3603
+ * rules for new token types, generated by plugins.
3604
+ *
3605
+ * See {@link Renderer} docs and
3606
+ * [source code](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts).
3607
+ *
3608
+ * @example
3609
+ * ```javascript
3610
+ * import MarkdownIt from 'markdown-it'
3611
+ * const md = new MarkdownIt()
3612
+ *
3613
+ * function myToken(tokens, idx, options, env, self) {
3614
+ * //...
3615
+ * return result;
3616
+ * };
3617
+ *
3618
+ * md.renderer.rules['my_token'] = myToken
3619
+ * ```
3620
+ */
3621
+ "renderer",
3622
+ new Renderer()
3623
+ );
3624
+ _defineProperty(
3625
+ this,
3626
+ /**
3627
+ * [linkify-it](https://github.com/markdown-it/linkify-it) instance.
3628
+ * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/src/rules_core/linkify.ts)
3629
+ * rule.
3630
+ */
3631
+ "linkify",
3632
+ new LinkifyIt()
3633
+ );
3634
+ _defineProperty(
3635
+ this,
3636
+ /**
3637
+ * Assorted utility functions, useful to write plugins. See details
3638
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/src/common/utils.ts).
3639
+ */
3640
+ "utils",
3641
+ utils_exports
3642
+ );
3643
+ _defineProperty(
3644
+ this,
3645
+ /**
3646
+ * Link components parser functions, useful to write plugins. See details
3647
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/src/helpers).
3648
+ */
3649
+ "helpers",
3650
+ Object.assign({}, helpers_exports)
3651
+ );
3652
+ const [presetNameOrOptions, options] = args;
3653
+ if (typeof presetNameOrOptions === "string") {
3654
+ this.configure(presetNameOrOptions);
3655
+ if (options) this.set(options);
3656
+ } else {
3657
+ this.configure("default");
3658
+ this.set(presetNameOrOptions || {});
3659
+ }
3660
+ }
3615
3661
  /**
3616
- * MarkdownIt#block -> ParserBlock
3662
+ * Set parser options (in the same format as in constructor). Probably, you
3663
+ * will never need it, but you can change options after constructor call.
3617
3664
  *
3618
- * Instance of [[ParserBlock]]. You may need it to add new rules when
3619
- * writing plugins. For simple rules control use [[MarkdownIt.disable]] and
3620
- * [[MarkdownIt.enable]].
3621
- **/
3622
- this.block = new ParserBlock();
3623
- /**
3624
- * MarkdownIt#core -> Core
3665
+ * __Note:__ To achieve the best possible performance, don't modify a
3666
+ * `markdown-it` instance options on the fly. If you need multiple configurations
3667
+ * it's best to create multiple instances and initialize each with separate
3668
+ * config.
3669
+ *
3670
+ * @example
3671
+ * ```javascript
3672
+ * import MarkdownIt from 'markdown-it'
3625
3673
  *
3626
- * Instance of [[Core]] chain executor. You may need it to add new rules when
3627
- * writing plugins. For simple rules control use [[MarkdownIt.disable]] and
3628
- * [[MarkdownIt.enable]].
3629
- **/
3630
- this.core = new Core();
3674
+ * const md = new MarkdownIt()
3675
+ * .set({ html: true, breaks: true })
3676
+ * .set({ typographer: true })
3677
+ * ```
3678
+ */
3679
+ set(options) {
3680
+ Object.assign(this.options, options);
3681
+ return this;
3682
+ }
3631
3683
  /**
3632
- * MarkdownIt#renderer -> Renderer
3684
+ * Batch load of all options and compenent settings. This is internal method,
3685
+ * and you probably will not need it. But if you will - see available presets
3686
+ * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/src/presets)
3633
3687
  *
3634
- * Instance of [[Renderer]]. Use it to modify output look. Or to add rendering
3635
- * rules for new token types, generated by plugins.
3688
+ * We strongly recommend to use presets instead of direct config loads. That
3689
+ * will give better compatibility with next versions.
3690
+ */
3691
+ configure(presets) {
3692
+ let p;
3693
+ if (typeof presets === "string") {
3694
+ const presetName = presets;
3695
+ p = config[presetName];
3696
+ if (!p) throw new Error(`Wrong 'markdown-it' preset "${presetName}", check name`);
3697
+ } else p = presets;
3698
+ if (!p) throw new Error("Wrong `markdown-it` preset, can't be empty");
3699
+ if (p.options) this.options = { ...p.options };
3700
+ const components = p.components;
3701
+ if (components) {
3702
+ var _components$inline;
3703
+ [
3704
+ "core",
3705
+ "block",
3706
+ "inline"
3707
+ ].forEach((name) => {
3708
+ var _components$name;
3709
+ const rules = (_components$name = components[name]) === null || _components$name === void 0 ? void 0 : _components$name.rules;
3710
+ if (rules) this[name].ruler.enableOnly(rules);
3711
+ });
3712
+ const rules2 = (_components$inline = components.inline) === null || _components$inline === void 0 ? void 0 : _components$inline.rules2;
3713
+ if (rules2) this.inline.ruler2.enableOnly(rules2);
3714
+ }
3715
+ return this;
3716
+ }
3717
+ /**
3718
+ * Enable list or rules. It will automatically find appropriate components,
3719
+ * containing rules with given names. If rule not found, and `ignoreInvalid`
3720
+ * not set - throws exception.
3636
3721
  *
3637
- * ##### Example
3722
+ * @param list Rule name or list of rule names to enable.
3723
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
3638
3724
  *
3725
+ * @example
3639
3726
  * ```javascript
3640
- * var md = require('markdown-it')();
3727
+ * import MarkdownIt from 'markdown-it'
3641
3728
  *
3642
- * function myToken(tokens, idx, options, env, self) {
3643
- * //...
3644
- * return result;
3645
- * };
3646
- *
3647
- * md.renderer.rules['my_token'] = myToken
3729
+ * const md = new MarkdownIt()
3730
+ * .enable(['sub', 'sup'])
3731
+ * .disable('smartquotes')
3648
3732
  * ```
3649
- *
3650
- * See [[Renderer]] docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs).
3651
- **/
3652
- this.renderer = new Renderer();
3733
+ */
3734
+ enable(list, ignoreInvalid = false) {
3735
+ let result = [];
3736
+ if (!Array.isArray(list)) list = [list];
3737
+ [
3738
+ "core",
3739
+ "block",
3740
+ "inline"
3741
+ ].forEach((chain) => {
3742
+ result = result.concat(this[chain].ruler.enable(list, true));
3743
+ });
3744
+ result = result.concat(this.inline.ruler2.enable(list, true));
3745
+ const missed = list.filter((name) => result.indexOf(name) < 0);
3746
+ if (missed.length && !ignoreInvalid) throw new Error(`MarkdownIt. Failed to enable unknown rule(s): ${missed}`);
3747
+ return this;
3748
+ }
3653
3749
  /**
3654
- * MarkdownIt#linkify -> LinkifyIt
3750
+ * The same as {@link MarkdownIt.enable}, but turn specified rules off.
3655
3751
  *
3656
- * [linkify-it](https://github.com/markdown-it/linkify-it) instance.
3657
- * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.mjs)
3658
- * rule.
3659
- **/
3660
- this.linkify = new linkify_it.default();
3752
+ * @param list Rule name or list of rule names to disable.
3753
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
3754
+ */
3755
+ disable(list, ignoreInvalid = false) {
3756
+ let result = [];
3757
+ if (!Array.isArray(list)) list = [list];
3758
+ [
3759
+ "core",
3760
+ "block",
3761
+ "inline"
3762
+ ].forEach((chain) => {
3763
+ result = result.concat(this[chain].ruler.disable(list, true));
3764
+ });
3765
+ result = result.concat(this.inline.ruler2.disable(list, true));
3766
+ const missed = list.filter((name) => result.indexOf(name) < 0);
3767
+ if (missed.length && !ignoreInvalid) throw new Error(`MarkdownIt. Failed to disable unknown rule(s): ${missed}`);
3768
+ return this;
3769
+ }
3661
3770
  /**
3662
- * MarkdownIt#validateLink(url) -> Boolean
3663
- *
3664
- * Link validation function. CommonMark allows too much in links. By default
3665
- * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas
3666
- * except some embedded image types.
3667
- *
3668
- * You can change this behaviour:
3771
+ * Load specified plugin with given params into current parser instance.
3772
+ * It's just a sugar to call `plugin(md, params)` with curring.
3669
3773
  *
3774
+ * @example
3670
3775
  * ```javascript
3671
- * var md = require('markdown-it')();
3672
- * // enable everything
3673
- * md.validateLink = function () { return true; }
3776
+ * import MarkdownIt from 'markdown-it'
3777
+ * import iterator from 'markdown-it-for-inline'
3778
+ *
3779
+ * const md = new MarkdownIt()
3780
+ * .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
3781
+ * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar')
3782
+ * })
3674
3783
  * ```
3675
- **/
3676
- this.validateLink = validateLink;
3784
+ */
3785
+ use(plugin, ...params) {
3786
+ plugin.apply(plugin, [this, ...params]);
3787
+ return this;
3788
+ }
3677
3789
  /**
3678
- * MarkdownIt#normalizeLink(url) -> String
3790
+ * Parse input string and return list of block tokens (special token type
3791
+ * "inline" will contain list of inline tokens). You should not call this
3792
+ * method directly, until you write custom renderer (for example, to produce
3793
+ * AST).
3679
3794
  *
3680
- * Function used to encode link url to a machine-readable format,
3681
- * which includes url-encoding, punycode, etc.
3682
- **/
3683
- this.normalizeLink = normalizeLink;
3795
+ * `env` is used to pass data between "distributed" rules and return additional
3796
+ * metadata like reference info, needed for the renderer. It also can be used to
3797
+ * inject data in specific cases. Usually, you will be ok to pass `{}`,
3798
+ * and then pass updated object to renderer.
3799
+ *
3800
+ * @param src Source string.
3801
+ * @param env Environment sandbox.
3802
+ */
3803
+ parse(src, env) {
3804
+ if (typeof src !== "string") throw new Error("Input data should be a String");
3805
+ const state = new this.core.State(src, this, env);
3806
+ this.core.process(state);
3807
+ return state.tokens;
3808
+ }
3684
3809
  /**
3685
- * MarkdownIt#normalizeLinkText(url) -> String
3810
+ * Render markdown string into html. It does all magic for you :).
3686
3811
  *
3687
- * Function used to decode link url to a human-readable format`
3688
- **/
3689
- this.normalizeLinkText = normalizeLinkText;
3812
+ * `env` can be used to inject additional metadata (`{}` by default).
3813
+ * But you will not need it with high probability. See also comment
3814
+ * in {@link MarkdownIt.parse}.
3815
+ *
3816
+ * @param src Source string.
3817
+ * @param env Environment sandbox.
3818
+ */
3819
+ render(src, env = {}) {
3820
+ return this.renderer.render(this.parse(src, env), this.options, env);
3821
+ }
3690
3822
  /**
3691
- * MarkdownIt#utils -> utils
3823
+ * The same as {@link MarkdownIt.parse} but skip all block rules. It returns
3824
+ * the block tokens list with the single `inline` element, containing parsed
3825
+ * inline tokens in `children` property. Also updates `env` object.
3692
3826
  *
3693
- * Assorted utility functions, useful to write plugins. See details
3694
- * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.mjs).
3695
- **/
3696
- this.utils = utils_exports;
3827
+ * @param src Source string.
3828
+ * @param env Environment sandbox.
3829
+ */
3830
+ parseInline(src, env) {
3831
+ const state = new this.core.State(src, this, env);
3832
+ state.inlineMode = true;
3833
+ this.core.process(state);
3834
+ return state.tokens;
3835
+ }
3697
3836
  /**
3698
- * MarkdownIt#helpers -> helpers
3837
+ * Similar to {@link MarkdownIt.render} but for single paragraph content.
3838
+ * Result will NOT be wrapped into `<p>` tags.
3699
3839
  *
3700
- * Link components parser functions, useful to write plugins. See details
3701
- * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/helpers).
3702
- **/
3703
- this.helpers = assign({}, helpers_exports);
3704
- this.options = {};
3705
- this.configure(presetName);
3706
- if (options) this.set(options);
3707
- }
3708
- /** chainable
3709
- * MarkdownIt.set(options)
3710
- *
3711
- * Set parser options (in the same format as in constructor). Probably, you
3712
- * will never need it, but you can change options after constructor call.
3713
- *
3714
- * ##### Example
3715
- *
3716
- * ```javascript
3717
- * var md = require('markdown-it')()
3718
- * .set({ html: true, breaks: true })
3719
- * .set({ typographer: true });
3720
- * ```
3721
- *
3722
- * __Note:__ To achieve the best possible performance, don't modify a
3723
- * `markdown-it` instance options on the fly. If you need multiple configurations
3724
- * it's best to create multiple instances and initialize each with separate
3725
- * config.
3726
- **/
3727
- MarkdownIt.prototype.set = function(options) {
3728
- assign(this.options, options);
3729
- return this;
3730
- };
3731
- /** chainable, internal
3732
- * MarkdownIt.configure(presets)
3733
- *
3734
- * Batch load of all options and compenent settings. This is internal method,
3735
- * and you probably will not need it. But if you will - see available presets
3736
- * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)
3737
- *
3738
- * We strongly recommend to use presets instead of direct config loads. That
3739
- * will give better compatibility with next versions.
3740
- **/
3741
- MarkdownIt.prototype.configure = function(presets) {
3742
- const self = this;
3743
- if (isString(presets)) {
3744
- const presetName = presets;
3745
- presets = config[presetName];
3746
- if (!presets) throw new Error("Wrong `markdown-it` preset \"" + presetName + "\", check name");
3747
- }
3748
- if (!presets) throw new Error("Wrong `markdown-it` preset, can't be empty");
3749
- if (presets.options) self.set(presets.options);
3750
- if (presets.components) Object.keys(presets.components).forEach(function(name) {
3751
- if (presets.components[name].rules) self[name].ruler.enableOnly(presets.components[name].rules);
3752
- if (presets.components[name].rules2) self[name].ruler2.enableOnly(presets.components[name].rules2);
3753
- });
3754
- return this;
3755
- };
3756
- /** chainable
3757
- * MarkdownIt.enable(list, ignoreInvalid)
3758
- * - list (String|Array): rule name or list of rule names to enable
3759
- * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
3760
- *
3761
- * Enable list or rules. It will automatically find appropriate components,
3762
- * containing rules with given names. If rule not found, and `ignoreInvalid`
3763
- * not set - throws exception.
3764
- *
3765
- * ##### Example
3766
- *
3767
- * ```javascript
3768
- * var md = require('markdown-it')()
3769
- * .enable(['sub', 'sup'])
3770
- * .disable('smartquotes');
3771
- * ```
3772
- **/
3773
- MarkdownIt.prototype.enable = function(list, ignoreInvalid) {
3774
- let result = [];
3775
- if (!Array.isArray(list)) list = [list];
3776
- [
3777
- "core",
3778
- "block",
3779
- "inline"
3780
- ].forEach(function(chain) {
3781
- result = result.concat(this[chain].ruler.enable(list, true));
3782
- }, this);
3783
- result = result.concat(this.inline.ruler2.enable(list, true));
3784
- const missed = list.filter(function(name) {
3785
- return result.indexOf(name) < 0;
3786
- });
3787
- if (missed.length && !ignoreInvalid) throw new Error("MarkdownIt. Failed to enable unknown rule(s): " + missed);
3788
- return this;
3789
- };
3790
- /** chainable
3791
- * MarkdownIt.disable(list, ignoreInvalid)
3792
- * - list (String|Array): rule name or list of rule names to disable.
3793
- * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found.
3794
- *
3795
- * The same as [[MarkdownIt.enable]], but turn specified rules off.
3796
- **/
3797
- MarkdownIt.prototype.disable = function(list, ignoreInvalid) {
3798
- let result = [];
3799
- if (!Array.isArray(list)) list = [list];
3800
- [
3801
- "core",
3802
- "block",
3803
- "inline"
3804
- ].forEach(function(chain) {
3805
- result = result.concat(this[chain].ruler.disable(list, true));
3806
- }, this);
3807
- result = result.concat(this.inline.ruler2.disable(list, true));
3808
- const missed = list.filter(function(name) {
3809
- return result.indexOf(name) < 0;
3810
- });
3811
- if (missed.length && !ignoreInvalid) throw new Error("MarkdownIt. Failed to disable unknown rule(s): " + missed);
3812
- return this;
3813
- };
3814
- /** chainable
3815
- * MarkdownIt.use(plugin, params)
3816
- *
3817
- * Load specified plugin with given params into current parser instance.
3818
- * It's just a sugar to call `plugin(md, params)` with curring.
3819
- *
3820
- * ##### Example
3821
- *
3822
- * ```javascript
3823
- * var iterator = require('markdown-it-for-inline');
3824
- * var md = require('markdown-it')()
3825
- * .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
3826
- * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
3827
- * });
3828
- * ```
3829
- **/
3830
- MarkdownIt.prototype.use = function(plugin) {
3831
- const args = [this].concat(Array.prototype.slice.call(arguments, 1));
3832
- plugin.apply(plugin, args);
3833
- return this;
3834
- };
3835
- /** internal
3836
- * MarkdownIt.parse(src, env) -> Array
3837
- * - src (String): source string
3838
- * - env (Object): environment sandbox
3839
- *
3840
- * Parse input string and return list of block tokens (special token type
3841
- * "inline" will contain list of inline tokens). You should not call this
3842
- * method directly, until you write custom renderer (for example, to produce
3843
- * AST).
3844
- *
3845
- * `env` is used to pass data between "distributed" rules and return additional
3846
- * metadata like reference info, needed for the renderer. It also can be used to
3847
- * inject data in specific cases. Usually, you will be ok to pass `{}`,
3848
- * and then pass updated object to renderer.
3849
- **/
3850
- MarkdownIt.prototype.parse = function(src, env) {
3851
- if (typeof src !== "string") throw new Error("Input data should be a String");
3852
- const state = new this.core.State(src, this, env);
3853
- this.core.process(state);
3854
- return state.tokens;
3840
+ * @param src Source string.
3841
+ * @param env Environment sandbox.
3842
+ */
3843
+ renderInline(src, env = {}) {
3844
+ return this.renderer.render(this.parseInline(src, env), this.options, env);
3845
+ }
3855
3846
  };
3847
+ _defineProperty(MarkdownIt, "Token", Token);
3848
+ _defineProperty(MarkdownIt, "Ruler", Ruler);
3849
+ _defineProperty(MarkdownIt, "Renderer", Renderer);
3850
+ _defineProperty(MarkdownIt, "ParserCore", ParserCore);
3851
+ _defineProperty(MarkdownIt, "StateCore", StateCore);
3852
+ _defineProperty(MarkdownIt, "ParserBlock", ParserBlock);
3853
+ _defineProperty(MarkdownIt, "StateBlock", StateBlock);
3854
+ _defineProperty(MarkdownIt, "ParserInline", ParserInline);
3855
+ _defineProperty(MarkdownIt, "StateInline", StateInline);
3856
+ //#endregion
3857
+ //#region src/index.ts
3856
3858
  /**
3857
- * MarkdownIt.render(src [, env]) -> String
3858
- * - src (String): source string
3859
- * - env (Object): environment sandbox
3860
- *
3861
- * Render markdown string into html. It does all magic for you :).
3862
- *
3863
- * `env` can be used to inject additional metadata (`{}` by default).
3864
- * But you will not need it with high probability. See also comment
3865
- * in [[MarkdownIt.parse]].
3866
- **/
3867
- MarkdownIt.prototype.render = function(src, env) {
3868
- env = env || {};
3869
- return this.renderer.render(this.parse(src, env), this.options, env);
3870
- };
3871
- /** internal
3872
- * MarkdownIt.parseInline(src, env) -> Array
3873
- * - src (String): source string
3874
- * - env (Object): environment sandbox
3859
+ * Default package export.
3875
3860
  *
3876
- * The same as [[MarkdownIt.parse]] but skip all block rules. It returns the
3877
- * block tokens list with the single `inline` element, containing parsed inline
3878
- * tokens in `children` property. Also updates `env` object.
3879
- **/
3880
- MarkdownIt.prototype.parseInline = function(src, env) {
3881
- const state = new this.core.State(src, this, env);
3882
- state.inlineMode = true;
3883
- this.core.process(state);
3884
- return state.tokens;
3885
- };
3886
- /**
3887
- * MarkdownIt.renderInline(src [, env]) -> String
3888
- * - src (String): source string
3889
- * - env (Object): environment sandbox
3861
+ * For backward compatibility, the {@link MarkdownIt} class is wrapped so
3862
+ * legacy code can call it without `new`. New code should instantiate it as a
3863
+ * regular class with `new`. The compatibility wrapper may be removed in a
3864
+ * future release.
3890
3865
  *
3891
- * Similar to [[MarkdownIt.render]] but for single paragraph content. Result
3892
- * will NOT be wrapped into `<p>` tags.
3893
- **/
3894
- MarkdownIt.prototype.renderInline = function(src, env) {
3895
- env = env || {};
3896
- return this.renderer.render(this.parseInline(src, env), this.options, env);
3897
- };
3866
+ * @category Main
3867
+ */
3868
+ var MarkdownItCallable = callable(MarkdownIt);
3898
3869
  //#endregion
3899
- module.exports = MarkdownIt;
3870
+ export { MarkdownItCallable as default };
3900
3871
 
3901
- //# sourceMappingURL=index.cjs.js.map
3872
+ //# sourceMappingURL=markdown-it.mjs.map