agahi
Version:
Client-side engine that renders Markdown files as a docs site in the browser—no build step.
2 lines (1 loc) • 2.03 kB
JavaScript
!function(){"use strict";!function(e,o){void 0===o&&(o={});var n=o.insertAt;if("undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&t.firstChild?t.insertBefore(r,t.firstChild):t.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}}(".copy-code {\n position: absolute;\n top: 0.5rem;\n right: 0.5rem;\n padding: 0.25rem 0.5rem;\n font-size: 0.75rem;\n font-weight: 500;\n color: var(--text-color);\n background-color: var(--background-hover);\n border: 1px solid var(--border-color);\n border-radius: 0.25rem;\n cursor: pointer;\n opacity: 0;\n transition: all 0.2s ease;\n z-index: 1;\n}\n\n/* Show on hover (desktop) */\n\n@media (hover: hover) {\n pre:hover .copy-code {\n opacity: 1;\n }\n}\n\n/* Always show on mobile */\n\n@media (hover: none) and (pointer: coarse) {\n .copy-code {\n opacity: 1;\n }\n}\n\n.copy-code:active,\n.copy-code:focus {\n outline: none;\n color: #fff;\n}\n\n.copy-code:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n"),document.addEventListener("agahi:ready",(()=>{const e=document.getElementById("md");if(!e)throw new Error('Article element with id="md" not found. Copy code plugin cannot initialize.');const o=e=>{const o=e.parentElement;if(!o||"PRE"!==o.tagName||o.querySelector(".copy-code"))return;const n=document.createElement("button");n.className="copy-code",n.textContent="Copy",n.onclick=()=>{navigator.clipboard.writeText(e.textContent).then((()=>{n.textContent="Copied!",setTimeout((()=>n.textContent="Copy"),1500)})).catch((e=>{console.error("Failed to copy using navigator.clipboard:",e)}))},o.appendChild(n)};e.querySelectorAll("pre > code").forEach(o);new MutationObserver((e=>{for(const{addedNodes:n}of e)for(const e of n){if(1!==e.nodeType)continue;("CODE"===e.tagName&&"PRE"===e.parentElement?.tagName?[e]:e.querySelectorAll?.("pre > code")||[]).forEach(o)}})).observe(e,{childList:!0,subtree:!0})}))}();