Files
oleibman 2319124ff6 WIP Docs Experiment with Properdocs and Copy Clipboard
Experiment with Properdocs as a substitute for the troubled Mkdocs package. Alternate approach to PR #4971.

Also add javascript for copy-to-clipboard functionality for readthedocs and mkdocs themes. A little less aesthetic than material themes, but it should work.

Still unable to add dark mode to readthedocs theme.
2026-08-23 20:33:34 -07:00

36 lines
1.3 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function () {
// Locate all code blocks inside the theme highlights
const codeBlocks = document.querySelectorAll("pre");
codeBlocks.forEach(function (block) {
// Create the button element
const button = document.createElement("button");
button.className = "copy-code-button";
button.type = "button";
button.innerText = "Copy";
// Extract raw code text from the pre/code block
const pre = block;
const code = pre.getElementsByTagName('code');
if (code.length == 1) {
button.addEventListener("click", function () {
const textToCopy = code[0].innerText || code[0].textContent;
navigator.clipboard.writeText(textToCopy).then(function () {
button.innerText = "Copied!";
setTimeout(function () {
button.innerText = "Copy";
}, 2000);
}).catch(function (error) {
button.innerText = "Error";
console.error("Failed to copy text: ", error);
});
});
// Append the button into the container block
block.setAttribute("style", "position: relative;");
block.appendChild(button);
}
});
});