-
Notifications
You must be signed in to change notification settings - Fork 64
/
index.html
61 lines (50 loc) · 1.49 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Rehype Pretty Code</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
code,
pre {
padding: 10px 20px 10px 20px;
line-height: 1.5
}
::selection {
color: #ffcffd;
background-color: #000
}
</style>
</head>
<body style="display: flex; height: 100vh; align-items: center; justify-content: center; background-color: #ffe8fa;">
<section style="font-size:1.75rem;" id="code"></section>
<script type="module">
import { unified } from 'https://esm.run/unified'
import remarkParse from 'https://esm.run/remark-parse'
import remarkRehype from 'https://esm.run/remark-rehype'
import rehypeStringify from 'https://esm.run/rehype-stringify'
import rehypePrettyCode from 'https://esm.run/rehype-pretty-code'
const codeElement = document.querySelector('section#code')
const codeSnippet = /* ts */ `ts
export function* FibonacciSequence() {
let [a, b] = [0, 1];
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
const fib = FibonacciSequence();
fib.next().value // 0
fib.next().value // 1
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
`
const processor = await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypePrettyCode, { theme: 'rose-pine' })
.use(rehypeStringify)
.process("```" + codeSnippet)
if (codeElement) codeElement.innerHTML = processor.toString()
</script>
</body>
</html>