Skip to content

Commit 3054ca6

Browse files
authored
feat: cdn example (#197)
1 parent fcb7d85 commit 3054ca6

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

examples/cdn/index.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Rehype Pretty Code</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<style>code,pre{padding:16px 20px;line-height:1.5}::selection{color:#ffcffd;background-color:#000}</style>
9+
</head>
10+
11+
<body style="display: flex; height: 100vh; align-items: center; justify-content: center; background-color: #ffe8fa;">
12+
13+
<section style="font-size:1.75rem;" id="code"></section>
14+
15+
<script type="module">
16+
import { unified } from 'https://esm.run/unified'
17+
import remarkParse from 'https://esm.run/remark-parse'
18+
import remarkRehype from 'https://esm.run/remark-rehype'
19+
import rehypeStringify from 'https://esm.run/rehype-stringify'
20+
import rehypePrettyCode from 'https://esm.run/rehype-pretty-code'
21+
22+
const codeElement = document.querySelector('section#code')
23+
24+
const codeSnippet = /* ts */ `ts
25+
export function* fibbonaciSequence() {
26+
let [a, b] = [0, 1];
27+
while (true) {
28+
yield a;
29+
[a, b] = [b, a + b];
30+
}
31+
}
32+
33+
const fib = fibbonaciSequence();
34+
fib.next().value // 0
35+
fib.next().value // 1
36+
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
37+
`
38+
39+
const processor = await unified()
40+
.use(remarkParse)
41+
.use(remarkRehype)
42+
.use(rehypePrettyCode, { theme: 'rose-pine' })
43+
.use(rehypeStringify)
44+
.process("```" + codeSnippet)
45+
46+
if (codeElement) codeElement.innerHTML = processor.toString()
47+
</script>
48+
</body>
49+
50+
</html>

examples/cdn/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "example-cdn",
3+
"scripts": {
4+
"dev": "pnpm dlx serve@latest .",
5+
"start": "pnpm dlx serve@latest ."
6+
}
7+
}

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)