@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
@@ -0,0 +1,979 @@
1
+ import * as mdurl from "mdurl";
2
+ import * as ucmicro from "uc.micro";
3
+ import { LinkifyIt } from "linkify-it";
4
+ //#endregion
5
+ //#region src/types.d.ts
6
+ /** @inline */
7
+ interface Reference {
8
+ title: string;
9
+ href: string;
10
+ }
11
+ /**
12
+ * Shared environment passed through parsing and rendering.
13
+ *
14
+ * Plugins may use it to store arbitrary data.
15
+ */
16
+ interface Env {
17
+ [key: string | symbol]: unknown;
18
+ references?: Record<string, Reference>;
19
+ }
20
+ /** Delimiter entry used by emphasis-like inline rules. */
21
+ interface Delimiter {
22
+ /** Char code of the starting marker. */
23
+ marker: number;
24
+ /** Total length of this series of delimiters. */
25
+ length?: number;
26
+ /** A position of the token this delimiter corresponds to. */
27
+ token: number;
28
+ /**
29
+ * If this delimiter is matched as a valid opener, `end` will be
30
+ * equal to its position, otherwise it's `-1`.
31
+ */
32
+ end: number;
33
+ /** Whether this delimiter can open an emphasis. */
34
+ open: boolean;
35
+ /** Whether this delimiter can close an emphasis. */
36
+ close: boolean;
37
+ /** One delimiter represents two characters. */
38
+ jump?: number;
39
+ }
40
+ /**
41
+ * Options controlling Markdown parsing and rendering.
42
+ *
43
+ * @category Main
44
+ */
45
+ interface MarkdownItOptions {
46
+ /** Enable HTML tags in source. */
47
+ html?: boolean;
48
+ /** Use '/' to close single tags (`<br />`). */
49
+ xhtmlOut?: boolean;
50
+ /** Convert '\n' in paragraphs into `<br>`. */
51
+ breaks?: boolean;
52
+ /** CSS language prefix for fenced blocks, used by external syntax highlighters. */
53
+ langPrefix?: string;
54
+ /** Autoconvert URL-like text to links. */
55
+ linkify?: boolean;
56
+ /**
57
+ * Enable language-neutral replacements and quotes beautification.
58
+ *
59
+ * See the [replacement rules](https://github.com/markdown-it/markdown-it/blob/master/src/rules_core/replacements.ts)
60
+ * for the full list.
61
+ */
62
+ typographer?: boolean;
63
+ /**
64
+ * Double + single quotes replacement pairs, when typographer is enabled
65
+ * and smartquotes are on. Can be either a string or an array.
66
+ *
67
+ * For example, use `'«»„“'` for Russian, `'„“‚‘'` for German, and
68
+ * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp).
69
+ */
70
+ quotes?: string | string[];
71
+ /**
72
+ * Highlighter function. Should return escaped HTML, or an empty string if
73
+ * the source string was not changed and should be escaped externally.
74
+ * If the result starts with `<pre`, the internal wrapper is skipped.
75
+ *
76
+ * The highlighter is called by the default `fence` renderer rule. If needed,
77
+ * you can replace that renderer rule completely; see the
78
+ * [renderer source](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts).
79
+ *
80
+ * @example
81
+ * ```js
82
+ * import MarkdownIt from 'markdown-it'
83
+ * import hljs from 'highlight.js' // https://highlightjs.org
84
+ *
85
+ * const md = new MarkdownIt({
86
+ * highlight: function (str, lang) {
87
+ * if (lang && hljs.getLanguage(lang)) {
88
+ * try {
89
+ * return hljs.highlight(str, { language: lang }).value
90
+ * } catch (__) {}
91
+ * }
92
+ *
93
+ * return '' // use external default escaping
94
+ * }
95
+ * });
96
+ * ```
97
+ *
98
+ * @example
99
+ * Or with full wrapper override (if you need assign class to `<pre>` or `<code>`):
100
+ * ```js
101
+ * import MarkdownIt from 'markdown-it'
102
+ * import hljs from 'highlight.js' // https://highlightjs.org
103
+ *
104
+ * const md = new MarkdownIt({
105
+ * highlight: function (str, lang) {
106
+ * if (lang && hljs.getLanguage(lang)) {
107
+ * try {
108
+ * return `<pre><code class="hljs">${hljs.highlight(str,
109
+ * { language: lang, ignoreIllegals: true }).value}</code></pre>`
110
+ * } catch (__) {}
111
+ * }
112
+ *
113
+ * return `<pre><code class="hljs">${md.utils.escapeHtml(str)}</code></pre>`
114
+ * }
115
+ * });
116
+ * ```
117
+ */
118
+ highlight?: ((str: string, lang: string, attrs: string) => string) | null;
119
+ /** Internal protection against excessive recursion. */
120
+ maxNesting?: number;
121
+ }
122
+ declare namespace utils_d_exports {
123
+ export { arrayReplaceAt, asciiTrim, callable, escapeHtml, escapeRE, fromCodePoint, isMdAsciiPunct, isPunctChar, isPunctCharCode, isSpace, isValidEntityCode, isWhiteSpace, lib, normalizeReference, unescapeAll, unescapeMd };
124
+ }
125
+ /** @hidden */
126
+ type ClassToWrap = new (...args: any[]) => object;
127
+ /** Wraps a class so it can be called with or without `new`. */
128
+ declare function callable<T extends ClassToWrap>(cls: T): T & ((...args: ConstructorParameters<T>) => InstanceType<T>);
129
+ /**
130
+ * Returns a copy of a token array with the token at `pos` replaced by
131
+ * `newElements`. Used to transform token streams without modifying the
132
+ * original array.
133
+ */
134
+ declare function arrayReplaceAt<T>(src: T[], pos: number, newElements: T[]): T[];
135
+ /** Checks whether a code point can be decoded from a numeric HTML entity. */
136
+ declare function isValidEntityCode(c: number): boolean;
137
+ /**
138
+ * Converts a Unicode code point to a string, like `String.fromCodePoint()`,
139
+ * but does not throw for invalid input.
140
+ */
141
+ declare function fromCodePoint(c: number): string;
142
+ /** Decodes Markdown backslash escapes. */
143
+ declare function unescapeMd(str: string): string;
144
+ /**
145
+ * Decodes Markdown backslash escapes and HTML character references in link
146
+ * destinations, link titles, and fenced code info strings.
147
+ */
148
+ declare function unescapeAll(str: string): string;
149
+ /** Escapes HTML special characters in a string. */
150
+ declare function escapeHtml(str: string): string;
151
+ /** Escapes regular expression metacharacters in a string. */
152
+ declare function escapeRE(str: string): string;
153
+ /** Checks whether a character code is an ASCII space or tab. */
154
+ declare function isSpace(code: number): boolean;
155
+ /**
156
+ * Checks whether a character code is whitespace recognized by Markdown.
157
+ *
158
+ * Matches the Unicode `Zs` category or `\t`, `\f`, `\v`, `\r`, `\n`.
159
+ */
160
+ declare function isWhiteSpace(code: number): boolean;
161
+ /**
162
+ * Checks whether a character is Unicode punctuation or a symbol.
163
+ *
164
+ * Does not support astral characters.
165
+ */
166
+ declare function isPunctChar(ch: string): boolean;
167
+ /** Checks whether a Unicode code point is punctuation or a symbol. */
168
+ declare function isPunctCharCode(code: number): boolean;
169
+ /**
170
+ * Markdown ASCII punctuation characters.
171
+ *
172
+ * !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @,
173
+ * [, \, ], ^, _, `, {, |, }, or ~
174
+ *
175
+ * http://spec.commonmark.org/0.15/#ascii-punctuation-character
176
+ *
177
+ * Don't confuse with Unicode punctuation. It lacks some characters in the
178
+ * ASCII range.
179
+ */
180
+ declare function isMdAsciiPunct(ch: number): boolean;
181
+ /** Normalizes `[reference labels]` for case-insensitive lookup. */
182
+ declare function normalizeReference(str: string): string;
183
+ /**
184
+ * "Light" `.trim()` for blocks (headings, paragraphs), where Unicode spaces
185
+ * should be preserved.
186
+ */
187
+ declare function asciiTrim(str: string): string;
188
+ /**
189
+ * Libraries commonly used by markdown-it and its plugins, re-exported to
190
+ * reduce duplicate dependencies in browser bundles.
191
+ */
192
+ declare const lib: {
193
+ mdurl: typeof mdurl;
194
+ ucmicro: typeof ucmicro;
195
+ };
196
+ //#endregion
197
+ //#region src/token.d.ts
198
+ /** @inline */
199
+ type TokenNesting = -1 | 0 | 1;
200
+ /** @inline */
201
+ type TokenAttribute = [name: string, value: string | number];
202
+ /**
203
+ * Represents one item in the parsed token stream, storing parsed data and
204
+ * providing helpers for managing HTML attributes.
205
+ */
206
+ declare class Token {
207
+ /**
208
+ * Type of the token (string, e.g. "paragraph_open")
209
+ */
210
+ type: string;
211
+ /**
212
+ * html tag name, e.g. "p"
213
+ */
214
+ tag: string;
215
+ /** Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]` */
216
+ attrs: TokenAttribute[] | null;
217
+ /**
218
+ * Source map info. Format: `[ line_begin, line_end ]`
219
+ */
220
+ map: [number, number] | null;
221
+ /**
222
+ * Level change (number in {-1, 0, 1} set), where:
223
+ *
224
+ * - `1` means the tag is opening
225
+ * - `0` means the tag is self-closing
226
+ * - `-1` means the tag is closing
227
+ */
228
+ nesting: TokenNesting;
229
+ /**
230
+ * nesting level, the same as `state.level`
231
+ */
232
+ level: number;
233
+ /**
234
+ * An array of child nodes (inline and img tokens)
235
+ */
236
+ children: Token[] | null;
237
+ /**
238
+ * In a case of self-closing tag (code, html, fence, etc.),
239
+ * it has contents of this tag.
240
+ */
241
+ content: string;
242
+ /**
243
+ * '*' or '_' for emphasis, fence string for fence, etc.
244
+ */
245
+ markup: string;
246
+ /**
247
+ * Additional information:
248
+ *
249
+ * - Info string for "fence" tokens
250
+ * - The value "auto" for autolink "link_open" and "link_close" tokens
251
+ * - The string value of the item marker for ordered-list "list_item_open" tokens
252
+ */
253
+ info: string;
254
+ /** A place for plugins to store an arbitrary data */
255
+ meta: Record<string, unknown> | null;
256
+ /**
257
+ * True for block-level tokens, false for inline tokens.
258
+ * Used in renderer to calculate line breaks
259
+ */
260
+ block: boolean;
261
+ /**
262
+ * If it's true, ignore this element when rendering. Used for tight lists
263
+ * to hide paragraphs.
264
+ */
265
+ hidden: boolean;
266
+ constructor(type: string, tag: string, nesting: TokenNesting);
267
+ /**
268
+ * Search attribute index by name.
269
+ */
270
+ attrIndex(name: string): number;
271
+ /**
272
+ * Add `[ name, value ]` attribute to list. Init attrs if necessary
273
+ */
274
+ attrPush(attrData: TokenAttribute): void;
275
+ /**
276
+ * Set `name` attribute to `value`. Override old value if exists.
277
+ */
278
+ attrSet(name: string, value: string | number): void;
279
+ /**
280
+ * Get the value of attribute `name`, or null if it does not exist.
281
+ */
282
+ attrGet(name: string): string | number | null;
283
+ /**
284
+ * Join value to existing attribute via space. Or create new attribute if not
285
+ * exists. Useful to operate with token classes.
286
+ */
287
+ attrJoin(name: string, value: string | number): void;
288
+ }
289
+ //#endregion
290
+ //#region src/rules_inline/state_inline.d.ts
291
+ /** @inline */
292
+ interface ScannedDelimiters {
293
+ can_open: boolean;
294
+ can_close: boolean;
295
+ length: number;
296
+ }
297
+ /** @inline */
298
+ type StateTokenMeta = Record<string, unknown> & {
299
+ delimiters?: Delimiter[];
300
+ };
301
+ /** Mutable state passed to inline rules while tokenizing inline content. */
302
+ declare class StateInline {
303
+ src: string;
304
+ env: Env;
305
+ md: MarkdownIt;
306
+ tokens: Token[];
307
+ tokens_meta: Array<StateTokenMeta | undefined>;
308
+ pos: number;
309
+ posMax: number;
310
+ level: number;
311
+ pending: string;
312
+ pendingLevel: number;
313
+ cache: Record<number, number>;
314
+ backticks: Record<number, number>;
315
+ backticksScanned: boolean;
316
+ linkLevel: number;
317
+ delimiters: Delimiter[];
318
+ _prev_delimiters: Delimiter[][];
319
+ Token: typeof Token;
320
+ constructor(src: string, md: MarkdownIt, env: Env, outTokens: Token[]);
321
+ pushPending(): Token;
322
+ push(type: string, tag: string, nesting: -1 | 0 | 1): Token;
323
+ scanDelims(start: number, canSplitWord: boolean): ScannedDelimiters;
324
+ }
325
+ //#endregion
326
+ //#region src/helpers/parse_link_label.d.ts
327
+ /** Finds the end of a link or image label (`[label]`). */
328
+ declare function parseLinkLabel(state: StateInline, start: number, disableNested?: boolean): number;
329
+ //#endregion
330
+ //#region src/helpers/parse_link_destination.d.ts
331
+ /** Parses the destination in `[label](destination "title")`. */
332
+ declare function parseLinkDestination(str: string, start: number, max: number): {
333
+ ok: boolean;
334
+ pos: number;
335
+ str: string;
336
+ };
337
+ //#endregion
338
+ //#region src/helpers/parse_link_title.d.ts
339
+ /** @inline */
340
+ interface ParseLinkTitleResult {
341
+ ok: boolean;
342
+ can_continue: boolean;
343
+ pos: number;
344
+ str: string;
345
+ marker: number;
346
+ }
347
+ /**
348
+ * Parses the optional title in `[label](destination "title")` or
349
+ * `[label]: destination "title"`.
350
+ *
351
+ * `prev_state` continues a reference title on the next source line.
352
+ */
353
+ declare function parseLinkTitle(str: string, start: number, max: number, prev_state?: ParseLinkTitleResult): ParseLinkTitleResult;
354
+ declare namespace index_d_exports {
355
+ export { parseLinkDestination, parseLinkLabel, parseLinkTitle };
356
+ }
357
+ //#endregion
358
+ //#region src/ruler.d.ts
359
+ /** @inline */
360
+ type RuleOptions = {
361
+ alt?: string[];
362
+ };
363
+ /**
364
+ * Helper class, used by {@link MarkdownIt.core}, {@link MarkdownIt.block} and
365
+ * {@link MarkdownIt.inline} to manage sequences of functions (rules):
366
+ *
367
+ * - keep rules in defined order
368
+ * - assign the name to each rule
369
+ * - enable/disable rules
370
+ * - add/replace rules
371
+ * - allow assign rules to additional named chains (in the same)
372
+ * - cacheing lists of active rules
373
+ *
374
+ * You will not need use this class directly until write plugins. For simple
375
+ * rules control use {@link MarkdownIt.disable}, {@link MarkdownIt.enable} and
376
+ * {@link MarkdownIt.use}.
377
+ */
378
+ declare class Ruler<Args extends unknown[], Result> {
379
+ __rules__: Array<{
380
+ name: string;
381
+ enabled: boolean;
382
+ fn: (...args: Args) => Result;
383
+ alt: string[];
384
+ }>;
385
+ __cache__: Record<string, Array<(...args: Args) => Result>> | null;
386
+ __find__(name: string): number;
387
+ __compile__(): void;
388
+ /**
389
+ * Replace rule by name with new function & options. Throws error if name not
390
+ * found.
391
+ *
392
+ * @param name Rule name to replace.
393
+ * @param fn New rule function.
394
+ * @param options Rule options. `alt` is an array with names of "alternate"
395
+ * chains.
396
+ *
397
+ * @example Replace existing typographer replacement rule with new one
398
+ * ```javascript
399
+ * import MarkdownIt from 'markdown-it'
400
+ * const md = new MarkdownIt()
401
+ *
402
+ * md.core.ruler.at('replacements', function replace(state) {
403
+ * //...
404
+ * });
405
+ * ```
406
+ */
407
+ at(name: string, fn: (...args: Args) => Result, options?: RuleOptions): void;
408
+ /**
409
+ * Add new rule to chain before one with given name. See also
410
+ * {@link Ruler.after}, {@link Ruler.push}.
411
+ *
412
+ * @param beforeName New rule will be added before this one.
413
+ * @param ruleName Name of added rule.
414
+ * @param fn Rule function.
415
+ * @param options Rule options. `alt` is an array with names of "alternate"
416
+ * chains.
417
+ *
418
+ * @example
419
+ * ```javascript
420
+ * import MarkdownIt from 'markdown-it'
421
+ * const md = new MarkdownIt()
422
+ *
423
+ * md.block.ruler.before('paragraph', 'my_rule', function replace(state) {
424
+ * //...
425
+ * });
426
+ * ```
427
+ */
428
+ before(beforeName: string, ruleName: string, fn: (...args: Args) => Result, options?: RuleOptions): void;
429
+ /**
430
+ * Add new rule to chain after one with given name. See also
431
+ * {@link Ruler.before}, {@link Ruler.push}.
432
+ *
433
+ * @param afterName New rule will be added after this one.
434
+ * @param ruleName Name of added rule.
435
+ * @param fn Rule function.
436
+ * @param options Rule options. `alt` is an array with names of "alternate"
437
+ * chains.
438
+ *
439
+ * @example
440
+ * ```javascript
441
+ * import MarkdownIt from 'markdown-it'
442
+ * const md = new MarkdownIt()
443
+ *
444
+ * md.inline.ruler.after('text', 'my_rule', function replace(state) {
445
+ * //...
446
+ * });
447
+ * ```
448
+ */
449
+ after(afterName: string, ruleName: string, fn: (...args: Args) => Result, options?: RuleOptions): void;
450
+ /**
451
+ * Push new rule to the end of chain. See also
452
+ * {@link Ruler.before}, {@link Ruler.after}.
453
+ *
454
+ * @param ruleName Name of added rule.
455
+ * @param fn Rule function.
456
+ * @param options Rule options. `alt` is an array with names of "alternate"
457
+ * chains.
458
+ *
459
+ * @example
460
+ * ```javascript
461
+ * import MarkdownIt from 'markdown-it'
462
+ * const md = new MarkdownIt()
463
+ *
464
+ * md.core.ruler.push('my_rule', function replace(state) {
465
+ * //...
466
+ * });
467
+ * ```
468
+ */
469
+ push(ruleName: string, fn: (...args: Args) => Result, options?: RuleOptions): void;
470
+ /**
471
+ * Enable rules with given names. If any rule name not found - throw Error.
472
+ * Errors can be disabled by second param.
473
+ *
474
+ * See also {@link Ruler.disable}, {@link Ruler.enableOnly}.
475
+ *
476
+ * @param list List of rule names to enable.
477
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
478
+ * @returns List of found rule names (if no exception happened).
479
+ */
480
+ enable(list: string | string[], ignoreInvalid?: boolean): string[];
481
+ /**
482
+ * Enable rules with given names, and disable everything else. If any rule name
483
+ * not found - throw Error. Errors can be disabled by second param.
484
+ *
485
+ * See also {@link Ruler.disable}, {@link Ruler.enable}.
486
+ *
487
+ * @param list List of rule names to enable (whitelist).
488
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
489
+ */
490
+ enableOnly(list: string | string[], ignoreInvalid?: boolean): void;
491
+ /**
492
+ * Disable rules with given names. If any rule name not found - throw Error.
493
+ * Errors can be disabled by second param.
494
+ *
495
+ * See also {@link Ruler.enable}, {@link Ruler.enableOnly}.
496
+ *
497
+ * @param list List of rule names to disable.
498
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
499
+ * @returns List of found rule names (if no exception happened).
500
+ */
501
+ disable(list: string | string[], ignoreInvalid?: boolean): string[];
502
+ /**
503
+ * Return array of active functions (rules) for given chain name. It analyzes
504
+ * rules configuration, compiles caches if not exists and returns result.
505
+ *
506
+ * Default chain name is `''` (empty string). It can't be skipped. That's
507
+ * done intentionally, to keep signature monomorphic for high speed.
508
+ */
509
+ getRules(chainName: string): Array<(...args: Args) => Result>;
510
+ }
511
+ //#endregion
512
+ //#region src/renderer.d.ts
513
+ /** Function that renders a token at a given position in a token stream. */
514
+ type RendererRule = (tokens: Token[], idx: number, options: Required<MarkdownItOptions>, env: Env | undefined, renderer: Renderer) => string;
515
+ /**
516
+ * Generates HTML from parsed token stream. Each instance has independent
517
+ * copy of rules. Those can be rewritten with ease. Also, you can add new
518
+ * rules if you create plugin and adds new token types.
519
+ *
520
+ * Creates new renderer instance and fills {@link Renderer.rules} with defaults.
521
+ */
522
+ declare class Renderer {
523
+ /**
524
+ * Contains render rules for tokens. Can be updated and extended.
525
+ *
526
+ * See [source code](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts)
527
+ * for more details and examples.
528
+ *
529
+ * @example Custom render rules
530
+ * ```javascript
531
+ * import MarkdownIt from 'markdown-it'
532
+ * const md = new MarkdownIt()
533
+ *
534
+ * md.renderer.rules.strong_open = function () { return '<b>'; };
535
+ * md.renderer.rules.strong_close = function () { return '</b>'; };
536
+ *
537
+ * const result = md.renderInline(...);
538
+ * ```
539
+ *
540
+ * @example Each rule is called as independent static function with fixed signature
541
+ * ```javascript
542
+ * function my_token_render(tokens, idx, options, env, renderer) {
543
+ * // ...
544
+ * return renderedHTML;
545
+ * }
546
+ * ```
547
+ */
548
+ rules: Record<string, RendererRule>;
549
+ /**
550
+ * Render token attributes to string.
551
+ */
552
+ renderAttrs(token: Pick<Token, 'attrs'>): string;
553
+ /**
554
+ * Default token renderer. Can be overriden by custom function
555
+ * in {@link Renderer.rules}.
556
+ *
557
+ * @param tokens List of tokens.
558
+ * @param idx Token index to render.
559
+ * @param options Params of parser instance.
560
+ */
561
+ renderToken(tokens: Token[], idx: number, options: Required<MarkdownItOptions>): string;
562
+ /**
563
+ * The same as {@link Renderer.render}, but for single token of `inline` type.
564
+ *
565
+ * @param tokens List on block tokens to render.
566
+ * @param options Params of parser instance.
567
+ * @param env Additional data from parsed input (references, for example).
568
+ */
569
+ renderInline(tokens: Token[], options: Required<MarkdownItOptions>, env: Env | undefined): string;
570
+ /**
571
+ * Special kludge for image `alt` attributes to conform CommonMark spec.
572
+ * Don't try to use it! Spec requires to show `alt` content with stripped markup,
573
+ * instead of simple escaping.
574
+ *
575
+ * @param tokens List on block tokens to render.
576
+ * @param options Params of parser instance.
577
+ * @param env Additional data from parsed input (references, for example).
578
+ */
579
+ renderInlineAsText(tokens: Token[], options: Required<MarkdownItOptions>, env: Env | undefined): string;
580
+ /**
581
+ * Takes token stream and generates HTML. Probably, you will never need to call
582
+ * this method directly.
583
+ *
584
+ * @param tokens List on block tokens to render.
585
+ * @param options Params of parser instance.
586
+ * @param env Additional data from parsed input (references, for example).
587
+ */
588
+ render(tokens: Token[], options: Required<MarkdownItOptions>, env?: Env): string;
589
+ }
590
+ //#endregion
591
+ //#region src/rules_core/state_core.d.ts
592
+ /** Mutable state passed through the core rules chain. */
593
+ declare class StateCore {
594
+ src: string;
595
+ env: Env;
596
+ tokens: Token[];
597
+ inlineMode: boolean;
598
+ md: MarkdownIt;
599
+ Token: typeof Token;
600
+ constructor(src: string, md: MarkdownIt, env: Env);
601
+ }
602
+ //#endregion
603
+ //#region src/parser_core.d.ts
604
+ /**
605
+ * Top-level rules executor. Glues block/inline parsers and does intermediate
606
+ * transformations.
607
+ */
608
+ declare class ParserCore {
609
+ /**
610
+ * {@link Ruler} instance. Keep configuration of core rules.
611
+ */
612
+ ruler: Ruler<[StateCore], void>;
613
+ State: typeof StateCore;
614
+ constructor();
615
+ /**
616
+ * Executes core chain rules.
617
+ */
618
+ process(state: StateCore): void;
619
+ }
620
+ //#endregion
621
+ //#region src/rules_block/state_block.d.ts
622
+ /** Mutable state passed to block rules while tokenizing a source document. */
623
+ declare class StateBlock {
624
+ src: string;
625
+ md: MarkdownIt;
626
+ env: Env;
627
+ tokens: Token[];
628
+ bMarks: number[];
629
+ eMarks: number[];
630
+ tShift: number[];
631
+ sCount: number[];
632
+ bsCount: number[];
633
+ blkIndent: number;
634
+ line: number;
635
+ lineMax: number;
636
+ tight: boolean;
637
+ listIndent: number;
638
+ parentType: string;
639
+ level: number;
640
+ Token: typeof Token;
641
+ constructor(src: string, md: MarkdownIt, env: Env, tokens: Token[]);
642
+ push(type: string, tag: string, nesting: -1 | 0 | 1): Token;
643
+ isEmpty(line: number): boolean;
644
+ skipEmptyLines(from: number): number;
645
+ skipSpaces(pos: number): number;
646
+ skipSpacesBack(pos: number, min: number): number;
647
+ skipChars(pos: number, code: number): number;
648
+ skipCharsBack(pos: number, code: number, min: number): number;
649
+ getLines(begin: number, end: number, indent: number, keepLastLF: boolean): string;
650
+ }
651
+ //#endregion
652
+ //#region src/parser_block.d.ts
653
+ /**
654
+ * Block-level tokenizer.
655
+ */
656
+ declare class ParserBlock {
657
+ /**
658
+ * {@link Ruler} instance. Keep configuration of block rules.
659
+ */
660
+ ruler: Ruler<[StateBlock, number, number, boolean], boolean>;
661
+ State: typeof StateBlock;
662
+ constructor();
663
+ tokenize(state: StateBlock, startLine: number, endLine: number): void;
664
+ /**
665
+ * Process input string and push block tokens into `outTokens`
666
+ */
667
+ parse(src: string, md: MarkdownIt, env: Env, outTokens: Token[]): void;
668
+ }
669
+ //#endregion
670
+ //#region src/parser_inline.d.ts
671
+ /**
672
+ * Tokenizes paragraph content.
673
+ */
674
+ declare class ParserInline {
675
+ /**
676
+ * {@link Ruler} instance. Keep configuration of inline rules.
677
+ */
678
+ ruler: Ruler<[StateInline, boolean], boolean>;
679
+ /**
680
+ * {@link Ruler} instance. Second ruler used for post-processing
681
+ * (e.g. in emphasis-like rules).
682
+ */
683
+ ruler2: Ruler<[StateInline], void>;
684
+ State: typeof StateInline;
685
+ constructor();
686
+ skipToken(state: StateInline): void;
687
+ tokenize(state: StateInline): void;
688
+ /**
689
+ * Process input string and push inline tokens into `outTokens`
690
+ */
691
+ parse(str: string, md: MarkdownIt, env: Env, outTokens: Token[]): void;
692
+ }
693
+ //#endregion
694
+ //#region src/markdownit.d.ts
695
+ declare const config: {
696
+ default: {
697
+ options: Required<MarkdownItOptions>;
698
+ components: {
699
+ core: {};
700
+ block: {};
701
+ inline: {};
702
+ };
703
+ };
704
+ zero: {
705
+ options: Required<MarkdownItOptions>;
706
+ components: {
707
+ core: {
708
+ rules: string[];
709
+ };
710
+ block: {
711
+ rules: string[];
712
+ };
713
+ inline: {
714
+ rules: string[];
715
+ rules2: string[];
716
+ };
717
+ };
718
+ };
719
+ commonmark: {
720
+ options: Required<MarkdownItOptions>;
721
+ components: {
722
+ core: {
723
+ rules: string[];
724
+ };
725
+ block: {
726
+ rules: string[];
727
+ };
728
+ inline: {
729
+ rules: string[];
730
+ rules2: string[];
731
+ };
732
+ };
733
+ };
734
+ };
735
+ type MarkdownItPresetName = keyof typeof config;
736
+ /**
737
+ * Parser preset containing options and enabled rules for each parser component.
738
+ */
739
+ interface MarkdownItPreset {
740
+ options?: Required<MarkdownItOptions>;
741
+ components?: {
742
+ core?: {
743
+ rules?: string[];
744
+ };
745
+ block?: {
746
+ rules?: string[];
747
+ };
748
+ inline?: {
749
+ rules?: string[];
750
+ rules2?: string[];
751
+ };
752
+ };
753
+ }
754
+ /**
755
+ * Parses Markdown into tokens and renders them to HTML.
756
+ *
757
+ * @category Main
758
+ */
759
+ declare class MarkdownIt {
760
+ /**
761
+ * Instance of {@link ParserInline}. You may need it to add new rules when
762
+ * writing plugins. For simple rules control use {@link MarkdownIt.disable}
763
+ * and {@link MarkdownIt.enable}.
764
+ */
765
+ inline: ParserInline;
766
+ /**
767
+ * Instance of {@link ParserBlock}. You may need it to add new rules when
768
+ * writing plugins. For simple rules control use {@link MarkdownIt.disable}
769
+ * and {@link MarkdownIt.enable}.
770
+ */
771
+ block: ParserBlock;
772
+ /**
773
+ * Instance of {@link ParserCore} chain executor. You may need it to add new
774
+ * rules when writing plugins. For simple rules control use
775
+ * {@link MarkdownIt.disable} and {@link MarkdownIt.enable}.
776
+ */
777
+ core: ParserCore;
778
+ /**
779
+ * Instance of {@link Renderer}. Use it to modify output look. Or to add rendering
780
+ * rules for new token types, generated by plugins.
781
+ *
782
+ * See {@link Renderer} docs and
783
+ * [source code](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts).
784
+ *
785
+ * @example
786
+ * ```javascript
787
+ * import MarkdownIt from 'markdown-it'
788
+ * const md = new MarkdownIt()
789
+ *
790
+ * function myToken(tokens, idx, options, env, self) {
791
+ * //...
792
+ * return result;
793
+ * };
794
+ *
795
+ * md.renderer.rules['my_token'] = myToken
796
+ * ```
797
+ */
798
+ renderer: Renderer;
799
+ /**
800
+ * [linkify-it](https://github.com/markdown-it/linkify-it) instance.
801
+ * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/src/rules_core/linkify.ts)
802
+ * rule.
803
+ */
804
+ linkify: LinkifyIt;
805
+ /**
806
+ * Link validation function. CommonMark allows too much in links. By default
807
+ * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas
808
+ * except some embedded image types.
809
+ *
810
+ * You can change this behaviour:
811
+ *
812
+ * @example
813
+ * ```javascript
814
+ * import MarkdownIt from 'markdown-it'
815
+ * const md = new MarkdownIt()
816
+ *
817
+ * // enable everything
818
+ * md.validateLink = function () { return true; }
819
+ * ```
820
+ */
821
+ validateLink(url: string): boolean;
822
+ /**
823
+ * Function used to encode link url to a machine-readable format,
824
+ * which includes url-encoding, punycode, etc.
825
+ */
826
+ normalizeLink(url: string): string;
827
+ /**
828
+ * Function used to decode link url to a human-readable format`
829
+ */
830
+ normalizeLinkText(url: string): string;
831
+ /**
832
+ * Assorted utility functions, useful to write plugins. See details
833
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/src/common/utils.ts).
834
+ */
835
+ utils: typeof utils_d_exports;
836
+ /**
837
+ * Link components parser functions, useful to write plugins. See details
838
+ * [here](https://github.com/markdown-it/markdown-it/blob/master/src/helpers).
839
+ */
840
+ helpers: typeof index_d_exports;
841
+ options: Required<MarkdownItOptions>;
842
+ constructor(...args: [] | [options: MarkdownItOptions] | [presetName: MarkdownItPresetName, options?: MarkdownItOptions]);
843
+ /**
844
+ * Set parser options (in the same format as in constructor). Probably, you
845
+ * will never need it, but you can change options after constructor call.
846
+ *
847
+ * __Note:__ To achieve the best possible performance, don't modify a
848
+ * `markdown-it` instance options on the fly. If you need multiple configurations
849
+ * it's best to create multiple instances and initialize each with separate
850
+ * config.
851
+ *
852
+ * @example
853
+ * ```javascript
854
+ * import MarkdownIt from 'markdown-it'
855
+ *
856
+ * const md = new MarkdownIt()
857
+ * .set({ html: true, breaks: true })
858
+ * .set({ typographer: true })
859
+ * ```
860
+ */
861
+ set(options: MarkdownItOptions): this;
862
+ /**
863
+ * Batch load of all options and compenent settings. This is internal method,
864
+ * and you probably will not need it. But if you will - see available presets
865
+ * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/src/presets)
866
+ *
867
+ * We strongly recommend to use presets instead of direct config loads. That
868
+ * will give better compatibility with next versions.
869
+ */
870
+ configure(presets: MarkdownItPresetName | MarkdownItPreset): this;
871
+ /**
872
+ * Enable list or rules. It will automatically find appropriate components,
873
+ * containing rules with given names. If rule not found, and `ignoreInvalid`
874
+ * not set - throws exception.
875
+ *
876
+ * @param list Rule name or list of rule names to enable.
877
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
878
+ *
879
+ * @example
880
+ * ```javascript
881
+ * import MarkdownIt from 'markdown-it'
882
+ *
883
+ * const md = new MarkdownIt()
884
+ * .enable(['sub', 'sup'])
885
+ * .disable('smartquotes')
886
+ * ```
887
+ */
888
+ enable(list: string | string[], ignoreInvalid?: boolean): this;
889
+ /**
890
+ * The same as {@link MarkdownIt.enable}, but turn specified rules off.
891
+ *
892
+ * @param list Rule name or list of rule names to disable.
893
+ * @param ignoreInvalid Set `true` to ignore errors when rule not found.
894
+ */
895
+ disable(list: string | string[], ignoreInvalid?: boolean): this;
896
+ /**
897
+ * Load specified plugin with given params into current parser instance.
898
+ * It's just a sugar to call `plugin(md, params)` with curring.
899
+ *
900
+ * @example
901
+ * ```javascript
902
+ * import MarkdownIt from 'markdown-it'
903
+ * import iterator from 'markdown-it-for-inline'
904
+ *
905
+ * const md = new MarkdownIt()
906
+ * .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
907
+ * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar')
908
+ * })
909
+ * ```
910
+ */
911
+ use<Params extends unknown[]>(plugin: (md: this, ...params: Params) => void, ...params: Params): this;
912
+ /**
913
+ * Parse input string and return list of block tokens (special token type
914
+ * "inline" will contain list of inline tokens). You should not call this
915
+ * method directly, until you write custom renderer (for example, to produce
916
+ * AST).
917
+ *
918
+ * `env` is used to pass data between "distributed" rules and return additional
919
+ * metadata like reference info, needed for the renderer. It also can be used to
920
+ * inject data in specific cases. Usually, you will be ok to pass `{}`,
921
+ * and then pass updated object to renderer.
922
+ *
923
+ * @param src Source string.
924
+ * @param env Environment sandbox.
925
+ */
926
+ parse(src: string, env: Env): Token[];
927
+ /**
928
+ * Render markdown string into html. It does all magic for you :).
929
+ *
930
+ * `env` can be used to inject additional metadata (`{}` by default).
931
+ * But you will not need it with high probability. See also comment
932
+ * in {@link MarkdownIt.parse}.
933
+ *
934
+ * @param src Source string.
935
+ * @param env Environment sandbox.
936
+ */
937
+ render(src: string, env?: Env): string;
938
+ /**
939
+ * The same as {@link MarkdownIt.parse} but skip all block rules. It returns
940
+ * the block tokens list with the single `inline` element, containing parsed
941
+ * inline tokens in `children` property. Also updates `env` object.
942
+ *
943
+ * @param src Source string.
944
+ * @param env Environment sandbox.
945
+ */
946
+ parseInline(src: string, env: Env): Token[];
947
+ /**
948
+ * Similar to {@link MarkdownIt.render} but for single paragraph content.
949
+ * Result will NOT be wrapped into `<p>` tags.
950
+ *
951
+ * @param src Source string.
952
+ * @param env Environment sandbox.
953
+ */
954
+ renderInline(src: string, env?: Env): string;
955
+ static Token: typeof Token;
956
+ static Ruler: typeof Ruler;
957
+ static Renderer: typeof Renderer;
958
+ static ParserCore: typeof ParserCore;
959
+ static StateCore: typeof StateCore;
960
+ static ParserBlock: typeof ParserBlock;
961
+ static StateBlock: typeof StateBlock;
962
+ static ParserInline: typeof ParserInline;
963
+ static StateInline: typeof StateInline;
964
+ }
965
+ //#endregion
966
+ //#region src/index.d.ts
967
+ /**
968
+ * Default package export.
969
+ *
970
+ * For backward compatibility, the {@link MarkdownIt} class is wrapped so
971
+ * legacy code can call it without `new`. New code should instantiate it as a
972
+ * regular class with `new`. The compatibility wrapper may be removed in a
973
+ * future release.
974
+ *
975
+ * @category Main
976
+ */
977
+ declare const MarkdownItCallable: typeof MarkdownIt & ((...args: [] | [options: MarkdownItOptions] | [presetName: "default" | "zero" | "commonmark", options?: MarkdownItOptions | undefined]) => MarkdownIt);
978
+ //#endregion
979
+ export { type Delimiter, type Env, type MarkdownIt, type MarkdownItOptions, type MarkdownItPreset, type ParserBlock, type ParserCore, type ParserInline, type Renderer, type RendererRule, type Ruler, type StateBlock, type StateCore, type StateInline, type Token, MarkdownItCallable as default };