1 | type Github = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Render a Markdown document |
6 | * |
7 | */ |
8 | export async function main( |
9 | auth: Github, |
10 | body: { |
11 | context?: string; |
12 | mode?: "markdown" | "gfm"; |
13 | text: string; |
14 | [k: string]: unknown; |
15 | } |
16 | ) { |
17 | const url = new URL(`https://api.github.com/markdown`); |
18 |
|
19 | const response = await fetch(url, { |
20 | method: "POST", |
21 | headers: { |
22 | "Content-Type": "application/json", |
23 | Authorization: "Bearer " + auth.token, |
24 | }, |
25 | body: JSON.stringify(body), |
26 | }); |
27 | if (!response.ok) { |
28 | const text = await response.text(); |
29 | throw new Error(`${response.status} ${text}`); |
30 | } |
31 | return await response.text(); |
32 | } |
33 |
|