From 1a13eb30da1483519c20ca8d075d85c816c2ff4e Mon Sep 17 00:00:00 2001 From: Francesco Tomaselli Date: Tue, 1 Apr 2025 12:06:34 +0200 Subject: Revert "fix: copy button position" --- static/js/copy-code.js | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'static/js') diff --git a/static/js/copy-code.js b/static/js/copy-code.js index ee7cdc7..2de3cda 100644 --- a/static/js/copy-code.js +++ b/static/js/copy-code.js @@ -1,37 +1,34 @@ document.addEventListener("DOMContentLoaded", function () { - const codeBlocks = document.querySelectorAll(".highlight") + const codeBlocks = document.querySelectorAll("pre"); codeBlocks.forEach((codeBlock) => { - if (codeBlock.className == "mermaid") return - const copyButton = document.createElement("button") - copyButton.className = "copy-code-button" - copyButton.textContent = "copy" - const copyButtonContainer = document.createElement("div") - copyButtonContainer.className = "copy-code-container" - copyButtonContainer.appendChild(copyButton) + if (codeBlock.className == "mermaid") return; + const copyButton = document.createElement("button"); + copyButton.className = "copy-code-button"; + copyButton.textContent = "copy"; // Insert the button inside the
 block
-    codeBlock.appendChild(copyButton)
+    codeBlock.appendChild(copyButton);
 
     copyButton.addEventListener("click", function () {
-      const code = codeBlock.querySelector("code")
+      const code = codeBlock.querySelector("code");
       // Get the code content
-      const textToCopy = code.textContent || code.innerText
+      const textToCopy = code.textContent || code.innerText;
 
       // Use the Clipboard API to copy the text
       navigator.clipboard
         .writeText(textToCopy)
         .then(() => {
           // Change button text to "Copied"
-          copyButton.textContent = "copied"
+          copyButton.textContent = "copied";
 
           setTimeout(() => {
-            copyButton.textContent = "copy"
-          }, 2000) // Reset the button text after 2 seconds
+            copyButton.textContent = "copy";
+          }, 2000); // Reset the button text after 2 seconds
         })
         .catch((err) => {
-          console.error("Unable to copy text:", err)
-        })
-    })
-  })
-})
+          console.error("Unable to copy text:", err);
+        });
+    });
+  });
+});
-- 
cgit v1.2.3