-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
45 lines (39 loc) · 1.16 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Marked sequential hooks</title>
</head>
<body>
<div id="content"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked-sequential-hooks/dist/index.umd.min.js"></script>
<script>
;(async () => {
const md = "# {title}\n\n{body}\n"
const myAsyncHook = async (markdown, data) => {
const res = await fetch("https://dummyjson.com/posts/2")
Object.assign(data, await res.json())
return markdown
}
document.getElementById("content").innerHTML = await new marked.Marked({
async: true
})
.use(
markedSequentialHooks({
markdownHooks: [
myAsyncHook,
(markdown, data) => {
document.title = data.id
return markdown
.replace("{title}", data.title)
.replace("{body}", data.body)
}
]
})
)
.parse(md)
})()
</script>
</body>
</html>