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