marked 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/marked.d.ts CHANGED
@@ -1,624 +1,724 @@
1
- type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del) & {
2
- loose?: boolean;
3
- tokens?: Token[];
4
- };
5
- declare namespace Tokens {
6
- interface Space {
7
- type: 'space';
8
- raw: string;
9
- }
10
- interface Code {
11
- type: 'code';
12
- raw: string;
13
- codeBlockStyle?: 'indented' | undefined;
14
- lang?: string | undefined;
15
- text: string;
16
- escaped?: boolean;
17
- }
18
- interface Heading {
19
- type: 'heading';
20
- raw: string;
21
- depth: number;
22
- text: string;
23
- tokens: Token[];
24
- }
25
- interface Table {
26
- type: 'table';
27
- raw?: string;
28
- align: Array<'center' | 'left' | 'right' | null>;
29
- header: TableCell[];
30
- rows: TableCell[][];
31
- }
32
- interface TableCell {
33
- text: string;
34
- tokens?: Token[];
35
- }
36
- interface Hr {
37
- type: 'hr';
38
- raw: string;
39
- }
40
- interface Blockquote {
41
- type: 'blockquote';
42
- raw: string;
43
- text: string;
44
- tokens: Token[];
45
- }
46
- interface List {
47
- type: 'list';
48
- raw: string;
49
- ordered: boolean;
50
- start: number | '';
51
- loose: boolean;
52
- items: ListItem[];
53
- }
54
- interface ListItem {
55
- type: 'list_item';
56
- raw: string;
57
- task: boolean;
58
- checked?: boolean | undefined;
59
- loose: boolean;
60
- text: string;
61
- tokens?: Token[];
62
- }
63
- interface Paragraph {
64
- type: 'paragraph';
65
- raw: string;
66
- pre?: boolean | undefined;
67
- text: string;
68
- tokens: Token[];
69
- }
70
- interface HTML {
71
- type: 'html';
72
- raw: string;
73
- pre: boolean;
74
- text: string;
75
- block: boolean;
76
- }
77
- interface Text {
78
- type: 'text';
79
- raw: string;
80
- text: string;
1
+ declare module "Tokens" {
2
+ export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del) & {
3
+ loose?: boolean;
81
4
  tokens?: Token[];
5
+ };
6
+ export namespace Tokens {
7
+ interface Space {
8
+ type: 'space';
9
+ raw: string;
10
+ }
11
+ interface Code {
12
+ type: 'code';
13
+ raw: string;
14
+ codeBlockStyle?: 'indented' | undefined;
15
+ lang?: string | undefined;
16
+ text: string;
17
+ escaped?: boolean;
18
+ }
19
+ interface Heading {
20
+ type: 'heading';
21
+ raw: string;
22
+ depth: number;
23
+ text: string;
24
+ tokens: Token[];
25
+ }
26
+ interface Table {
27
+ type: 'table';
28
+ raw?: string;
29
+ align: Array<'center' | 'left' | 'right' | null>;
30
+ header: TableCell[];
31
+ rows: TableCell[][];
32
+ }
33
+ interface TableCell {
34
+ text: string;
35
+ tokens?: Token[];
36
+ }
37
+ interface Hr {
38
+ type: 'hr';
39
+ raw: string;
40
+ }
41
+ interface Blockquote {
42
+ type: 'blockquote';
43
+ raw: string;
44
+ text: string;
45
+ tokens: Token[];
46
+ }
47
+ interface List {
48
+ type: 'list';
49
+ raw: string;
50
+ ordered: boolean;
51
+ start: number | '';
52
+ loose: boolean;
53
+ items: ListItem[];
54
+ }
55
+ interface ListItem {
56
+ type: 'list_item';
57
+ raw: string;
58
+ task: boolean;
59
+ checked?: boolean | undefined;
60
+ loose: boolean;
61
+ text: string;
62
+ tokens?: Token[];
63
+ }
64
+ interface Paragraph {
65
+ type: 'paragraph';
66
+ raw: string;
67
+ pre?: boolean | undefined;
68
+ text: string;
69
+ tokens: Token[];
70
+ }
71
+ interface HTML {
72
+ type: 'html';
73
+ raw: string;
74
+ pre: boolean;
75
+ text: string;
76
+ block: boolean;
77
+ }
78
+ interface Text {
79
+ type: 'text';
80
+ raw: string;
81
+ text: string;
82
+ tokens?: Token[];
83
+ }
84
+ interface Def {
85
+ type: 'def';
86
+ raw: string;
87
+ tag: string;
88
+ href: string;
89
+ title: string;
90
+ }
91
+ interface Escape {
92
+ type: 'escape';
93
+ raw: string;
94
+ text: string;
95
+ }
96
+ interface Tag {
97
+ type: 'text' | 'html';
98
+ raw: string;
99
+ inLink: boolean;
100
+ inRawBlock: boolean;
101
+ text: string;
102
+ block: boolean;
103
+ }
104
+ interface Link {
105
+ type: 'link';
106
+ raw: string;
107
+ href: string;
108
+ title?: string | null;
109
+ text: string;
110
+ tokens: Token[];
111
+ }
112
+ interface Image {
113
+ type: 'image';
114
+ raw: string;
115
+ href: string;
116
+ title: string | null;
117
+ text: string;
118
+ }
119
+ interface Strong {
120
+ type: 'strong';
121
+ raw: string;
122
+ text: string;
123
+ tokens: Token[];
124
+ }
125
+ interface Em {
126
+ type: 'em';
127
+ raw: string;
128
+ text: string;
129
+ tokens: Token[];
130
+ }
131
+ interface Codespan {
132
+ type: 'codespan';
133
+ raw: string;
134
+ text: string;
135
+ }
136
+ interface Br {
137
+ type: 'br';
138
+ raw: string;
139
+ }
140
+ interface Del {
141
+ type: 'del';
142
+ raw: string;
143
+ text: string;
144
+ tokens: Token[];
145
+ }
146
+ interface Generic {
147
+ [index: string]: any;
148
+ type: string;
149
+ raw: string;
150
+ tokens?: Token[] | undefined;
151
+ }
82
152
  }
83
- interface Def {
84
- type: 'def';
85
- raw: string;
86
- tag: string;
87
- href: string;
88
- title: string;
89
- }
90
- interface Escape {
91
- type: 'escape';
92
- raw: string;
93
- text: string;
94
- }
95
- interface Tag {
96
- type: 'text' | 'html';
97
- raw: string;
98
- inLink: boolean;
99
- inRawBlock: boolean;
100
- text: string;
101
- block: boolean;
102
- }
103
- interface Link {
104
- type: 'link';
105
- raw: string;
106
- href: string;
107
- title?: string | null;
108
- text: string;
109
- tokens: Token[];
110
- }
111
- interface Image {
112
- type: 'image';
113
- raw: string;
114
- href: string;
115
- title: string | null;
116
- text: string;
117
- }
118
- interface Strong {
119
- type: 'strong';
120
- raw: string;
121
- text: string;
122
- tokens: Token[];
123
- }
124
- interface Em {
125
- type: 'em';
126
- raw: string;
127
- text: string;
128
- tokens: Token[];
129
- }
130
- interface Codespan {
131
- type: 'codespan';
132
- raw: string;
133
- text: string;
134
- }
135
- interface Br {
136
- type: 'br';
137
- raw: string;
138
- }
139
- interface Del {
140
- type: 'del';
141
- raw: string;
142
- text: string;
143
- tokens: Token[];
144
- }
145
- interface Generic {
146
- [index: string]: any;
147
- type: string;
148
- raw: string;
149
- tokens?: Token[] | undefined;
150
- }
151
- }
152
- type Links = Record<string, Pick<Tokens.Link | Tokens.Image, 'href' | 'title'>>;
153
- type TokensList = Token[] & {
154
- links: Links;
155
- };
156
-
157
- /**
158
- * Renderer
159
- */
160
- declare class _Renderer {
161
- options: MarkedOptions;
162
- constructor(options?: MarkedOptions);
163
- code(code: string, infostring: string | undefined, escaped: boolean): string;
164
- blockquote(quote: string): string;
165
- html(html: string, block?: boolean): string;
166
- heading(text: string, level: number, raw: string, slugger: _Slugger): string;
167
- hr(): string;
168
- list(body: string, ordered: boolean, start: number | ''): string;
169
- listitem(text: string, task: boolean, checked: boolean): string;
170
- checkbox(checked: boolean): string;
171
- paragraph(text: string): string;
172
- table(header: string, body: string): string;
173
- tablerow(content: string): string;
174
- tablecell(content: string, flags: {
175
- header: boolean;
176
- align: 'center' | 'left' | 'right' | null;
177
- }): string;
178
- /**
179
- * span level renderer
180
- */
181
- strong(text: string): string;
182
- em(text: string): string;
183
- codespan(text: string): string;
184
- br(): string;
185
- del(text: string): string;
186
- link(href: string, title: string | null | undefined, text: string): string;
187
- image(href: string, title: string | null, text: string): string;
188
- text(text: string): string;
189
- }
190
-
191
- /**
192
- * TextRenderer
193
- * returns only the textual part of the token
194
- */
195
- declare class _TextRenderer {
196
- strong(text: string): string;
197
- em(text: string): string;
198
- codespan(text: string): string;
199
- del(text: string): string;
200
- html(text: string): string;
201
- text(text: string): string;
202
- link(href: string, title: string | null | undefined, text: string): string;
203
- image(href: string, title: string | null, text: string): string;
204
- br(): string;
205
- }
206
-
207
- /**
208
- * Slugger generates header id
209
- */
210
- declare class _Slugger {
211
- seen: {
212
- [slugValue: string]: number;
153
+ export type Links = Record<string, Pick<Tokens.Link | Tokens.Image, 'href' | 'title'>>;
154
+ export type TokensList = Token[] & {
155
+ links: Links;
213
156
  };
214
- constructor();
215
- serialize(value: string): string;
216
- /**
217
- * Finds the next safe (unique) slug to use
218
- */
219
- getNextSafeSlug(originalSlug: string, isDryRun: boolean | undefined): string;
220
- /**
221
- * Convert string to unique id
222
- */
223
- slug(value: string, options?: SluggerOptions): string;
224
157
  }
225
-
226
- /**
227
- * Parsing & Compiling
228
- */
229
- declare class _Parser {
230
- options: MarkedOptions;
231
- renderer: _Renderer;
232
- textRenderer: _TextRenderer;
233
- slugger: _Slugger;
234
- constructor(options?: MarkedOptions);
235
- /**
236
- * Static Parse Method
237
- */
238
- static parse(tokens: Token[], options?: MarkedOptions): string;
239
- /**
240
- * Static Parse Inline Method
241
- */
242
- static parseInline(tokens: Token[], options?: MarkedOptions): string;
158
+ declare module "Tokenizer" {
159
+ import { _Lexer } from "Lexer";
160
+ import type { Links, Tokens } from "Tokens";
161
+ import type { MarkedOptions } from "MarkedOptions";
162
+ /**
163
+ * Tokenizer
164
+ */
165
+ export class _Tokenizer {
166
+ options: MarkedOptions;
167
+ rules: any;
168
+ lexer: _Lexer;
169
+ constructor(options?: MarkedOptions);
170
+ space(src: string): Tokens.Space | undefined;
171
+ code(src: string): Tokens.Code | undefined;
172
+ fences(src: string): Tokens.Code | undefined;
173
+ heading(src: string): Tokens.Heading | undefined;
174
+ hr(src: string): Tokens.Hr | undefined;
175
+ blockquote(src: string): Tokens.Blockquote | undefined;
176
+ list(src: string): Tokens.List | undefined;
177
+ html(src: string): Tokens.HTML | Tokens.Paragraph | undefined;
178
+ def(src: string): Tokens.Def | undefined;
179
+ table(src: string): Tokens.Table | undefined;
180
+ lheading(src: string): Tokens.Heading | undefined;
181
+ paragraph(src: string): Tokens.Paragraph | undefined;
182
+ text(src: string): Tokens.Text | undefined;
183
+ escape(src: string): Tokens.Escape | undefined;
184
+ tag(src: string): Tokens.Tag | undefined;
185
+ link(src: string): Tokens.Link | Tokens.Image | undefined;
186
+ reflink(src: string, links: Links): Tokens.Link | Tokens.Image | Tokens.Text | undefined;
187
+ emStrong(src: string, maskedSrc: string, prevChar?: string): Tokens.Em | Tokens.Strong | undefined;
188
+ codespan(src: string): Tokens.Codespan | undefined;
189
+ br(src: string): Tokens.Br | undefined;
190
+ del(src: string): Tokens.Del | undefined;
191
+ autolink(src: string, mangle: (cap: string) => string): Tokens.Link | undefined;
192
+ url(src: string, mangle: (cap: string) => string): Tokens.Link | undefined;
193
+ inlineText(src: string, smartypants: (cap: string) => string): Tokens.Text | undefined;
194
+ }
195
+ }
196
+ declare module "rules" {
197
+ export type Rule = RegExp | string;
198
+ export interface Rules {
199
+ [ruleName: string]: Pick<RegExp, 'exec'> | Rule | Rules;
200
+ }
201
+ type BlockRuleNames = 'newline' | 'code' | 'fences' | 'hr' | 'heading' | 'blockquote' | 'list' | 'html' | 'def' | 'lheading' | '_paragraph' | 'text' | '_label' | '_title' | 'bullet' | 'listItemStart' | '_tag' | '_comment' | 'paragraph' | 'uote';
202
+ type BlockSubRuleNames = 'normal' | 'gfm' | 'pedantic';
203
+ type InlineRuleNames = 'escape' | 'autolink' | 'tag' | 'link' | 'reflink' | 'nolink' | 'reflinkSearch' | 'code' | 'br' | 'text' | '_punctuation' | 'punctuation' | 'blockSkip' | 'escapedEmSt' | '_comment' | '_escapes' | '_scheme' | '_email' | '_attribute' | '_label' | '_href' | '_title' | 'strong' | '_extended_email' | '_backpedal';
204
+ type InlineSubRuleNames = 'gfm' | 'emStrong' | 'normal' | 'pedantic' | 'breaks';
243
205
  /**
244
- * Parse Loop
206
+ * Block-Level Grammar
245
207
  */
246
- parse(tokens: Token[], top?: boolean): string;
208
+ export const block: Record<BlockRuleNames, Rule> & Record<BlockSubRuleNames, Rules> & Rules;
247
209
  /**
248
- * Parse Inline Tokens
210
+ * Inline-Level Grammar
249
211
  */
250
- parseInline(tokens: Token[], renderer?: _Renderer | _TextRenderer): string;
251
- }
252
-
253
- /**
254
- * Tokenizer
255
- */
256
- declare class _Tokenizer {
257
- options: MarkedOptions;
258
- rules: any;
259
- lexer: _Lexer;
260
- constructor(options?: MarkedOptions);
261
- space(src: string): Tokens.Space | undefined;
262
- code(src: string): Tokens.Code | undefined;
263
- fences(src: string): Tokens.Code | undefined;
264
- heading(src: string): Tokens.Heading | undefined;
265
- hr(src: string): Tokens.Hr | undefined;
266
- blockquote(src: string): Tokens.Blockquote | undefined;
267
- list(src: string): Tokens.List | undefined;
268
- html(src: string): Tokens.HTML | Tokens.Paragraph | undefined;
269
- def(src: string): Tokens.Def | undefined;
270
- table(src: string): Tokens.Table | undefined;
271
- lheading(src: string): Tokens.Heading | undefined;
272
- paragraph(src: string): Tokens.Paragraph | undefined;
273
- text(src: string): Tokens.Text | undefined;
274
- escape(src: string): Tokens.Escape | undefined;
275
- tag(src: string): Tokens.Tag | undefined;
276
- link(src: string): Tokens.Link | Tokens.Image | undefined;
277
- reflink(src: string, links: Links): Tokens.Link | Tokens.Image | Tokens.Text | undefined;
278
- emStrong(src: string, maskedSrc: string, prevChar?: string): Tokens.Em | Tokens.Strong | undefined;
279
- codespan(src: string): Tokens.Codespan | undefined;
280
- br(src: string): Tokens.Br | undefined;
281
- del(src: string): Tokens.Del | undefined;
282
- autolink(src: string, mangle: (cap: string) => string): Tokens.Link | undefined;
283
- url(src: string, mangle: (cap: string) => string): Tokens.Link | undefined;
284
- inlineText(src: string, smartypants: (cap: string) => string): Tokens.Text | undefined;
212
+ export const inline: Record<InlineRuleNames, Rule> & Record<InlineSubRuleNames, Rules> & Rules;
285
213
  }
286
-
287
- interface SluggerOptions {
288
- /** Generates the next unique slug without updating the internal accumulator. */
289
- dryrun?: boolean;
290
- }
291
- interface TokenizerThis {
292
- lexer: _Lexer;
214
+ declare module "Lexer" {
215
+ import type { Token, TokensList } from "Tokens";
216
+ import type { MarkedOptions } from "MarkedOptions";
217
+ import type { Rules } from "rules";
218
+ /**
219
+ * Block Lexer
220
+ */
221
+ export class _Lexer {
222
+ tokens: TokensList;
223
+ options: MarkedOptions;
224
+ state: {
225
+ inLink: boolean;
226
+ inRawBlock: boolean;
227
+ top: boolean;
228
+ };
229
+ private tokenizer;
230
+ private inlineQueue;
231
+ constructor(options?: MarkedOptions);
232
+ /**
233
+ * Expose Rules
234
+ */
235
+ static get rules(): Rules;
236
+ /**
237
+ * Static Lex Method
238
+ */
239
+ static lex(src: string, options?: MarkedOptions): TokensList;
240
+ /**
241
+ * Static Lex Inline Method
242
+ */
243
+ static lexInline(src: string, options?: MarkedOptions): Token[];
244
+ /**
245
+ * Preprocessing
246
+ */
247
+ lex(src: string): TokensList;
248
+ /**
249
+ * Lexing
250
+ */
251
+ blockTokens(src: string, tokens?: Token[]): Token[];
252
+ blockTokens(src: string, tokens?: TokensList): TokensList;
253
+ inline(src: string, tokens?: Token[]): Token[];
254
+ /**
255
+ * Lexing/Compiling
256
+ */
257
+ inlineTokens(src: string, tokens?: Token[]): Token[];
258
+ }
293
259
  }
294
- interface TokenizerExtension {
295
- name: string;
296
- level: 'block' | 'inline';
297
- start?: ((this: TokenizerThis, src: string) => number | void) | undefined;
298
- tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic | void;
299
- childTokens?: string[] | undefined;
260
+ declare module "TextRenderer" {
261
+ /**
262
+ * TextRenderer
263
+ * returns only the textual part of the token
264
+ */
265
+ export class _TextRenderer {
266
+ strong(text: string): string;
267
+ em(text: string): string;
268
+ codespan(text: string): string;
269
+ del(text: string): string;
270
+ html(text: string): string;
271
+ text(text: string): string;
272
+ link(href: string, title: string | null | undefined, text: string): string;
273
+ image(href: string, title: string | null, text: string): string;
274
+ br(): string;
275
+ }
300
276
  }
301
- interface RendererThis {
302
- parser: _Parser;
277
+ declare module "Slugger" {
278
+ import type { SluggerOptions } from "MarkedOptions";
279
+ /**
280
+ * Slugger generates header id
281
+ */
282
+ export class _Slugger {
283
+ seen: {
284
+ [slugValue: string]: number;
285
+ };
286
+ constructor();
287
+ serialize(value: string): string;
288
+ /**
289
+ * Finds the next safe (unique) slug to use
290
+ */
291
+ getNextSafeSlug(originalSlug: string, isDryRun: boolean | undefined): string;
292
+ /**
293
+ * Convert string to unique id
294
+ */
295
+ slug(value: string, options?: SluggerOptions): string;
296
+ }
303
297
  }
304
- interface RendererExtension {
305
- name: string;
306
- renderer: (this: RendererThis, token: Tokens.Generic) => string | false | undefined;
298
+ declare module "Instance" {
299
+ import { _Lexer } from "Lexer";
300
+ import { _Parser } from "Parser";
301
+ import { _Hooks } from "Hooks";
302
+ import { _Renderer } from "Renderer";
303
+ import { _Tokenizer } from "Tokenizer";
304
+ import { _TextRenderer } from "TextRenderer";
305
+ import { _Slugger } from "Slugger";
306
+ import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
307
+ import type { Token, TokensList } from "Tokens";
308
+ export type ResultCallback = (error: Error | null, parseResult?: string) => undefined | void;
309
+ export class Marked {
310
+ #private;
311
+ defaults: MarkedOptions;
312
+ options: (opt: any) => this;
313
+ parse: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
314
+ parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
315
+ Parser: typeof _Parser;
316
+ parser: typeof _Parser.parse;
317
+ Renderer: typeof _Renderer;
318
+ TextRenderer: typeof _TextRenderer;
319
+ Lexer: typeof _Lexer;
320
+ lexer: typeof _Lexer.lex;
321
+ Tokenizer: typeof _Tokenizer;
322
+ Slugger: typeof _Slugger;
323
+ Hooks: typeof _Hooks;
324
+ constructor(...args: MarkedExtension[]);
325
+ /**
326
+ * Run callback for every token
327
+ */
328
+ walkTokens<T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]): T[];
329
+ use(...args: MarkedExtension[]): this;
330
+ setOptions(opt: any): this;
331
+ }
307
332
  }
308
- type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
309
- type RendererApi = Omit<_Renderer, 'constructor' | 'options'>;
310
- type RendererObject = {
311
- [K in keyof RendererApi]?: (...args: Parameters<RendererApi[K]>) => ReturnType<RendererApi[K]> | false;
312
- };
313
- type TokenizerApi = Omit<_Tokenizer, 'constructor' | 'options' | 'rules' | 'lexer'>;
314
- type TokenizerObject = {
315
- [K in keyof TokenizerApi]?: (...args: Parameters<TokenizerApi[K]>) => ReturnType<TokenizerApi[K]> | false;
316
- };
317
- interface MarkedExtension {
318
- /**
319
- * True will tell marked to await any walkTokens functions before parsing the tokens and returning an HTML string.
320
- */
321
- async?: boolean;
322
- /**
323
- * A prefix URL for any relative link.
324
- * @deprecated Deprecated in v5.0.0 use marked-base-url to prefix url for any relative link.
325
- */
326
- baseUrl?: string | undefined | null;
327
- /**
328
- * Enable GFM line breaks. This option requires the gfm option to be true.
329
- */
330
- breaks?: boolean | undefined;
331
- /**
332
- * Add tokenizers and renderers to marked
333
- */
334
- extensions?: TokenizerAndRendererExtension[] | undefined | null;
335
- /**
336
- * Enable GitHub flavored markdown.
337
- */
338
- gfm?: boolean | undefined;
339
- /**
340
- * Include an id attribute when emitting headings.
341
- * @deprecated Deprecated in v5.0.0 use marked-gfm-heading-id to include an id attribute when emitting headings (h1, h2, h3, etc).
342
- */
343
- headerIds?: boolean | undefined;
344
- /**
345
- * Set the prefix for header tag ids.
346
- * @deprecated Deprecated in v5.0.0 use marked-gfm-heading-id to add a string to prefix the id attribute when emitting headings (h1, h2, h3, etc).
347
- */
348
- headerPrefix?: string | undefined;
349
- /**
350
- * A function to highlight code blocks. The function can either be
351
- * synchronous (returning a string) or asynchronous (callback invoked
352
- * with an error if any occurred during highlighting and a string
353
- * if highlighting was successful)
354
- * @deprecated Deprecated in v5.0.0 use marked-highlight to add highlighting to code blocks.
355
- */
356
- highlight?: ((code: string, lang: string | undefined, callback?: (error: Error, code?: string) => void) => string | void) | null;
357
- /**
358
- * Hooks are methods that hook into some part of marked.
359
- * preprocess is called to process markdown before sending it to marked.
360
- * postprocess is called to process html after marked has finished parsing.
361
- */
362
- hooks?: {
363
- preprocess: (markdown: string) => string;
364
- postprocess: (html: string | undefined) => string | undefined;
365
- options?: MarkedOptions;
366
- } | null;
367
- /**
368
- * Set the prefix for code block classes.
369
- * @deprecated Deprecated in v5.0.0 use marked-highlight to prefix the className in a <code> block. Useful for syntax highlighting.
370
- */
371
- langPrefix?: string | undefined;
372
- /**
373
- * Mangle autolinks (<email@domain.com>).
374
- * @deprecated Deprecated in v5.0.0 use marked-mangle to mangle email addresses.
375
- */
376
- mangle?: boolean | undefined;
377
- /**
378
- * Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
379
- */
380
- pedantic?: boolean | undefined;
333
+ declare module "helpers" {
334
+ import type { MarkedOptions } from "MarkedOptions";
335
+ import type { ResultCallback } from "Instance";
336
+ import type { Rule } from "rules";
337
+ export function escape(html: string, encode?: boolean): string;
338
+ export function unescape(html: string): string;
339
+ export function edit(regex: Rule, opt?: string): {
340
+ replace: (name: string | RegExp, val: string | RegExp) => any;
341
+ getRegex: () => RegExp;
342
+ };
343
+ export function cleanUrl(sanitize: boolean | undefined, base: string | undefined | null, href: string): string | null;
344
+ export function resolveUrl(base: string, href: string): string;
345
+ export const noopTest: {
346
+ exec: () => null;
347
+ };
348
+ export function splitCells(tableRow: string, count: number): string[];
381
349
  /**
382
- * Type: object Default: new Renderer()
350
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
351
+ * /c*$/ is vulnerable to REDOS.
383
352
  *
384
- * An object containing functions to render tokens to HTML.
385
- */
386
- renderer?: RendererObject | undefined | null;
387
- /**
388
- * Sanitize the output. Ignore any HTML that has been input. If true, sanitize the HTML passed into markdownString with the sanitizer function.
389
- * @deprecated Warning: This feature is deprecated and it should NOT be used as it cannot be considered secure. Instead use a sanitize library, like DOMPurify (recommended), sanitize-html or insane on the output HTML!
390
- */
391
- sanitize?: boolean | undefined;
392
- /**
393
- * Optionally sanitize found HTML with a sanitizer function.
394
- * @deprecated A function to sanitize the HTML passed into markdownString.
395
- */
396
- sanitizer?: ((html: string) => string) | null;
397
- /**
398
- * Shows an HTML error message when rendering fails.
353
+ * @param str
354
+ * @param c
355
+ * @param invert Remove suffix of non-c chars instead. Default falsey.
399
356
  */
400
- silent?: boolean | undefined;
401
- /**
402
- * Use smarter list behavior than the original markdown. May eventually be default with the old behavior moved into pedantic.
403
- */
404
- smartLists?: boolean | undefined;
405
- /**
406
- * Use "smart" typograhic punctuation for things like quotes and dashes.
407
- * @deprecated Deprecated in v5.0.0 use marked-smartypants to use "smart" typographic punctuation for things like quotes and dashes.
408
- */
409
- smartypants?: boolean | undefined;
410
- /**
411
- * The tokenizer defines how to turn markdown text into tokens.
412
- */
413
- tokenizer?: TokenizerObject | undefined | null;
414
- /**
415
- * The walkTokens function gets called with every token.
416
- * Child tokens are called before moving on to sibling tokens.
417
- * Each token is passed by reference so updates are persisted when passed to the parser.
418
- * The return value of the function is ignored.
419
- */
420
- walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
421
- /**
422
- * Generate closing slash for self-closing tags (<br/> instead of <br>)
423
- * @deprecated Deprecated in v5.0.0 use marked-xhtml to emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.
424
- */
425
- xhtml?: boolean | undefined;
357
+ export function rtrim(str: string, c: string, invert?: boolean): string;
358
+ export function findClosingBracket(str: string, b: string): number;
359
+ export function checkDeprecations(opt: MarkedOptions, callback?: ResultCallback): void;
426
360
  }
427
- interface MarkedOptions extends Omit<MarkedExtension, 'extensions' | 'renderer' | 'tokenizer' | 'walkTokens'> {
428
- /**
429
- * Type: object Default: new Renderer()
361
+ declare module "marked" {
362
+ import { _Lexer } from "Lexer";
363
+ import { _Parser } from "Parser";
364
+ import { _Tokenizer } from "Tokenizer";
365
+ import { _Renderer } from "Renderer";
366
+ import { _TextRenderer } from "TextRenderer";
367
+ import { _Slugger } from "Slugger";
368
+ import { _Hooks } from "Hooks";
369
+ import { _getDefaults } from "defaults";
370
+ import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
371
+ import type { Token, TokensList } from "Tokens";
372
+ import type { ResultCallback } from "Instance";
373
+ /**
374
+ * Compiles markdown to HTML asynchronously.
430
375
  *
431
- * An object containing functions to render tokens to HTML.
376
+ * @param src String of markdown source to be compiled
377
+ * @param options Hash of options, having async: true
378
+ * @return Promise of string of compiled HTML
432
379
  */
433
- renderer?: Omit<_Renderer, 'constructor'> | undefined | null;
380
+ export function marked(src: string, options: MarkedOptions & {
381
+ async: true;
382
+ }): Promise<string>;
434
383
  /**
435
- * The tokenizer defines how to turn markdown text into tokens.
384
+ * Compiles markdown to HTML synchronously.
385
+ *
386
+ * @param src String of markdown source to be compiled
387
+ * @param options Optional hash of options
388
+ * @return String of compiled HTML
436
389
  */
437
- tokenizer?: Omit<_Tokenizer, 'constructor'> | undefined | null;
390
+ export function marked(src: string, options?: MarkedOptions): string;
438
391
  /**
439
- * The walkTokens function gets called with every token.
440
- * Child tokens are called before moving on to sibling tokens.
441
- * Each token is passed by reference so updates are persisted when passed to the parser.
442
- * The return value of the function is ignored.
392
+ * Compiles markdown to HTML asynchronously with a callback.
393
+ *
394
+ * @param src String of markdown source to be compiled
395
+ * @param callback Function called when the markdownString has been fully parsed when using async highlighting
443
396
  */
444
- walkTokens?: ((token: Token) => void | Promise<void> | Array<void | Promise<void>>) | undefined | null;
397
+ export function marked(src: string, callback: ResultCallback): void;
445
398
  /**
446
- * Add tokenizers and renderers to marked
399
+ * Compiles markdown to HTML asynchronously with a callback.
400
+ *
401
+ * @param src String of markdown source to be compiled
402
+ * @param options Hash of options
403
+ * @param callback Function called when the markdownString has been fully parsed when using async highlighting
447
404
  */
448
- extensions?: (TokenizerAndRendererExtension[] & {
449
- renderers: Record<string, (this: RendererThis, token: Tokens.Generic) => string | false | undefined>;
450
- childTokens: Record<string, string[]>;
451
- block: any[];
452
- inline: any[];
453
- startBlock: Array<(this: TokenizerThis, src: string) => number | void>;
454
- startInline: Array<(this: TokenizerThis, src: string) => number | void>;
455
- }) | undefined | null;
405
+ export function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
406
+ /**
407
+ * Compiles markdown to HTML asynchronously with a callback.
408
+ *
409
+ * @param src String of markdown source to be compiled
410
+ * @param options Hash of options
411
+ * @param callback Function called when the markdownString has been fully parsed when using async highlighting
412
+ */
413
+ export namespace marked {
414
+ var options: (options: MarkedOptions) => typeof marked;
415
+ var setOptions: (options: MarkedOptions) => typeof marked;
416
+ var getDefaults: typeof _getDefaults;
417
+ var defaults: MarkedOptions;
418
+ var use: (...args: MarkedExtension[]) => typeof marked;
419
+ var walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
420
+ var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
421
+ var Parser: typeof _Parser;
422
+ var parser: typeof _Parser.parse;
423
+ var Renderer: typeof _Renderer;
424
+ var TextRenderer: typeof _TextRenderer;
425
+ var Lexer: typeof _Lexer;
426
+ var lexer: typeof _Lexer.lex;
427
+ var Tokenizer: typeof _Tokenizer;
428
+ var Slugger: typeof _Slugger;
429
+ var Hooks: typeof _Hooks;
430
+ var parse: typeof marked;
431
+ }
432
+ export const options: (options: MarkedOptions) => typeof marked;
433
+ export const setOptions: (options: MarkedOptions) => typeof marked;
434
+ export const use: (...args: MarkedExtension[]) => typeof marked;
435
+ export const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
436
+ export const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
437
+ export const parse: typeof marked;
438
+ export const parser: typeof _Parser.parse;
439
+ export const lexer: typeof _Lexer.lex;
440
+ export { _defaults as defaults, _getDefaults as getDefaults } from "defaults";
441
+ export { _Lexer as Lexer } from "Lexer";
442
+ export { _Parser as Parser } from "Parser";
443
+ export { _Tokenizer as Tokenizer } from "Tokenizer";
444
+ export { _Renderer as Renderer } from "Renderer";
445
+ export { _TextRenderer as TextRenderer } from "TextRenderer";
446
+ export { _Slugger as Slugger } from "Slugger";
447
+ export { _Hooks as Hooks } from "Hooks";
448
+ export { Marked } from "Instance";
449
+ export type * from "MarkedOptions";
450
+ export type * from "rules";
451
+ export type * from "Tokens";
456
452
  }
457
-
458
- type Rule = RegExp | string;
459
- interface Rules {
460
- [ruleName: string]: Pick<RegExp, 'exec'> | Rule | Rules;
453
+ declare module "Renderer" {
454
+ import type { MarkedOptions } from "MarkedOptions";
455
+ import { Slugger } from "marked";
456
+ /**
457
+ * Renderer
458
+ */
459
+ export class _Renderer {
460
+ options: MarkedOptions;
461
+ constructor(options?: MarkedOptions);
462
+ code(code: string, infostring: string | undefined, escaped: boolean): string;
463
+ blockquote(quote: string): string;
464
+ html(html: string, block?: boolean): string;
465
+ heading(text: string, level: number, raw: string, slugger: Slugger): string;
466
+ hr(): string;
467
+ list(body: string, ordered: boolean, start: number | ''): string;
468
+ listitem(text: string, task: boolean, checked: boolean): string;
469
+ checkbox(checked: boolean): string;
470
+ paragraph(text: string): string;
471
+ table(header: string, body: string): string;
472
+ tablerow(content: string): string;
473
+ tablecell(content: string, flags: {
474
+ header: boolean;
475
+ align: 'center' | 'left' | 'right' | null;
476
+ }): string;
477
+ /**
478
+ * span level renderer
479
+ */
480
+ strong(text: string): string;
481
+ em(text: string): string;
482
+ codespan(text: string): string;
483
+ br(): string;
484
+ del(text: string): string;
485
+ link(href: string, title: string | null | undefined, text: string): string;
486
+ image(href: string, title: string | null, text: string): string;
487
+ text(text: string): string;
488
+ }
461
489
  }
462
- type BlockRuleNames = 'newline' | 'code' | 'fences' | 'hr' | 'heading' | 'blockquote' | 'list' | 'html' | 'def' | 'lheading' | '_paragraph' | 'text' | '_label' | '_title' | 'bullet' | 'listItemStart' | '_tag' | '_comment' | 'paragraph' | 'uote';
463
- type BlockSubRuleNames = 'normal' | 'gfm' | 'pedantic';
464
- type InlineRuleNames = 'escape' | 'autolink' | 'tag' | 'link' | 'reflink' | 'nolink' | 'reflinkSearch' | 'code' | 'br' | 'text' | '_punctuation' | 'punctuation' | 'blockSkip' | 'escapedEmSt' | '_comment' | '_escapes' | '_scheme' | '_email' | '_attribute' | '_label' | '_href' | '_title' | 'strong' | '_extended_email' | '_backpedal';
465
- type InlineSubRuleNames = 'gfm' | 'emStrong' | 'normal' | 'pedantic' | 'breaks';
466
- /**
467
- * Block-Level Grammar
468
- */
469
- declare const block: Record<BlockRuleNames, Rule> & Record<BlockSubRuleNames, Rules> & Rules;
470
- /**
471
- * Inline-Level Grammar
472
- */
473
- declare const inline: Record<InlineRuleNames, Rule> & Record<InlineSubRuleNames, Rules> & Rules;
474
-
475
- /**
476
- * Block Lexer
477
- */
478
- declare class _Lexer {
479
- tokens: TokensList;
480
- options: MarkedOptions;
481
- state: {
482
- inLink: boolean;
483
- inRawBlock: boolean;
484
- top: boolean;
485
- };
486
- private tokenizer;
487
- private inlineQueue;
488
- constructor(options?: MarkedOptions);
489
- /**
490
- * Expose Rules
491
- */
492
- static get rules(): Rules;
493
- /**
494
- * Static Lex Method
495
- */
496
- static lex(src: string, options?: MarkedOptions): TokensList;
497
- /**
498
- * Static Lex Inline Method
499
- */
500
- static lexInline(src: string, options?: MarkedOptions): Token[];
501
- /**
502
- * Preprocessing
503
- */
504
- lex(src: string): TokensList;
505
- /**
506
- * Lexing
507
- */
508
- blockTokens(src: string, tokens?: Token[]): Token[];
509
- blockTokens(src: string, tokens?: TokensList): TokensList;
510
- inline(src: string, tokens?: Token[]): Token[];
511
- /**
512
- * Lexing/Compiling
513
- */
514
- inlineTokens(src: string, tokens?: Token[]): Token[];
490
+ declare module "Parser" {
491
+ import { _Renderer } from "Renderer";
492
+ import { _TextRenderer } from "TextRenderer";
493
+ import { _Slugger } from "Slugger";
494
+ import type { Token } from "Tokens";
495
+ import type { MarkedOptions } from "MarkedOptions";
496
+ /**
497
+ * Parsing & Compiling
498
+ */
499
+ export class _Parser {
500
+ options: MarkedOptions;
501
+ renderer: _Renderer;
502
+ textRenderer: _TextRenderer;
503
+ slugger: _Slugger;
504
+ constructor(options?: MarkedOptions);
505
+ /**
506
+ * Static Parse Method
507
+ */
508
+ static parse(tokens: Token[], options?: MarkedOptions): string;
509
+ /**
510
+ * Static Parse Inline Method
511
+ */
512
+ static parseInline(tokens: Token[], options?: MarkedOptions): string;
513
+ /**
514
+ * Parse Loop
515
+ */
516
+ parse(tokens: Token[], top?: boolean): string;
517
+ /**
518
+ * Parse Inline Tokens
519
+ */
520
+ parseInline(tokens: Token[], renderer?: _Renderer | _TextRenderer): string;
521
+ }
515
522
  }
516
-
517
- declare class _Hooks {
518
- options: MarkedOptions;
519
- constructor(options?: MarkedOptions);
520
- static passThroughHooks: Set<string>;
521
- /**
522
- * Process markdown before marked
523
- */
524
- preprocess(markdown: string): string;
525
- /**
526
- * Process HTML after marked is finished
527
- */
528
- postprocess(html: string | undefined): string | undefined;
523
+ declare module "MarkedOptions" {
524
+ import type { Token, Tokens, TokensList } from "Tokens";
525
+ import { _Parser } from "Parser";
526
+ import { _Lexer } from "Lexer";
527
+ import { _Renderer } from "Renderer";
528
+ import { _Tokenizer } from "Tokenizer";
529
+ export interface SluggerOptions {
530
+ /** Generates the next unique slug without updating the internal accumulator. */
531
+ dryrun?: boolean;
532
+ }
533
+ export interface TokenizerThis {
534
+ lexer: _Lexer;
535
+ }
536
+ export interface TokenizerExtension {
537
+ name: string;
538
+ level: 'block' | 'inline';
539
+ start?: ((this: TokenizerThis, src: string) => number | void) | undefined;
540
+ tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic | void;
541
+ childTokens?: string[] | undefined;
542
+ }
543
+ export interface RendererThis {
544
+ parser: _Parser;
545
+ }
546
+ export interface RendererExtension {
547
+ name: string;
548
+ renderer: (this: RendererThis, token: Tokens.Generic) => string | false | undefined;
549
+ }
550
+ export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
551
+ type RendererApi = Omit<_Renderer, 'constructor' | 'options'>;
552
+ type RendererObject = {
553
+ [K in keyof RendererApi]?: (...args: Parameters<RendererApi[K]>) => ReturnType<RendererApi[K]> | false;
554
+ };
555
+ type TokenizerApi = Omit<_Tokenizer, 'constructor' | 'options' | 'rules' | 'lexer'>;
556
+ type TokenizerObject = {
557
+ [K in keyof TokenizerApi]?: (...args: Parameters<TokenizerApi[K]>) => ReturnType<TokenizerApi[K]> | false;
558
+ };
559
+ export interface MarkedExtension {
560
+ /**
561
+ * True will tell marked to await any walkTokens functions before parsing the tokens and returning an HTML string.
562
+ */
563
+ async?: boolean;
564
+ /**
565
+ * A prefix URL for any relative link.
566
+ * @deprecated Deprecated in v5.0.0 use marked-base-url to prefix url for any relative link.
567
+ */
568
+ baseUrl?: string | undefined | null;
569
+ /**
570
+ * Enable GFM line breaks. This option requires the gfm option to be true.
571
+ */
572
+ breaks?: boolean | undefined;
573
+ /**
574
+ * Add tokenizers and renderers to marked
575
+ */
576
+ extensions?: TokenizerAndRendererExtension[] | undefined | null;
577
+ /**
578
+ * Enable GitHub flavored markdown.
579
+ */
580
+ gfm?: boolean | undefined;
581
+ /**
582
+ * Include an id attribute when emitting headings.
583
+ * @deprecated Deprecated in v5.0.0 use marked-gfm-heading-id to include an id attribute when emitting headings (h1, h2, h3, etc).
584
+ */
585
+ headerIds?: boolean | undefined;
586
+ /**
587
+ * Set the prefix for header tag ids.
588
+ * @deprecated Deprecated in v5.0.0 use marked-gfm-heading-id to add a string to prefix the id attribute when emitting headings (h1, h2, h3, etc).
589
+ */
590
+ headerPrefix?: string | undefined;
591
+ /**
592
+ * A function to highlight code blocks. The function can either be
593
+ * synchronous (returning a string) or asynchronous (callback invoked
594
+ * with an error if any occurred during highlighting and a string
595
+ * if highlighting was successful)
596
+ * @deprecated Deprecated in v5.0.0 use marked-highlight to add highlighting to code blocks.
597
+ */
598
+ highlight?: ((code: string, lang: string | undefined, callback?: (error: Error, code?: string) => void) => string | void) | null;
599
+ /**
600
+ * Hooks are methods that hook into some part of marked.
601
+ * preprocess is called to process markdown before sending it to marked.
602
+ * postprocess is called to process html after marked has finished parsing.
603
+ */
604
+ hooks?: {
605
+ preprocess: (markdown: string) => string;
606
+ postprocess: (html: string | undefined) => string | undefined;
607
+ options?: MarkedOptions;
608
+ } | null;
609
+ /**
610
+ * Set the prefix for code block classes.
611
+ * @deprecated Deprecated in v5.0.0 use marked-highlight to prefix the className in a <code> block. Useful for syntax highlighting.
612
+ */
613
+ langPrefix?: string | undefined;
614
+ /**
615
+ * Mangle autolinks (<email@domain.com>).
616
+ * @deprecated Deprecated in v5.0.0 use marked-mangle to mangle email addresses.
617
+ */
618
+ mangle?: boolean | undefined;
619
+ /**
620
+ * Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
621
+ */
622
+ pedantic?: boolean | undefined;
623
+ /**
624
+ * Type: object Default: new Renderer()
625
+ *
626
+ * An object containing functions to render tokens to HTML.
627
+ */
628
+ renderer?: RendererObject | undefined | null;
629
+ /**
630
+ * Sanitize the output. Ignore any HTML that has been input. If true, sanitize the HTML passed into markdownString with the sanitizer function.
631
+ * @deprecated Warning: This feature is deprecated and it should NOT be used as it cannot be considered secure. Instead use a sanitize library, like DOMPurify (recommended), sanitize-html or insane on the output HTML!
632
+ */
633
+ sanitize?: boolean | undefined;
634
+ /**
635
+ * Optionally sanitize found HTML with a sanitizer function.
636
+ * @deprecated A function to sanitize the HTML passed into markdownString.
637
+ */
638
+ sanitizer?: ((html: string) => string) | null;
639
+ /**
640
+ * Shows an HTML error message when rendering fails.
641
+ */
642
+ silent?: boolean | undefined;
643
+ /**
644
+ * Use smarter list behavior than the original markdown. May eventually be default with the old behavior moved into pedantic.
645
+ */
646
+ smartLists?: boolean | undefined;
647
+ /**
648
+ * Use "smart" typograhic punctuation for things like quotes and dashes.
649
+ * @deprecated Deprecated in v5.0.0 use marked-smartypants to use "smart" typographic punctuation for things like quotes and dashes.
650
+ */
651
+ smartypants?: boolean | undefined;
652
+ /**
653
+ * The tokenizer defines how to turn markdown text into tokens.
654
+ */
655
+ tokenizer?: TokenizerObject | undefined | null;
656
+ /**
657
+ * The walkTokens function gets called with every token.
658
+ * Child tokens are called before moving on to sibling tokens.
659
+ * Each token is passed by reference so updates are persisted when passed to the parser.
660
+ * The return value of the function is ignored.
661
+ */
662
+ walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
663
+ /**
664
+ * Generate closing slash for self-closing tags (<br/> instead of <br>)
665
+ * @deprecated Deprecated in v5.0.0 use marked-xhtml to emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.
666
+ */
667
+ xhtml?: boolean | undefined;
668
+ }
669
+ export interface MarkedOptions extends Omit<MarkedExtension, 'extensions' | 'renderer' | 'tokenizer' | 'walkTokens'> {
670
+ /**
671
+ * Type: object Default: new Renderer()
672
+ *
673
+ * An object containing functions to render tokens to HTML.
674
+ */
675
+ renderer?: Omit<_Renderer, 'constructor'> | undefined | null;
676
+ /**
677
+ * The tokenizer defines how to turn markdown text into tokens.
678
+ */
679
+ tokenizer?: Omit<_Tokenizer, 'constructor'> | undefined | null;
680
+ /**
681
+ * The walkTokens function gets called with every token.
682
+ * Child tokens are called before moving on to sibling tokens.
683
+ * Each token is passed by reference so updates are persisted when passed to the parser.
684
+ * The return value of the function is ignored.
685
+ */
686
+ walkTokens?: ((token: Token) => void | Promise<void> | Array<void | Promise<void>>) | undefined | null;
687
+ /**
688
+ * Add tokenizers and renderers to marked
689
+ */
690
+ extensions?: (TokenizerAndRendererExtension[] & {
691
+ renderers: Record<string, (this: RendererThis, token: Tokens.Generic) => string | false | undefined>;
692
+ childTokens: Record<string, string[]>;
693
+ block: any[];
694
+ inline: any[];
695
+ startBlock: Array<(this: TokenizerThis, src: string) => number | void>;
696
+ startInline: Array<(this: TokenizerThis, src: string) => number | void>;
697
+ }) | undefined | null;
698
+ }
529
699
  }
530
-
531
- type ResultCallback$1 = (error: Error | null, parseResult?: string) => undefined | void;
532
- declare class Marked {
533
- #private;
534
- defaults: MarkedOptions;
535
- options: (opt: any) => this;
536
- parse: (src: string, optOrCallback?: MarkedOptions | ResultCallback$1 | undefined | null, callback?: ResultCallback$1 | undefined) => string | Promise<string | undefined> | undefined;
537
- parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback$1 | undefined | null, callback?: ResultCallback$1 | undefined) => string | Promise<string | undefined> | undefined;
538
- Parser: typeof _Parser;
539
- parser: typeof _Parser.parse;
540
- Renderer: typeof _Renderer;
541
- TextRenderer: typeof _TextRenderer;
542
- Lexer: typeof _Lexer;
543
- lexer: typeof _Lexer.lex;
544
- Tokenizer: typeof _Tokenizer;
545
- Slugger: typeof _Slugger;
546
- Hooks: typeof _Hooks;
547
- constructor(...args: MarkedExtension[]);
700
+ declare module "defaults" {
701
+ import type { MarkedOptions } from "MarkedOptions";
548
702
  /**
549
- * Run callback for every token
703
+ * Gets the original marked default options.
550
704
  */
551
- walkTokens<T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]): T[];
552
- use(...args: MarkedExtension[]): this;
553
- setOptions(opt: any): this;
705
+ export function _getDefaults(): MarkedOptions;
706
+ export let _defaults: MarkedOptions;
707
+ export function changeDefaults(newDefaults: MarkedOptions): void;
554
708
  }
555
-
556
- /**
557
- * Gets the original marked default options.
558
- */
559
- declare function _getDefaults(): MarkedOptions;
560
- declare let _defaults: MarkedOptions;
561
-
562
- type ResultCallback = (error: Error | null, parseResult?: string) => undefined | void;
563
- /**
564
- * Compiles markdown to HTML asynchronously.
565
- *
566
- * @param src String of markdown source to be compiled
567
- * @param options Hash of options, having async: true
568
- * @return Promise of string of compiled HTML
569
- */
570
- declare function marked(src: string, options: MarkedOptions & {
571
- async: true;
572
- }): Promise<string>;
573
- /**
574
- * Compiles markdown to HTML synchronously.
575
- *
576
- * @param src String of markdown source to be compiled
577
- * @param options Optional hash of options
578
- * @return String of compiled HTML
579
- */
580
- declare function marked(src: string, options?: MarkedOptions): string;
581
- /**
582
- * Compiles markdown to HTML asynchronously with a callback.
583
- *
584
- * @param src String of markdown source to be compiled
585
- * @param callback Function called when the markdownString has been fully parsed when using async highlighting
586
- */
587
- declare function marked(src: string, callback: ResultCallback): void;
588
- /**
589
- * Compiles markdown to HTML asynchronously with a callback.
590
- *
591
- * @param src String of markdown source to be compiled
592
- * @param options Hash of options
593
- * @param callback Function called when the markdownString has been fully parsed when using async highlighting
594
- */
595
- declare function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
596
- declare namespace marked {
597
- var options: (options: MarkedOptions) => typeof marked;
598
- var setOptions: (options: MarkedOptions) => typeof marked;
599
- var getDefaults: typeof _getDefaults;
600
- var defaults: MarkedOptions;
601
- var use: (...args: MarkedExtension[]) => typeof marked;
602
- var walkTokens: <T = void>(tokens: TokensList | Token[], callback: (token: Token) => T | T[]) => T[];
603
- var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback$1 | null | undefined, callback?: ResultCallback$1 | undefined) => string | Promise<string | undefined> | undefined;
604
- var Parser: typeof _Parser;
605
- var parser: typeof _Parser.parse;
606
- var Renderer: typeof _Renderer;
607
- var TextRenderer: typeof _TextRenderer;
608
- var Lexer: typeof _Lexer;
609
- var lexer: typeof _Lexer.lex;
610
- var Tokenizer: typeof _Tokenizer;
611
- var Slugger: typeof _Slugger;
612
- var Hooks: typeof _Hooks;
613
- var parse: typeof marked;
709
+ declare module "Hooks" {
710
+ import type { MarkedOptions } from "MarkedOptions";
711
+ export class _Hooks {
712
+ options: MarkedOptions;
713
+ constructor(options?: MarkedOptions);
714
+ static passThroughHooks: Set<string>;
715
+ /**
716
+ * Process markdown before marked
717
+ */
718
+ preprocess(markdown: string): string;
719
+ /**
720
+ * Process HTML after marked is finished
721
+ */
722
+ postprocess(html: string | undefined): string | undefined;
723
+ }
614
724
  }
615
- declare const options: (options: MarkedOptions) => typeof marked;
616
- declare const setOptions: (options: MarkedOptions) => typeof marked;
617
- declare const use: (...args: MarkedExtension[]) => typeof marked;
618
- declare const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
619
- declare const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback$1 | null | undefined, callback?: ResultCallback$1 | undefined) => string | Promise<string | undefined> | undefined;
620
- declare const parse: typeof marked;
621
- declare const parser: typeof _Parser.parse;
622
- declare const lexer: typeof _Lexer.lex;
623
-
624
- export { _Hooks as Hooks, _Lexer as Lexer, Links, Marked, MarkedExtension, MarkedOptions, _Parser as Parser, _Renderer as Renderer, RendererExtension, RendererThis, ResultCallback, Rule, Rules, _Slugger as Slugger, SluggerOptions, _TextRenderer as TextRenderer, Token, _Tokenizer as Tokenizer, TokenizerAndRendererExtension, TokenizerExtension, TokenizerThis, Tokens, TokensList, block, _defaults as defaults, _getDefaults as getDefaults, inline, lexer, marked, options, parse, parseInline, parser, setOptions, use, walkTokens };