Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): copy to clipboard button #4037

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Node.js Undici</title>
Expand All @@ -9,6 +10,7 @@
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
<link rel="icon" type="image/png" href="https://nodejs.org/static/images/favicons/favicon.png" />
</head>

<body>
<div id="app"></div>
<script>
Expand All @@ -32,6 +34,11 @@
noCompileLinks: [
'benchmarks/.*'
],
copyCode: {
buttonText: 'Copy Code',
errorText: 'Error',
successText: 'Copied',
},
relativePath: true,
markdown: {
renderer: {
Expand Down Expand Up @@ -73,6 +80,7 @@
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
<script src="https://unpkg.com/docsify-copy-code@3"></script>
<script type="module">
import mermaid from "//cdn.jsdelivr.net/npm/mermaid@10.8.0/+esm";
mermaid.initialize({ startOnLoad: true });
Expand All @@ -81,18 +89,18 @@
<script>
const plugin = (config) => (hook) => {
hook.afterEach((html, next) => {
const container = document.createElement('div');
container.innerHTML = html;
const container = document.createElement('div');
container.innerHTML = html;

const elements = container.querySelectorAll('pre[data-lang=mermaid]')
for (const element of elements) {
const replacement = document.createElement('div');
replacement.textContent = element.textContent;
replacement.classList.add('mermaid');
element.parentNode.replaceChild(replacement, element);
}
const elements = container.querySelectorAll('pre[data-lang=mermaid]')
for (const element of elements) {
const replacement = document.createElement('div');
replacement.textContent = element.textContent;
replacement.classList.add('mermaid');
element.parentNode.replaceChild(replacement, element);
}

next(container.innerHTML);
next(container.innerHTML);
});

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

</html>
Loading