Skip to content

Commit a9176c9

Browse files
authored
feat(docs): copy to clipboard button (nodejs#4037)
1 parent 008187b commit a9176c9

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

docs/index.html

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Node.js Undici</title>
@@ -9,6 +10,7 @@
910
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
1011
<link rel="icon" type="image/png" href="https://nodejs.org/static/images/favicons/favicon.png" />
1112
</head>
13+
1214
<body>
1315
<div id="app"></div>
1416
<script>
@@ -32,6 +34,11 @@
3234
noCompileLinks: [
3335
'benchmarks/.*'
3436
],
37+
copyCode: {
38+
buttonText: 'Copy Code',
39+
errorText: 'Error',
40+
successText: 'Copied',
41+
},
3542
relativePath: true,
3643
markdown: {
3744
renderer: {
@@ -73,6 +80,7 @@
7380
<!-- Docsify v4 -->
7481
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
7582
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
83+
<script src="https://unpkg.com/docsify-copy-code@3"></script>
7684
<script type="module">
7785
import mermaid from "//cdn.jsdelivr.net/npm/[email protected]/+esm";
7886
mermaid.initialize({ startOnLoad: true });
@@ -81,18 +89,18 @@
8189
<script>
8290
const plugin = (config) => (hook) => {
8391
hook.afterEach((html, next) => {
84-
const container = document.createElement('div');
85-
container.innerHTML = html;
92+
const container = document.createElement('div');
93+
container.innerHTML = html;
8694

87-
const elements = container.querySelectorAll('pre[data-lang=mermaid]')
88-
for (const element of elements) {
89-
const replacement = document.createElement('div');
90-
replacement.textContent = element.textContent;
91-
replacement.classList.add('mermaid');
92-
element.parentNode.replaceChild(replacement, element);
93-
}
95+
const elements = container.querySelectorAll('pre[data-lang=mermaid]')
96+
for (const element of elements) {
97+
const replacement = document.createElement('div');
98+
replacement.textContent = element.textContent;
99+
replacement.classList.add('mermaid');
100+
element.parentNode.replaceChild(replacement, element);
101+
}
94102

95-
next(container.innerHTML);
103+
next(container.innerHTML);
96104
});
97105

98106
hook.doneEach(() => mermaid.run(config));
@@ -104,4 +112,5 @@
104112
window.$docsify.plugins.push(plugin(window.$docsify.mermaidConfig || { querySelector: ".mermaid" }));
105113
</script>
106114
</body>
107-
</html>
115+
116+
</html>

0 commit comments

Comments
 (0)