-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathmarked.ts
More file actions
166 lines (151 loc) · 5.41 KB
/
Copy pathmarked.ts
File metadata and controls
166 lines (151 loc) · 5.41 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { _Lexer } from './Lexer.ts';
import { _Parser } from './Parser.ts';
import { _Tokenizer } from './Tokenizer.ts';
import { _Renderer } from './Renderer.ts';
import { _TextRenderer } from './TextRenderer.ts';
import { _Hooks } from './Hooks.ts';
import { Marked } from './Instance.ts';
import {
_getDefaults,
changeDefaults,
_defaults,
} from './defaults.ts';
import type { MarkedExtension, MarkedOptions } from './MarkedOptions.ts';
import type { Token, TokensList } from './Tokens.ts';
import type { MaybePromise } from './Instance.ts';
const markedInstance = new Marked();
/**
* Compiles markdown to HTML asynchronously.
*
* To configure hooks, a renderer, or a tokenizer, create a `Marked` instance
* and use `Marked#use` instead of passing them as options on each call.
*
* @param src String of markdown source to be compiled
* @param options Hash of options, having async: true
* @return Promise of string of compiled HTML
*/
export function marked(src: string, options: MarkedOptions & { async: true }): Promise<string>;
/**
* Compiles markdown to HTML.
*
* To configure hooks, a renderer, or a tokenizer, create a `Marked` instance
* and use `Marked#use` instead of passing them as options on each call.
*
* @param src String of markdown source to be compiled
* @param options Optional hash of options
* @return String of compiled HTML. Will be a Promise of string if async is set to true by any extensions.
*/
export function marked(src: string, options: MarkedOptions & { async: false }): string;
export function marked(src: string, options: MarkedOptions & { async: true }): Promise<string>;
export function marked(src: string, options?: MarkedOptions | null): string | Promise<string>;
export function marked(src: string, opt?: MarkedOptions | null): string | Promise<string> {
return markedInstance.parse(src, opt);
}
export declare namespace marked {
/**
* Compiles inline markdown to HTML.
*
* To configure hooks, a renderer, or a tokenizer, create a `Marked` instance
* and use `Marked#use` instead of passing them as options on each call.
*/
let parseInline: typeof markedInstance.parseInline;
/**
* Registers extensions with the default Marked instance.
*
* The `renderer`, `tokenizer`, and `hooks` objects may each contain only the
* methods that should be overridden. Their methods are merged with built-in
* behavior and extensions registered by earlier calls.
*
* Use this function when supplying only some hook methods.
*/
let use: (...args: MarkedExtension[]) => typeof marked;
}
/**
* Sets the default options.
*
* @param options Hash of options
*/
marked.options =
marked.setOptions = function(options: MarkedOptions) {
markedInstance.setOptions(options);
marked.defaults = markedInstance.defaults;
changeDefaults(marked.defaults);
return marked;
};
/**
* Gets the original marked default options.
*/
marked.getDefaults = _getDefaults;
marked.defaults = _defaults;
/**
* Registers extensions with the default Marked instance.
*
* The `renderer`, `tokenizer`, and `hooks` objects may each contain only the
* methods that should be overridden. Their methods are merged with built-in
* behavior and extensions registered by earlier calls.
*
* Use this function when supplying only some hook methods.
*
* @param args Extensions to register
* @return The `marked` function
*/
function useExtension(...args: MarkedExtension[]) {
markedInstance.use(...args);
marked.defaults = markedInstance.defaults;
changeDefaults(marked.defaults);
return marked;
}
marked.use = useExtension;
/**
* Run callback for every token
*/
marked.walkTokens = function(tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) {
return markedInstance.walkTokens(tokens, callback);
};
/**
* Compiles markdown to HTML without enclosing `p` tag.
*
* To configure hooks, a renderer, or a tokenizer, create a `Marked` instance
* and use `Marked#use` instead of passing them as options on each call.
*
* @param src String of markdown source to be compiled
* @param options Hash of options
* @return String of compiled HTML
*/
marked.parseInline = markedInstance.parseInline;
/**
* Expose
*/
marked.Parser = _Parser;
marked.parser = _Parser.parse;
marked.Renderer = _Renderer;
marked.TextRenderer = _TextRenderer;
marked.Lexer = _Lexer;
marked.lexer = _Lexer.lex;
marked.Tokenizer = _Tokenizer;
marked.Hooks = _Hooks;
marked.parse = marked;
export const options = marked.options;
export const setOptions = marked.setOptions;
export const walkTokens = marked.walkTokens;
/**
* Compiles inline markdown to HTML.
*
* To configure hooks, a renderer, or a tokenizer, create a `Marked` instance
* and use `Marked#use` instead of passing them as options on each call.
*/
export const parseInline = marked.parseInline;
export const parse = marked;
export const parser = _Parser.parse;
export const lexer = _Lexer.lex;
export { _defaults as defaults, _getDefaults as getDefaults } from './defaults.ts';
export { _Lexer as Lexer } from './Lexer.ts';
export { _Parser as Parser } from './Parser.ts';
export { _Tokenizer as Tokenizer } from './Tokenizer.ts';
export { _Renderer as Renderer } from './Renderer.ts';
export { _TextRenderer as TextRenderer } from './TextRenderer.ts';
export { _Hooks as Hooks } from './Hooks.ts';
export { Marked } from './Instance.ts';
export { useExtension as use };
export type * from './MarkedOptions.ts';
export type * from './Tokens.ts';