From 2cbeace762900566935e42513ca3b300a4095424 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 14 Jun 2024 12:12:36 -0500 Subject: [PATCH] feature: allowing a copy widget to the code elements --- internal/assets/doco.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/assets/doco.js b/internal/assets/doco.js index 1d7abe0..a64f0f5 100644 --- a/internal/assets/doco.js +++ b/internal/assets/doco.js @@ -8,6 +8,28 @@ document.addEventListener("DOMContentLoaded", () => { // Add highligthing to the code blocks hljs.highlightAll(); + document.querySelectorAll("pre").forEach((el) => { + let bt = document.createElement("button"); + bt.appendChild(document.createTextNode("content_copy")); + bt.classList.add( + "material-symbols-outlined", + "absolute", + "top-4", + "right-2", + "p-1.5", + "bg-gray-50", + "hover:bg-gray-100", + "rounded", + ); + + bt.addEventListener("click", () => { + navigator.clipboard.writeText(el.textContent); + }); + + el.appendChild(bt); + el.classList.add("relative"); + }); + // Adding the mobile menu toggle let toggles = document.querySelectorAll(".toggle-mobile-nav"); toggles.forEach((toggle) => {