+ {{ end }}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index e9cad8b17..17d9bf05f 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -19,3 +19,7 @@
{{ if .IsHome }}{{ partial "head/hugo-generator.html" . }}{{ end }}
{{ partial "head/extensions.html" . }}
+
+{{ if (findRE "
+{{ end }}
\ No newline at end of file
diff --git a/static/css/clipboard.css b/static/css/clipboard.css
new file mode 100644
index 000000000..770a4f64c
--- /dev/null
+++ b/static/css/clipboard.css
@@ -0,0 +1,37 @@
+.clipboard-button {
+ position: absolute;
+ right: 0;
+ padding: 5px 7px 3px 7px;
+ margin: 5px;
+ color: #767676;
+ border-color: #767676;
+ background-color: #ededed;
+ border: 1px solid;
+ border-radius: 6px;
+ font-size: 0.8em;
+ z-index: 1;
+ opacity: 0;
+ transition: 0.1s;
+ }
+ .clipboard-button > svg {
+ fill: #767676;
+ }
+ .clipboard-button:hover {
+ cursor: pointer;
+ border-color: #696969;
+ background-color: #e0e0e0;
+ }
+ .clipboard-button:hover > svg {
+ fill: #696969;
+ }
+ .clipboard-button:focus {
+ outline: 0;
+ }
+ .highlight {
+ position: relative;
+ }
+ .highlight:hover > .clipboard-button {
+ opacity: 1;
+ transition: 0.2s;
+ }
+
\ No newline at end of file
diff --git a/static/js/clipboard.js b/static/js/clipboard.js
new file mode 100644
index 000000000..3c01556c0
--- /dev/null
+++ b/static/js/clipboard.js
@@ -0,0 +1,37 @@
+const svgCopy =
+ '';
+const svgCheck =
+ '';
+
+const addCopyButtons = (clipboard) => {
+ document.querySelectorAll("pre > code").forEach((codeBlock) => {
+ const button = document.createElement("button");
+ button.className = "clipboard-button";
+ button.type = "button";
+ button.innerHTML = svgCopy;
+ button.addEventListener("click", () => {
+ clipboard.writeText(codeBlock.innerText).then(
+ () => {
+ button.blur();
+ button.innerHTML = svgCheck;
+ setTimeout(() => (button.innerHTML = svgCopy), 2000);
+ },
+ (error) => (button.innerHTML = "Error")
+ );
+ });
+ const pre = codeBlock.parentNode;
+ pre.parentNode.insertBefore(button, pre);
+ });
+};
+if (navigator && navigator.clipboard) {
+ addCopyButtons(navigator.clipboard);
+ } else {
+ const script = document.createElement("script");
+ script.src =
+ "https://cdnjs.cloudflare.com/ajax/libs/clipboard-polyfill/2.7.0/clipboard-polyfill.promise.js";
+ script.integrity = "sha256-waClS2re9NUbXRsryKoof+F9qc1gjjIhc2eT7ZbIv94=";
+ script.crossOrigin = "anonymous";
+ script.onload = () => addCopyButtons(clipboard);
+ document.body.appendChild(script);
+ }
+
\ No newline at end of file