-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd4w.d.ts
209 lines (197 loc) · 5.65 KB
/
md4w.d.ts
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* ParseFlags is a set of flags for md4c parser.
*/
export enum ParseFlags {
/** Collapse non-trivial whitespace into single space. */
COLLAPSE_WHITESPACE,
/** Do not require space in ATX headers ( ###header ) */
PERMISSIVE_ATX_HEADERS,
/** Recognize URLs as links. */
PERMISSIVE_URL_AUTO_LINKS,
/** Recognize e-mails as links.*/
PERMISSIVE_EMAIL_AUTO_LINKS,
/** Disable indented code blocks. (Only fenced code works.) */
NO_INDENTED_CODE_BLOCKS,
/** Disable raw HTML blocks. */
NO_HTML_BLOCKS,
/** Disable raw HTML (inline). */
NO_HTML_SPANS,
/** Support GitHub-style tables. */
TABLES,
/** Support strike-through spans (text enclosed in tilde marks, e.g. ~foo bar~). */
STRIKETHROUGH,
/** Support WWW autolinks (without proto; just 'www.') */
PERMISSIVE_WWW_AUTO_LINKS,
/** Support GitHub-style task lists. */
TASKLISTS,
/** Support LaTeX math spans ($...$) and LaTeX display math spans ($$...$$) are supported. (Note though that the HTML renderer outputs them verbatim in a custom tag <x-equation>.) */
LATEX_MATH_SPANS,
/** Support wiki-style links ([[link label]] and [[target article|link label]]) are supported. (Note that the HTML renderer outputs them in a custom tag <x-wikilink>.) */
WIKI_LINKS,
/** Denotes an underline instead of an ordinary emphasis or strong emphasis. */
UNDERLINE,
/** Using hard line breaks. */
HARD_SOFT_BREAKS,
/** Shorthand for NO_HTML_BLOCKS | NO_HTML_SPANS */
NO_HTML,
/** Default flags COLLAPSE_WHITESPACE | PERMISSIVE_ATX_HEADERS | PERMISSIVE_URL_AUTO_LINKS | STRIKETHROUGH | TABLES | TASK_LISTS */
DEFAULT,
}
/**
* Options for md4w.
*/
export interface Options {
/** parse flags for the md4c parser. */
parseFlags?:
| number
| Partial<Record<keyof typeof ParseFlags, true>>
| Array<keyof typeof ParseFlags>;
/** buffer size for the stream API. */
bufferSize?: number;
}
/**
* Converts markdown to html.
* @param {string | Uint8Array} input markdown input
* @param {Options} options
* @returns {string} html output
*/
export function mdToHtml(input: string | Uint8Array, options?: Options): string;
/**
* Converts markdown to html as a readable stream.
* @param {string | Uint8Array} input markdown input
* @param {Options} options
* @returns {ReadableStream<Uint8Array>} readable stream of html output
*/
export function mdToReadableHtml(
input: string | Uint8Array,
options?: Options,
): ReadableStream<Uint8Array>;
/**
* NodeType is a type of the markdown node.
*/
export enum NodeType {
QUOTE = 1,
UL = 2,
OL = 3,
LI = 4,
HR = 5,
CODE_BLOCK = 7,
HTML = 8,
P = 9,
TABLE = 10,
THEAD = 11,
TBODY = 12,
TR = 13,
TH = 14,
TD = 15,
H1 = 21,
H2 = 22,
H3 = 23,
H4 = 24,
H5 = 25,
H6 = 26,
EM = 30,
STRONG = 31,
A = 32,
IMG = 33,
CODE_SPAN = 34,
DEL = 35,
LATEXMATH = 36,
LATEXMATH_DISPLAY = 37,
WIKILINK = 38,
U = 39,
}
/**
* NodeProps is a type of the node properties.
*/
export type NodeProps<T> = Record<string, undefined> & T;
/**
* MDNode is a node in the markdown tree.
*/
export type MDNode = {
readonly type: Exclude<
number,
| NodeType.CODE_BLOCK
| NodeType.OL
| NodeType.LI
| NodeType.TH
| NodeType.TD
| NodeType.HR
| NodeType.A
| NodeType.IMG
| NodeType.WIKILINK
>;
readonly props?: Record<string, undefined>;
readonly children?: readonly (string | MDNode)[];
} | {
readonly type: NodeType.CODE_BLOCK;
readonly props?: NodeProps<{ lang: string }>;
readonly children: readonly string[];
} | {
readonly type: NodeType.OL;
readonly props?: NodeProps<{ start: number }>;
readonly children: readonly (string | MDNode)[];
} | {
readonly type: NodeType.LI;
readonly props?: NodeProps<{ isTask: boolean; done: boolean }>;
readonly children: readonly (string | MDNode)[];
} | {
readonly type: NodeType.TH | NodeType.TD;
readonly props: NodeProps<{ align: "left" | "center" | "right" | "" }>;
readonly children: readonly (string | MDNode)[];
} | {
readonly type: NodeType.HR;
readonly props: undefined;
readonly children: undefined;
} | {
readonly type: NodeType.A;
readonly props: NodeProps<{ href: string; title?: string }>;
readonly children: readonly (string | MDNode)[];
} | {
readonly type: NodeType.IMG;
readonly props: NodeProps<{ src: string; alt: string; title?: string }>;
readonly children: undefined;
} | {
readonly type: NodeType.WIKILINK;
readonly props: NodeProps<{ target: string }>;
readonly children: readonly (string | MDNode)[];
};
/**
* MDTree is a parsed markdown tree.
*/
export interface MDTree {
readonly children: MDNode[];
}
/**
* Converts markdown to json.
* @param {string | Uint8Array} input markdown input
* @param {Options} options parse options
* @returns {MDTree} json output
*/
export function mdToJSON(input: string | Uint8Array, options?: Options): MDTree;
/**
* Code highlighter interface.
*/
export interface CodeHighlighter {
(language: string, code: string): string;
}
/**
* Sets the code highlighter for the code blocks.
* @param {CodeHighlighter} highlighter
* @returns {void}
*/
export function setCodeHighlighter(highlighter: CodeHighlighter): void;
/**
* Initializes md4w wasm from fs/CDN.
* @param {"fast" | "small" | URL | Uint8Array | ArrayBuffer | Response | Promise<Response> | string | undefined} wasm The wasm module.
* @returns {Promise<void>}
*/
export async function init(
wasm?: "fast" | "small" | URL | Uint8Array | ArrayBuffer | Response | Promise<Response> | string,
): Promise<void>;
/**
* Initializes md4w wasm with a wasm module.
* @param {WebAssembly.Module} wasmModule The wasm module.
* @returns {void}
*/
export function initSync(wasmModule: WebAssembly.Module): void;