diff --git a/docs/en/docs/js/custom.js b/docs/en/docs/js/custom.js index 48e95901d..939bdadfe 100644 --- a/docs/en/docs/js/custom.js +++ b/docs/en/docs/js/custom.js @@ -81,6 +81,9 @@ function setupTermynal() { } } saveBuffer(); + + const originalText = node.textContent; + const div = document.createElement("div"); node.replaceWith(div); const termynal = new Termynal(div, { @@ -89,6 +92,38 @@ function setupTermynal() { lineDelay: 500 }); termynals.push(termynal); + + const highlightParent = div.closest('.highlight'); + if (highlightParent) { + const existingButton = highlightParent.querySelector('button[data-clipboard-text]'); + if (existingButton) { + existingButton.remove(); + } + + const copyButton = document.createElement('button'); + copyButton.className = 'md-clipboard md-icon'; + copyButton.title = 'Copy to clipboard'; + copyButton.setAttribute('data-clipboard-text', originalText); + + copyButton.innerHTML = ''; + + copyButton.addEventListener('click', async function() { + try { + await navigator.clipboard.writeText(originalText); + const originalTitle = copyButton.title; + copyButton.title = 'Copied!'; + copyButton.classList.add('md-clipboard--copied'); + setTimeout(() => { + copyButton.title = originalTitle; + copyButton.classList.remove('md-clipboard--copied'); + }, 2000); + } catch (err) { + console.error('Failed to copy text: ', err); + } + }); + + highlightParent.appendChild(copyButton); + } }); }