aboutsummaryrefslogtreecommitdiff
path: root/static/codecopy.js
diff options
context:
space:
mode:
authorJieiku2022-06-15 02:51:03 -0700
committerJieiku2022-06-15 02:51:03 -0700
commitc24c001d799742ba6dd0ce0be2b84a67f7a78081 (patch)
treec82262b3f8ccb996f27c843f789d30b878d3a19c /static/codecopy.js
parent4827695147bea438cf5c42c0ebc325b89f6e731e (diff)
downloadabridge-c24c001d799742ba6dd0ce0be2b84a67f7a78081.tar.gz
abridge-c24c001d799742ba6dd0ce0be2b84a67f7a78081.tar.bz2
abridge-c24c001d799742ba6dd0ce0be2b84a67f7a78081.zip
Update SCSS for Zola's linenos and hl_lines
Diffstat (limited to 'static/codecopy.js')
-rw-r--r--static/codecopy.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/static/codecopy.js b/static/codecopy.js
index 7163cdb..4d100a8 100644
--- a/static/codecopy.js
+++ b/static/codecopy.js
@@ -1,4 +1,5 @@
// https://aaronluna.dev/blog/add-copy-button-to-code-blocks-hugo-chroma/
+// Further modified for Zola by Jieiku: https://github.com/Jieiku
// create copy button
function ccb(highlightDiv) {
@@ -20,8 +21,18 @@ function ccb(highlightDiv) {
// copy code clipboard
async function ccc(button, highlightDiv) {
- const codeToCopy = highlightDiv.querySelector(":last-child > code")
- .innerText;
+ //look for table, if so do it different
+ const { length } = highlightDiv.querySelectorAll("table");
+ let codeToCopy = "";
+ if (length > 0) {
+ const items = highlightDiv.querySelectorAll(":last-child > tr > td:last-child");
+ items.forEach(item => {
+ codeToCopy = codeToCopy + item.innerText;
+ console.log(codeToCopy);
+ });
+ } else {
+ const codeToCopy = highlightDiv.querySelector(":last-child > code").innerText;
+ }
try {
result = await navigator.permissions.query({ name: "clipboard-write" });
if (result.state == "granted" || result.state == "prompt") {
@@ -33,7 +44,7 @@ async function ccc(button, highlightDiv) {
cce(codeToCopy, highlightDiv);//copyCodeBlockExecCommand
} finally {
//codeWasCopied
- button.blur();
+ //button.blur();
button.innerHTML = "Copied";
setTimeout(function () {
button.innerHTML = "Copy";