-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
46 lines (34 loc) · 1.29 KB
/
index.html
File metadata and controls
46 lines (34 loc) · 1.29 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
<!DOCTYPE html>
<html>
<head>
<title>Streaming Markdown</title>
<meta name="darkreader-lock">
<link rel="preload" href="readme.md" as="fetch" type="text/plain" crossorigin="anonymous" />
<link rel="preload" href="dist/browser.js" as="script" crossorigin="anonymous" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400..700;1,400..700&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="index.css" />
</head>
<body>
<main id="markdown" class="prose"></main>
</body>
<script type="module">
import { parse, finish, createParser, createDOMRenderer } from "./dist/browser.js"
const response = await fetch("readme.md")
const source = await response.text()
const container = document.getElementById("markdown")
const renderer = createDOMRenderer(container)
const parser = createParser(renderer)
let i = 0
while (i < source.length) {
const length = Math.floor(Math.random() * 20) + 1
const delay = Math.floor(Math.random() * 80) + 10
const chunk = source.slice(i, i += length)
await new Promise(resolve => setTimeout(resolve, delay))
parse(parser, chunk)
}
finish(parser)
</script>
</html>