-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
44 lines (40 loc) · 1.3 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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Marked hook data</title>
</head>
<body>
<h1>My Posts</h1>
<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 src="https://cdn.jsdelivr.net/npm/marked-hook-data/dist/index.umd.min.js"></script>
<script>
;(async () => {
const res = await fetch("https://dummyjson.com/posts?limit=10")
const dataPosts = await res.json()
document.getElementById("content").innerHTML = await new marked.Marked({
async: true
})
.use(
markedSequentialHooks({
markdownHooks: [
markedHookData(dataPosts),
(markdown, { posts = [] }) => {
const chunk = []
for (const { title, body } of posts) {
chunk.push(
markdown.replace("{title}", title).replace("{body}", body)
)
}
return chunk.join("\n")
}
]
})
)
.parse("## {title}\n\n{body}\n\n---\n")
})()
</script>
</body>
</html>