UNPKG

35.2 kBTypeScriptView Raw
1import LinkifyIt = require("linkify-it");
2import mdurl = require("mdurl");
3// import ucmicro = require("uc.micro");
4
5// lib/token.mjs
6
7declare class Token {
8 /**
9 * Create new token and fill passed properties.
10 */
11 constructor(type: string, tag: string, nesting: MarkdownIt.Token.Nesting);
12
13 /**
14 * Type of the token, e.g. "paragraph_open"
15 */
16 type: string;
17
18 /**
19 * HTML tag name, e.g. "p"
20 */
21 tag: string;
22
23 /**
24 * HTML attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]`
25 */
26 attrs: Array<[string, string]> | null;
27
28 /**
29 * Source map info. Format: `[ line_begin, line_end ]`
30 */
31 map: [number, number] | null;
32
33 /**
34 * Level change (number in {-1, 0, 1} set), where:
35 *
36 * - `1` means the tag is opening
37 * - `0` means the tag is self-closing
38 * - `-1` means the tag is closing
39 */
40 nesting: MarkdownIt.Token.Nesting;
41
42 /**
43 * Nesting level, the same as `state.level`
44 */
45 level: number;
46
47 /**
48 * An array of child nodes (inline and img tokens)
49 */
50 children: Token[] | null;
51
52 /**
53 * In a case of self-closing tag (code, html, fence, etc.),
54 * it has contents of this tag.
55 */
56 content: string;
57
58 /**
59 * '*' or '_' for emphasis, fence string for fence, etc.
60 */
61 markup: string;
62
63 /**
64 * - Info string for "fence" tokens
65 * - The value "auto" for autolink "link_open" and "link_close" tokens
66 * - The string value of the item marker for ordered-list "list_item_open" tokens
67 */
68 info: string;
69
70 /**
71 * A place for plugins to store an arbitrary data
72 */
73 meta: any;
74
75 /**
76 * True for block-level tokens, false for inline tokens.
77 * Used in renderer to calculate line breaks
78 */
79 block: boolean;
80
81 /**
82 * If it's true, ignore this element when rendering. Used for tight lists
83 * to hide paragraphs.
84 */
85 hidden: boolean;
86
87 /**
88 * Search attribute index by name.
89 */
90 attrIndex(name: string): number;
91
92 /**
93 * Add `[ name, value ]` attribute to list. Init attrs if necessary
94 */
95 attrPush(attrData: [string, string]): void;
96
97 /**
98 * Set `name` attribute to `value`. Override old value if exists.
99 */
100 attrSet(name: string, value: string): void;
101
102 /**
103 * Get the value of attribute `name`, or null if it does not exist.
104 */
105 attrGet(name: string): string | null;
106
107 /**
108 * Join value to existing attribute via space. Or create new attribute if not
109 * exists. Useful to operate with token classes.
110 */
111 attrJoin(name: string, value: string): void;
112}
113
114type Token_ = Token;
115
116// lib/renderer.mjs
117
118declare class Renderer {
119 /**
120 * Creates new {@link Renderer} instance and fill {@link Renderer#rules} with defaults.
121 */
122 constructor();
123
124 /**
125 * Contains render rules for tokens. Can be updated and extended.
126 *
127 * ##### Example
128 *
129 * ```javascript
130 * var md = require('markdown-it')();
131 *
132 * md.renderer.rules.strong_open = function () { return '<b>'; };
133 * md.renderer.rules.strong_close = function () { return '</b>'; };
134 *
135 * var result = md.renderInline(...);
136 * ```
137 *
138 * Each rule is called as independent static function with fixed signature:
139 *
140 * ```javascript
141 * function my_token_render(tokens, idx, options, env, renderer) {
142 * // ...
143 * return renderedHTML;
144 * }
145 * ```
146 *
147 * @see https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs
148 */
149 rules: MarkdownIt.Renderer.RenderRuleRecord;
150
151 /**
152 * Render token attributes to string.
153 */
154 renderAttrs(token: Token): string;
155
156 /**
157 * Default token renderer. Can be overriden by custom function
158 * in {@link Renderer#rules}.
159 *
160 * @param tokens list of tokens
161 * @param idx token index to render
162 * @param options params of parser instance
163 */
164 renderToken(tokens: Token[], idx: number, options: MarkdownIt.Options): string;
165
166 /**
167 * The same as {@link Renderer.render}, but for single token of `inline` type.
168 *
169 * @param tokens list of block tokens to render
170 * @param options params of parser instance
171 * @param env additional data from parsed input (references, for example)
172 */
173 renderInline(tokens: Token[], options: MarkdownIt.Options, env: any): string;
174
175 /**
176 * Special kludge for image `alt` attributes to conform CommonMark spec.
177 * Don't try to use it! Spec requires to show `alt` content with stripped markup,
178 * instead of simple escaping.
179 *
180 * @param tokens list of block tokens to render
181 * @param options params of parser instance
182 * @param env additional data from parsed input (references, for example)
183 */
184 renderInlineAsText(tokens: Token[], options: MarkdownIt.Options, env: any): string;
185
186 /**
187 * Takes token stream and generates HTML. Probably, you will never need to call
188 * this method directly.
189 *
190 * @param tokens list of block tokens to render
191 * @param options params of parser instance
192 * @param env additional data from parsed input (references, for example)
193 */
194 render(tokens: Token[], options: MarkdownIt.Options, env: any): string;
195}
196
197type Renderer_ = Renderer;
198
199// lib/ruler.mjs
200
201/**
202 * Helper class, used by {@link MarkdownIt#core}, {@link MarkdownIt#block} and
203 * {@link MarkdownIt#inline} to manage sequences of functions (rules):
204 *
205 * - keep rules in defined order
206 * - assign the name to each rule
207 * - enable/disable rules
208 * - add/replace rules
209 * - allow assign rules to additional named chains (in the same)
210 * - caching lists of active rules
211 *
212 * You will not need use this class directly until write plugins. For simple
213 * rules control use {@link MarkdownIt.disable}, {@link MarkdownIt.enable} and
214 * {@link MarkdownIt.use}.
215 */
216declare class Ruler<T> {
217 constructor();
218
219 /**
220 * Replace rule by name with new function & options. Throws error if name not
221 * found.
222 *
223 * ##### Example
224 *
225 * Replace existing typographer replacement rule with new one:
226 *
227 * ```javascript
228 * var md = require('markdown-it')();
229 *
230 * md.core.ruler.at('replacements', function replace(state) {
231 * //...
232 * });
233 * ```
234 *
235 * @param name rule name to replace.
236 * @param fn new rule function.
237 * @param options new rule options (not mandatory).
238 */
239 at(name: string, fn: T, options?: MarkdownIt.Ruler.RuleOptions): void;
240
241 /**
242 * Add new rule to chain before one with given name.
243 *
244 * ##### Example
245 *
246 * ```javascript
247 * var md = require('markdown-it')();
248 *
249 * md.block.ruler.before('paragraph', 'my_rule', function replace(state) {
250 * //...
251 * });
252 * ```
253 *
254 * @see {@link Ruler.after}, {@link Ruler.push}
255 *
256 * @param beforeName new rule will be added before this one.
257 * @param ruleName name of added rule.
258 * @param fn rule function.
259 * @param options rule options (not mandatory).
260 */
261 before(beforeName: string, ruleName: string, fn: T, options?: MarkdownIt.Ruler.RuleOptions): void;
262
263 /**
264 * Add new rule to chain after one with given name.
265 *
266 * ##### Example
267 *
268 * ```javascript
269 * var md = require('markdown-it')();
270 *
271 * md.inline.ruler.after('text', 'my_rule', function replace(state) {
272 * //...
273 * });
274 * ```
275 *
276 * @see {@link Ruler.before}, {@link Ruler.push}
277 *
278 * @param afterName new rule will be added after this one.
279 * @param ruleName name of added rule.
280 * @param fn rule function.
281 * @param options rule options (not mandatory).
282 */
283 after(afterName: string, ruleName: string, fn: T, options?: MarkdownIt.Ruler.RuleOptions): void;
284
285 /**
286 * Push new rule to the end of chain.
287 *
288 * ##### Example
289 *
290 * ```javascript
291 * var md = require('markdown-it')();
292 *
293 * md.core.ruler.push('my_rule', function replace(state) {
294 * //...
295 * });
296 * ```
297 *
298 * @see {@link Ruler.before}, {@link Ruler.after}
299 *
300 * @param ruleName name of added rule.
301 * @param fn rule function.
302 * @param options rule options (not mandatory).
303 */
304 push(ruleName: string, fn: T, options?: MarkdownIt.Ruler.RuleOptions): void;
305
306 /**
307 * Enable rules with given names. If any rule name not found - throw Error.
308 * Errors can be disabled by second param.
309 *
310 * Returns list of found rule names (if no exception happened).
311 *
312 * @see {@link Ruler.disable}, {@link Ruler.enableOnly}
313 *
314 * @param list list of rule names to enable.
315 * @param ignoreInvalid set `true` to ignore errors when rule not found.
316 */
317 enable(list: string | string[], ignoreInvalid?: boolean): string[];
318
319 /**
320 * Enable rules with given names, and disable everything else. If any rule name
321 * not found - throw Error. Errors can be disabled by second param.
322 *
323 * @see {@link Ruler.disable}, {@link Ruler.enable}
324 *
325 * @param list list of rule names to enable (whitelist).
326 * @param ignoreInvalid set `true` to ignore errors when rule not found.
327 */
328 enableOnly(list: string | string[], ignoreInvalid?: boolean): void;
329
330 /**
331 * Disable rules with given names. If any rule name not found - throw Error.
332 * Errors can be disabled by second param.
333 *
334 * Returns list of found rule names (if no exception happened).
335 *
336 * @see {@link Ruler.enable}, {@link Ruler.enableOnly}
337 *
338 * @param list list of rule names to disable.
339 * @param ignoreInvalid set `true` to ignore errors when rule not found.
340 */
341 disable(list: string | string[], ignoreInvalid?: boolean): string[];
342
343 /**
344 * Return array of active functions (rules) for given chain name. It analyzes
345 * rules configuration, compiles caches if not exists and returns result.
346 *
347 * Default chain name is `''` (empty string). It can't be skipped. That's
348 * done intentionally, to keep signature monomorphic for high speed.
349 */
350 getRules(chainName: string): T[];
351}
352
353type Ruler_<T> = Ruler<T>;
354
355// lib/rules_core/state_core.mjs
356
357declare class StateCore {
358 constructor(src: string, md: MarkdownIt, env: any);
359
360 src: string;
361 env: any;
362 tokens: Token[];
363 inlineMode: boolean;
364
365 /**
366 * link to parser instance
367 */
368 md: MarkdownIt;
369
370 Token: typeof Token;
371}
372
373type StateCore_ = StateCore;
374
375// lib/rules_block/state_block.mjs
376
377declare class StateBlock {
378 constructor(src: string, md: MarkdownIt, env: any, tokens: Token[]);
379
380 src: string;
381
382 /**
383 * link to parser instance
384 */
385 md: MarkdownIt;
386
387 env: any;
388
389 //
390 // Internal state vartiables
391 //
392
393 tokens: Token[];
394
395 /**
396 * line begin offsets for fast jumps
397 */
398 bMarks: number[];
399 /**
400 * line end offsets for fast jumps
401 */
402 eMarks: number[];
403 /**
404 * offsets of the first non-space characters (tabs not expanded)
405 */
406 tShift: number[];
407 /**
408 * indents for each line (tabs expanded)
409 */
410 sCount: number[];
411
412 /**
413 * An amount of virtual spaces (tabs expanded) between beginning
414 * of each line (bMarks) and real beginning of that line.
415 *
416 * It exists only as a hack because blockquotes override bMarks
417 * losing information in the process.
418 *
419 * It's used only when expanding tabs, you can think about it as
420 * an initial tab length, e.g. bsCount=21 applied to string `\t123`
421 * means first tab should be expanded to 4-21%4 === 3 spaces.
422 */
423 bsCount: number[];
424
425 // block parser variables
426
427 /**
428 * required block content indent (for example, if we are
429 * inside a list, it would be positioned after list marker)
430 */
431 blkIndent: number;
432 /**
433 * line index in src
434 */
435 line: number;
436 /**
437 * lines count
438 */
439 lineMax: number;
440 /**
441 * loose/tight mode for lists
442 */
443 tight: boolean;
444 /**
445 * indent of the current dd block (-1 if there isn't any)
446 */
447 ddIndent: number;
448 /**
449 * indent of the current list block (-1 if there isn't any)
450 */
451 listIndent: number;
452
453 /**
454 * used in lists to determine if they interrupt a paragraph
455 */
456 parentType: MarkdownIt.StateBlock.ParentType;
457
458 level: number;
459
460 /**
461 * Push new token to "stream".
462 */
463 push(type: string, tag: string, nesting: MarkdownIt.Token.Nesting): Token;
464
465 isEmpty(line: number): boolean;
466
467 skipEmptyLines(from: number): number;
468
469 /**
470 * Skip spaces from given position.
471 */
472 skipSpaces(pos: number): number;
473
474 /**
475 * Skip spaces from given position in reverse.
476 */
477 skipSpacesBack(pos: number, min: number): number;
478
479 /**
480 * Skip char codes from given position
481 */
482 skipChars(pos: number, code: number): number;
483
484 /**
485 * Skip char codes reverse from given position - 1
486 */
487 skipCharsBack(pos: number, code: number, min: number): number;
488
489 /**
490 * cut lines range from source.
491 */
492 getLines(begin: number, end: number, indent: number, keepLastLF: boolean): string;
493
494 Token: typeof Token;
495}
496
497type StateBlock_ = StateBlock;
498
499// lib/rules_inline/state_inline.mjs
500
501declare class StateInline {
502 constructor(src: string, md: MarkdownIt, env: any, outTokens: Token[]);
503
504 src: string;
505 env: any;
506 md: MarkdownIt;
507 tokens: Token[];
508 tokens_meta: Array<MarkdownIt.StateInline.TokenMeta | null>;
509
510 pos: number;
511 posMax: number;
512 level: number;
513 pending: string;
514 pendingLevel: number;
515
516 /**
517 * Stores { start: end } pairs. Useful for backtrack
518 * optimization of pairs parse (emphasis, strikes).
519 */
520 cache: any;
521
522 /**
523 * List of emphasis-like delimiters for current tag
524 */
525 delimiters: MarkdownIt.StateInline.Delimiter[];
526
527 // Stack of delimiter lists for upper level tags
528 // _prev_delimiters: StateInline.Delimiter[][];
529
530 /**
531 * Flush pending text
532 */
533 pushPending(): Token;
534
535 /**
536 * Push new token to "stream".
537 * If pending text exists - flush it as text token
538 */
539 push(type: string, tag: string, nesting: MarkdownIt.Token.Nesting): Token;
540
541 /**
542 * Scan a sequence of emphasis-like markers, and determine whether
543 * it can start an emphasis sequence or end an emphasis sequence.
544 *
545 * @param start position to scan from (it should point at a valid marker)
546 * @param canSplitWord determine if these markers can be found inside a word
547 */
548 scanDelims(start: number, canSplitWord: boolean): MarkdownIt.StateInline.Scanned;
549
550 Token: typeof Token;
551}
552
553type StateInline_ = StateInline;
554
555// lib/parser_core.mjs
556
557declare class Core {
558 /**
559 * {@link Ruler} instance. Keep configuration of core rules.
560 */
561 ruler: Ruler<MarkdownIt.Core.RuleCore>;
562
563 /**
564 * Executes core chain rules.
565 */
566 process(state: StateCore): void;
567
568 State: typeof StateCore;
569}
570
571type Core_ = Core;
572
573// lib/parser_block.mjs
574
575declare class ParserBlock {
576 /**
577 * {@link Ruler} instance. Keep configuration of block rules.
578 */
579 ruler: Ruler<MarkdownIt.ParserBlock.RuleBlock>;
580
581 /**
582 * Generate tokens for input range
583 */
584 tokenize(state: StateBlock, startLine: number, endLine: number): void;
585
586 /**
587 * Process input string and push block tokens into `outTokens`
588 */
589 parse(str: string, md: MarkdownIt, env: any, outTokens: Token[]): void;
590
591 State: typeof StateBlock;
592}
593
594type ParserBlock_ = ParserBlock;
595
596// lib/parser_inline.mjs
597
598declare class ParserInline {
599 /**
600 * {@link Ruler} instance. Keep configuration of inline rules.
601 */
602 ruler: Ruler<MarkdownIt.ParserInline.RuleInline>;
603
604 /**
605 * {@link Ruler} instance. Second ruler used for post-processing
606 * (e.g. in emphasis-like rules).
607 */
608 ruler2: Ruler<MarkdownIt.ParserInline.RuleInline2>;
609
610 /**
611 * Skip single token by running all rules in validation mode;
612 * returns `true` if any rule reported success
613 */
614 skipToken(state: StateInline): void;
615
616 /**
617 * Generate tokens for input range
618 */
619 tokenize(state: StateInline): void;
620
621 /**
622 * Process input string and push inline tokens into `outTokens`
623 */
624 parse(str: string, md: MarkdownIt, env: any, outTokens: Token[]): void;
625
626 State: typeof StateInline;
627}
628
629type ParserInline_ = ParserInline;
630
631declare namespace MarkdownIt {
632 // lib/common/utils.mjs
633
634 interface Utils {
635 lib: {
636 mdurl: typeof mdurl;
637 ucmicro: any;
638 };
639
640 /**
641 * Merge objects
642 */
643 assign(obj: any, ...from: any[]): any;
644
645 isString(obj: any): obj is string;
646
647 has(obj: any, key: keyof any): boolean;
648
649 unescapeMd(str: string): string;
650
651 unescapeAll(str: string): string;
652
653 isValidEntityCode(c: number): boolean;
654
655 fromCodePoint(c: number): string;
656
657 escapeHtml(str: string): string;
658
659 /**
660 * Remove element from array and put another array at those position.
661 * Useful for some operations with tokens
662 */
663 arrayReplaceAt<T>(src: T[], pos: number, newElements: T[]): T[];
664
665 isSpace(code: number): boolean;
666
667 /**
668 * Zs (unicode class) || [\t\f\v\r\n]
669 */
670 isWhiteSpace(code: number): boolean;
671
672 /**
673 * Markdown ASCII punctuation characters.
674 *
675 * !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~
676 *
677 * Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
678 *
679 * @see http://spec.commonmark.org/0.15/#ascii-punctuation-character
680 */
681 isMdAsciiPunct(code: number): boolean;
682
683 /**
684 * Currently without astral characters support.
685 */
686 isPunctChar(ch: string): boolean;
687
688 escapeRE(str: string): string;
689
690 /**
691 * Helper to unify [reference labels].
692 */
693 normalizeReference(str: string): string;
694 }
695
696 // lib/helpers/index.mjs
697
698 interface ParseLinkDestinationResult {
699 ok: boolean;
700 pos: number;
701 str: string;
702 }
703
704 interface ParseLinkTitleResult {
705 /**
706 * if `true`, this is a valid link title
707 */
708 ok: boolean;
709 /**
710 * if `true`, this link can be continued on the next line
711 */
712 can_continue: boolean;
713 /**
714 * if `ok`, it's the position of the first character after the closing marker
715 */
716 pos: number;
717 /**
718 * if `ok`, it's the unescaped title
719 */
720 str: string;
721 /**
722 * expected closing marker character code
723 */
724 marker: number;
725 }
726
727 interface Helpers {
728 // lib/helpers/parse_link_label.mjs
729
730 parseLinkLabel(state: StateInline, start: number, disableNested?: boolean): number;
731
732 // lib/helpers/parse_link_destination.mjs
733
734 parseLinkDestination(str: string, start: number, max: number): ParseLinkDestinationResult;
735
736 // lib/helpers/parse_link_title.mjs
737
738 parseLinkTitle(
739 str: string,
740 start: number,
741 max: number,
742 prev_state?: ParseLinkTitleResult,
743 ): ParseLinkTitleResult;
744 }
745
746 /**
747 * MarkdownIt provides named presets as a convenience to quickly
748 * enable/disable active syntax rules and options for common use cases.
749 *
750 * - ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.js) -
751 * configures parser to strict [CommonMark](http://commonmark.org/) mode.
752 * - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.js) -
753 * similar to GFM, used when no preset name given. Enables all available rules,
754 * but still without html, typographer & autolinker.
755 * - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.js) -
756 * all rules disabled. Useful to quickly setup your config via `.enable()`.
757 * For example, when you need only `bold` and `italic` markup and nothing else.
758 */
759 type PresetName = "default" | "zero" | "commonmark";
760
761 interface Options {
762 /**
763 * Set `true` to enable HTML tags in source. Be careful!
764 * That's not safe! You may need external sanitizer to protect output from XSS.
765 * It's better to extend features via plugins, instead of enabling HTML.
766 * @default false
767 */
768 html?: boolean | undefined;
769
770 /**
771 * Set `true` to add '/' when closing single tags
772 * (`<br />`). This is needed only for full CommonMark compatibility. In real
773 * world you will need HTML output.
774 * @default false
775 */
776 xhtmlOut?: boolean | undefined;
777
778 /**
779 * Set `true` to convert `\n` in paragraphs into `<br>`.
780 * @default false
781 */
782 breaks?: boolean | undefined;
783
784 /**
785 * CSS language class prefix for fenced blocks.
786 * Can be useful for external highlighters.
787 * @default 'language-'
788 */
789 langPrefix?: string | undefined;
790
791 /**
792 * Set `true` to autoconvert URL-like text to links.
793 * @default false
794 */
795 linkify?: boolean | undefined;
796
797 /**
798 * Set `true` to enable [some language-neutral replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js) +
799 * quotes beautification (smartquotes).
800 * @default false
801 */
802 typographer?: boolean | undefined;
803
804 /**
805 * Double + single quotes replacement
806 * pairs, when typographer enabled and smartquotes on. For example, you can
807 * use `'«»„“'` for Russian, `'„“‚‘'` for German, and
808 * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp).
809 * @default '“”‘’'
810 */
811 quotes?: string | string[];
812
813 /**
814 * Highlighter function for fenced code blocks.
815 * Highlighter `function (str, lang, attrs)` should return escaped HTML. It can
816 * also return empty string if the source was not changed and should be escaped
817 * externally. If result starts with <pre... internal wrapper is skipped.
818 * @default null
819 */
820 highlight?: ((str: string, lang: string, attrs: string) => string) | null | undefined;
821 }
822
823 // lib/token.mjs
824
825 type Token = Token_;
826 namespace Token {
827 type Nesting = 1 | 0 | -1;
828 }
829
830 // lib/renderer.mjs
831
832 type Renderer = Renderer_;
833 namespace Renderer {
834 type RenderRule = (tokens: Token[], idx: number, options: Options, env: any, self: Renderer) => string;
835
836 interface RenderRuleRecord {
837 [type: string]: RenderRule | undefined;
838 code_inline?: RenderRule | undefined;
839 code_block?: RenderRule | undefined;
840 fence?: RenderRule | undefined;
841 image?: RenderRule | undefined;
842 hardbreak?: RenderRule | undefined;
843 softbreak?: RenderRule | undefined;
844 text?: RenderRule | undefined;
845 html_block?: RenderRule | undefined;
846 html_inline?: RenderRule | undefined;
847 }
848 }
849
850 // lib/ruler.mjs
851
852 type Ruler<T> = Ruler_<T>;
853 namespace Ruler {
854 interface RuleOptions {
855 /**
856 * array with names of "alternate" chains.
857 */
858 alt: string[];
859 }
860 }
861
862 // lib/rules_core/state_core.mjs
863
864 type StateCore = StateCore_;
865
866 // lib/rules_block/state_block.mjs
867
868 type StateBlock = StateBlock_;
869 namespace StateBlock {
870 type ParentType = "blockquote" | "list" | "root" | "paragraph" | "reference";
871 }
872
873 // lib/rules_inline/state_inline.mjs
874
875 type StateInline = StateInline_;
876 namespace StateInline {
877 interface Scanned {
878 can_open: boolean;
879 can_close: boolean;
880 length: number;
881 }
882
883 interface Delimiter {
884 marker: number;
885 length: number;
886 token: number;
887 end: number;
888 open: boolean;
889 close: boolean;
890 }
891
892 interface TokenMeta {
893 delimiters: Delimiter[];
894 }
895 }
896
897 // lib/parser_core.mjs
898
899 type Core = Core_;
900 namespace Core {
901 type RuleCore = (state: StateCore) => void;
902 }
903
904 // lib/parser_block.mjs
905
906 type ParserBlock = ParserBlock_;
907 namespace ParserBlock {
908 type RuleBlock = (state: StateBlock, startLine: number, endLine: number, silent: boolean) => boolean;
909 }
910
911 // lib/parser_inline.mjs
912
913 type ParserInline = ParserInline_;
914 namespace ParserInline {
915 type RuleInline = (state: StateInline, silent: boolean) => boolean;
916 type RuleInline2 = (state: StateInline) => boolean;
917 }
918
919 type PluginSimple = (md: MarkdownIt) => void;
920 type PluginWithOptions<T = any> = (md: MarkdownIt, options?: T) => void;
921 type PluginWithParams = (md: MarkdownIt, ...params: any[]) => void;
922}
923
924interface MarkdownItConstructor {
925 new(): MarkdownIt;
926 new(presetName: MarkdownIt.PresetName, options?: MarkdownIt.Options): MarkdownIt;
927 new(options: MarkdownIt.Options): MarkdownIt;
928 (): MarkdownIt;
929 (presetName: MarkdownIt.PresetName, options?: MarkdownIt.Options): MarkdownIt;
930 (options: MarkdownIt.Options): MarkdownIt;
931}
932
933interface MarkdownIt {
934 /**
935 * Instance of {@link ParserInline}. You may need it to add new rules when
936 * writing plugins. For simple rules control use {@link MarkdownIt.disable} and
937 * {@link MarkdownIt.enable}.
938 */
939 readonly inline: ParserInline;
940
941 /**
942 * Instance of {@link ParserBlock}. You may need it to add new rules when
943 * writing plugins. For simple rules control use {@link MarkdownIt.disable} and
944 * {@link MarkdownIt.enable}.
945 */
946 readonly block: ParserBlock;
947
948 /**
949 * Instance of {@link Core} chain executor. You may need it to add new rules when
950 * writing plugins. For simple rules control use {@link MarkdownIt.disable} and
951 * {@link MarkdownIt.enable}.
952 */
953 readonly core: Core;
954
955 /**
956 * Instance of {@link Renderer}. Use it to modify output look. Or to add rendering
957 * rules for new token types, generated by plugins.
958 *
959 * ##### Example
960 *
961 * ```javascript
962 * var md = require('markdown-it')();
963 *
964 * function myToken(tokens, idx, options, env, self) {
965 * //...
966 * return result;
967 * };
968 *
969 * md.renderer.rules['my_token'] = myToken
970 * ```
971 *
972 * See {@link Renderer} docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js).
973 */
974 readonly renderer: Renderer;
975
976 /**
977 * [linkify-it](https://github.com/markdown-it/linkify-it) instance.
978 * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js)
979 * rule.
980 */
981 readonly linkify: LinkifyIt;
982
983 /**
984 * Link validation function. CommonMark allows too much in links. By default
985 * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas
986 * except some embedded image types.
987 *
988 * You can change this behaviour:
989 *
990 * ```javascript
991 * var md = require('markdown-it')();
992 * // enable everything
993 * md.validateLink = function () { return true; }
994 * ```
995 */
996 validateLink(url: string): boolean;
997
998 /**
999 * Function used to encode link url to a machine-readable format,
1000 * which includes url-encoding, punycode, etc.
1001 */
1002 normalizeLink(url: string): string;
1003
1004 /**
1005 * Function used to decode link url to a human-readable format`
1006 */
1007 normalizeLinkText(url: string): string;
1008
1009 readonly utils: MarkdownIt.Utils;
1010
1011 readonly helpers: MarkdownIt.Helpers;
1012
1013 readonly options: MarkdownIt.Options;
1014
1015 /**
1016 * *chainable*
1017 *
1018 * Set parser options (in the same format as in constructor). Probably, you
1019 * will never need it, but you can change options after constructor call.
1020 *
1021 * ##### Example
1022 *
1023 * ```javascript
1024 * var md = require('markdown-it')()
1025 * .set({ html: true, breaks: true })
1026 * .set({ typographer: true });
1027 * ```
1028 *
1029 * __Note:__ To achieve the best possible performance, don't modify a
1030 * `markdown-it` instance options on the fly. If you need multiple configurations
1031 * it's best to create multiple instances and initialize each with separate
1032 * config.
1033 */
1034 set(options: MarkdownIt.Options): this;
1035
1036 /**
1037 * *chainable*, *internal*
1038 *
1039 * Batch load of all options and compenent settings. This is internal method,
1040 * and you probably will not need it. But if you with - see available presets
1041 * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)
1042 *
1043 * We strongly recommend to use presets instead of direct config loads. That
1044 * will give better compatibility with next versions.
1045 */
1046 configure(presets: MarkdownIt.PresetName): this;
1047
1048 /**
1049 * *chainable*
1050 *
1051 * Enable list or rules. It will automatically find appropriate components,
1052 * containing rules with given names. If rule not found, and `ignoreInvalid`
1053 * not set - throws exception.
1054 *
1055 * ##### Example
1056 *
1057 * ```javascript
1058 * var md = require('markdown-it')()
1059 * .enable(['sub', 'sup'])
1060 * .disable('smartquotes');
1061 * ```
1062 *
1063 * @param list rule name or list of rule names to enable
1064 * @param ignoreInvalid set `true` to ignore errors when rule not found.
1065 */
1066 enable(list: string | string[], ignoreInvalid?: boolean): this;
1067
1068 /**
1069 * *chainable*
1070 *
1071 * The same as {@link MarkdownIt.enable}, but turn specified rules off.
1072 *
1073 * @param list rule name or list of rule names to disable.
1074 * @param ignoreInvalid set `true` to ignore errors when rule not found.
1075 */
1076 disable(list: string | string[], ignoreInvalid?: boolean): this;
1077
1078 /**
1079 * *chainable*
1080 *
1081 * Load specified plugin with given params into current parser instance.
1082 * It's just a sugar to call `plugin(md, params)` with curring.
1083 *
1084 * ##### Example
1085 *
1086 * ```javascript
1087 * var iterator = require('markdown-it-for-inline');
1088 * var md = require('markdown-it')()
1089 * .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
1090 * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
1091 * });
1092 * ```
1093 */
1094 use(plugin: MarkdownIt.PluginSimple): this;
1095 use<T = any>(plugin: MarkdownIt.PluginWithOptions<T>, options?: T): this;
1096 use(plugin: MarkdownIt.PluginWithParams, ...params: any[]): this;
1097
1098 /**
1099 * *internal*
1100 *
1101 * Parse input string and returns list of block tokens (special token type
1102 * "inline" will contain list of inline tokens). You should not call this
1103 * method directly, until you write custom renderer (for example, to produce
1104 * AST).
1105 *
1106 * `env` is used to pass data between "distributed" rules and return additional
1107 * metadata like reference info, needed for the renderer. It also can be used to
1108 * inject data in specific cases. Usually, you will be ok to pass `{}`,
1109 * and then pass updated object to renderer.
1110 *
1111 * @param src source string
1112 * @param env environment sandbox
1113 */
1114 parse(src: string, env: any): Token[];
1115
1116 /**
1117 * Render markdown string into html. It does all magic for you :).
1118 *
1119 * `env` can be used to inject additional metadata (`{}` by default).
1120 * But you will not need it with high probability. See also comment
1121 * in {@link MarkdownIt.parse}.
1122 *
1123 * @param src source string
1124 * @param env environment sandbox
1125 */
1126 render(src: string, env?: any): string;
1127
1128 /**
1129 * *internal*
1130 *
1131 * The same as {@link MarkdownIt.parse} but skip all block rules. It returns the
1132 * block tokens list with the single `inline` element, containing parsed inline
1133 * tokens in `children` property. Also updates `env` object.
1134 *
1135 * @param src source string
1136 * @param env environment sandbox
1137 */
1138 parseInline(src: string, env: any): Token[];
1139
1140 /**
1141 * Similar to {@link MarkdownIt.render} but for single paragraph content. Result
1142 * will NOT be wrapped into `<p>` tags.
1143 *
1144 * @param src source string
1145 * @param env environment sandbox
1146 */
1147 renderInline(src: string, env?: any): string;
1148}
1149
1150/**
1151 * Main parser/renderer class.
1152 *
1153 * ##### Usage
1154 *
1155 * ```javascript
1156 * // node.js, "classic" way:
1157 * var MarkdownIt = require('markdown-it'),
1158 * md = new MarkdownIt();
1159 * var result = md.render('# markdown-it rulezz!');
1160 *
1161 * // node.js, the same, but with sugar:
1162 * var md = require('markdown-it')();
1163 * var result = md.render('# markdown-it rulezz!');
1164 *
1165 * // browser without AMD, added to "window" on script load
1166 * // Note, there are no dash.
1167 * var md = window.markdownit();
1168 * var result = md.render('# markdown-it rulezz!');
1169 * ```
1170 *
1171 * Single line rendering, without paragraph wrap:
1172 *
1173 * ```javascript
1174 * var md = require('markdown-it')();
1175 * var result = md.renderInline('__markdown-it__ rulezz!');
1176 * ```
1177 *
1178 * ##### Example
1179 *
1180 * ```javascript
1181 * // commonmark mode
1182 * var md = require('markdown-it')('commonmark');
1183 *
1184 * // default mode
1185 * var md = require('markdown-it')();
1186 *
1187 * // enable everything
1188 * var md = require('markdown-it')({
1189 * html: true,
1190 * linkify: true,
1191 * typographer: true
1192 * });
1193 * ```
1194 *
1195 * ##### Syntax highlighting
1196 *
1197 * ```js
1198 * var hljs = require('highlight.js') // https://highlightjs.org/
1199 *
1200 * var md = require('markdown-it')({
1201 * highlight: function (str, lang) {
1202 * if (lang && hljs.getLanguage(lang)) {
1203 * try {
1204 * return hljs.highlight(lang, str, true).value;
1205 * } catch (__) {}
1206 * }
1207 *
1208 * return ''; // use external default escaping
1209 * }
1210 * });
1211 * ```
1212 *
1213 * Or with full wrapper override (if you need assign class to `<pre>`):
1214 *
1215 * ```javascript
1216 * var hljs = require('highlight.js') // https://highlightjs.org/
1217 *
1218 * // Actual default values
1219 * var md = require('markdown-it')({
1220 * highlight: function (str, lang) {
1221 * if (lang && hljs.getLanguage(lang)) {
1222 * try {
1223 * return '<pre class="hljs"><code>' +
1224 * hljs.highlight(lang, str, true).value +
1225 * '</code></pre>';
1226 * } catch (__) {}
1227 * }
1228 *
1229 * return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
1230 * }
1231 * });
1232 * ```
1233 */
1234declare const MarkdownIt: MarkdownItConstructor;
1235
1236export = MarkdownIt;