From 0467329a857909024f3be6ec8cf22dde6c50ae54 Mon Sep 17 00:00:00 2001 From: paoloredis Date: Wed, 23 Sep 2026 12:26:45 +0200 Subject: [PATCH 1/2] Strip shell/redis-cli prompts from single-line code block copies The copy-to-clipboard button copied "$ ", "> ", and "127.0.0.1:6379> " prompts verbatim, so pasting a copied command failed until the prompt was removed by hand. Strip these prefixes for single-line blocks, where the line is always just the command; leave multiline blocks (which mix commands and output) untouched. Co-Authored-By: Claude Sonnet 5 --- layouts/partials/scripts.html | 8 +++++++- static/js/codetabs.js | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index d294b98851..e6907338e3 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -49,7 +49,13 @@ // Handle copy logic button.addEventListener('click', () => { const lines = block.querySelectorAll('span.cl'); - const text = Array.from(lines).map(line => line.textContent).join(''); + // Single-line blocks are almost always one command preceded by a + // prompt ("$ ", "> ", "127.0.0.1:6379> "). Strip that prompt so the + // copied text runs as-is. Multiline blocks mix commands and output, + // so leave them untouched. + const text = lines.length === 1 + ? lines[0].textContent.replace(/^(\s*)(?:\$\s*|>\s*|127\.0\.0\.1:6379>\s*)/, '$1') + : Array.from(lines).map(line => line.textContent).join(''); navigator.clipboard.writeText(text).then(() => { tooltip.style.display = 'block'; diff --git a/static/js/codetabs.js b/static/js/codetabs.js index 16170411bb..927c10fa1b 100644 --- a/static/js/codetabs.js +++ b/static/js/codetabs.js @@ -72,6 +72,14 @@ function copyCodeToClipboardForCodetabs(button) { } } + // Single-line blocks are almost always one command preceded by a prompt + // ("$ ", "> ", "127.0.0.1:6379> "). Strip that prompt so the copied text + // runs as-is. Multiline blocks mix commands and output, so leave them untouched. + const codeLines = code.split('\n').filter(line => line !== ''); + if (codeLines.length === 1) { + code = codeLines[0].replace(/^(\s*)(?:\$\s*|>\s*|127\.0\.0\.1:6379>\s*)/, '$1'); + } + navigator.clipboard.writeText(code); // Toggle tooltip From 0151597751525d1e93539a6446404560ef360873 Mon Sep 17 00:00:00 2001 From: paoloredis Date: Wed, 23 Sep 2026 14:32:31 +0200 Subject: [PATCH 2/2] Require a space after the prompt character before stripping it \$\s* and >\s* matched zero trailing spaces, so a bare $ or > with no following space was treated as a prompt too. That stripped the leading character from single-line snippets like PHP ($client = ...) or anything starting with >=. Require at least one space (\s+) so only an actual "$ cmd" / "> cmd" / "127.0.0.1:6379> cmd" prompt gets stripped. Co-Authored-By: Claude Sonnet 5 --- layouts/partials/scripts.html | 2 +- static/js/codetabs.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index e6907338e3..567b497099 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -54,7 +54,7 @@ // copied text runs as-is. Multiline blocks mix commands and output, // so leave them untouched. const text = lines.length === 1 - ? lines[0].textContent.replace(/^(\s*)(?:\$\s*|>\s*|127\.0\.0\.1:6379>\s*)/, '$1') + ? lines[0].textContent.replace(/^(\s*)(?:\$\s+|>\s+|127\.0\.0\.1:6379>\s+)/, '$1') : Array.from(lines).map(line => line.textContent).join(''); navigator.clipboard.writeText(text).then(() => { diff --git a/static/js/codetabs.js b/static/js/codetabs.js index 927c10fa1b..8c31cd7089 100644 --- a/static/js/codetabs.js +++ b/static/js/codetabs.js @@ -77,7 +77,7 @@ function copyCodeToClipboardForCodetabs(button) { // runs as-is. Multiline blocks mix commands and output, so leave them untouched. const codeLines = code.split('\n').filter(line => line !== ''); if (codeLines.length === 1) { - code = codeLines[0].replace(/^(\s*)(?:\$\s*|>\s*|127\.0\.0\.1:6379>\s*)/, '$1'); + code = codeLines[0].replace(/^(\s*)(?:\$\s+|>\s+|127\.0\.0\.1:6379>\s+)/, '$1'); } navigator.clipboard.writeText(code);