-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathindex.html
95 lines (95 loc) · 3.14 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="Ridiculously simple zero-config markdown displayer - a markdown-to-html web component based on Custom Elements V1 specs to load and display an external MD file."
/>
<title><zero-md></title>
<link rel="icon" type="image/png" href="favicon.png" />
<script type="module">
import ZeroMd from 'https://cdn.jsdelivr.net/npm/zero-md@3'
customElements.define(
'zero-md',
class extends ZeroMd {
async load() {
await super.load()
this.template += `<style>.zero-md-copy{position:relative;}.zero-md-copy button{position:absolute;top:0.5rem;right:0.75rem;cursor:pointer;opacity:0.9;}</style>`
}
async parse(obj) {
const parsed = await super.parse(obj)
if (!navigator.clipboard) return parsed
const tpl = document.createElement('template')
tpl.innerHTML = parsed
tpl.content.querySelectorAll('pre>code').forEach((code) => {
const pre = code.parentElement
pre.replaceWith(
this.frag(`<div class="zero-md-copy">${pre.outerHTML}<button>Copy</button></div>`)
)
})
return tpl.innerHTML
}
async render(obj) {
const out = await super.render(obj)
this.root.querySelectorAll('.zero-md-copy button').forEach((btn) => {
btn.onclick = async () => {
const code = btn.previousElementSibling.firstElementChild.innerText
await navigator.clipboard.writeText(code)
btn.innerText = 'Copied!'
setTimeout(() => (btn.innerText = 'Copy'), 2500)
}
})
return out
}
}
)
</script>
<script type="module" src="https://cdn.jsdelivr.net/npm/zero-md-docs@1"></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/zero-md-docs@next/dist/default.min.css"
/>
<script>
if (location.hostname !== 'localhost') {
window.dataLayer = window.dataLayer || []
function gtag() {
dataLayer.push(arguments)
}
gtag('js', new Date())
gtag('config', 'G-LJS2EY950X')
const el = document.createElement('script')
el.src = 'https://www.googletagmanager.com/gtag/js?id=G-LJS2EY950X'
el.async = true
document.head.append(el)
}
</script>
<style>
footer {
height: 4rem;
margin-top: 4rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 0.875rem;
}
footer a {
text-decoration: underline;
}
footer a:hover {
opacity: 0.8;
}
</style>
</head>
<body>
<div id="app"></div>
<footer>
<span
>GENERATED BY
<a class="link" href="https://github.com/zerodevx/zero-md-docs">ZERO-MD-DOCS</a></span
>
</footer>
</body>
</html>