Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add copy-to-clipboard button for code blocks
Maximilian Roos171752978333
diff --git a/docs/sass/custom.scss b/docs/sass/custom.scssindex ada87cb61..892dc9547 100644--- a/docs/sass/custom.scss+++ b/docs/sass/custom.scss@@ -298,6 +298,35 @@ main {}}+// Copy button for code blocks+.code-copy-btn {+ position: absolute;+ top: 0.5rem;+ right: 0.5rem;+ padding: 0.4rem;+ background: var(--wt-color-bg-soft);+ border: 1px solid var(--wt-color-border-subtle);+ border-radius: 0.3rem;+ cursor: pointer;+ color: var(--wt-color-text-muted);+ opacity: 0;+ transition: opacity 150ms, background 150ms, color 150ms;+ line-height: 0;++ &:hover {+ background: var(--wt-color-bg);+ color: var(--wt-color-text);+ }++ &.copied {+ color: var(--wt-color-accent);+ }+}++.content pre:hover .code-copy-btn {+ opacity: 1;+}+// Terminal output styling (ANSI colors).terminal {position: relative;diff --git a/docs/static/code-copy.js b/docs/static/code-copy.jsnew file mode 100644index 000000000..b7ee29394--- /dev/null+++ b/docs/static/code-copy.js@@ -0,0 +1,39 @@+// Copy-to-clipboard for code blocks+// Strips leading `$ ` from terminal blocks++document.addEventListener('DOMContentLoaded', function() {+ const codeBlocks = document.querySelectorAll('.content pre');++ codeBlocks.forEach(function(block) {+ const button = document.createElement('button');+ button.className = 'code-copy-btn';+ button.setAttribute('aria-label', 'Copy code');+ button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>';++ button.addEventListener('click', function() {+ // Check if this is a bash/shell code block (has language-bash class on code element)+ const codeEl = block.querySelector('code');+ const isBash = codeEl && /language-(bash|sh|shell|zsh)/.test(codeEl.className);+ const isTerminal = block.classList.contains('terminal');+ let text = block.textContent;++ if (isBash || isTerminal) {+ // Strip leading `$ ` from each line+ text = text.split('\n').map(function(line) {+ return line.replace(/^\$ /, '');+ }).join('\n');+ }++ navigator.clipboard.writeText(text.trim()).then(function() {+ button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>';+ button.classList.add('copied');+ setTimeout(function() {+ button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>';+ button.classList.remove('copied');+ }, 2000);+ });+ });++ block.appendChild(button);+ });+});diff --git a/docs/templates/base.html b/docs/templates/base.htmlindex 0221d6bdf..8742970b9 100644--- a/docs/templates/base.html+++ b/docs/templates/base.html@@ -72,6 +72,7 @@<script src="/elasticlunr.min.js" defer></script><script src="/search_index.en.js" defer></script><script src="/search.js" defer></script>+<script src="/code-copy.js" defer></script>{% endblock head %}{% block header %}