-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathHooks.ts
More file actions
69 lines (59 loc) · 1.54 KB
/
Copy pathHooks.ts
File metadata and controls
69 lines (59 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { _defaults } from './defaults.ts';
import { _Lexer } from './Lexer.ts';
import { _Parser } from './Parser.ts';
import type { MarkedOptions } from './MarkedOptions.ts';
import type { Token, TokensList } from './Tokens.ts';
export class _Hooks<ParserOutput = string, RendererOutput = string> {
options: MarkedOptions<ParserOutput, RendererOutput>;
block?: boolean;
constructor(options?: MarkedOptions<ParserOutput, RendererOutput>) {
this.options = options || _defaults;
}
static passThroughHooks = new Set([
'preprocess',
'postprocess',
'processAllTokens',
'emStrongMask',
]);
static passThroughHooksRespectAsync = new Set([
'preprocess',
'postprocess',
'processAllTokens',
]);
/**
* Process markdown before marked
*/
preprocess(markdown: string) {
return markdown;
}
/**
* Process HTML after marked is finished
*/
postprocess(html: ParserOutput) {
return html;
}
/**
* Process all tokens before walk tokens
*/
processAllTokens(tokens: Token[] | TokensList) {
return tokens;
}
/**
* Mask contents that should not be interpreted as em/strong delimiters
*/
emStrongMask(src: string) {
return src;
}
/**
* Provide function to tokenize markdown
*/
provideLexer(block = this.block) {
return block ? _Lexer.lex : _Lexer.lexInline;
}
/**
* Provide function to parse tokens
*/
provideParser(block = this.block) {
return block ? _Parser.parse<ParserOutput, RendererOutput> : _Parser.parseInline<ParserOutput, RendererOutput>;
}
}