From 98c17559e9c15f6ee64515f75ec22a2895b8a01f Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:00:08 +0530 Subject: [PATCH] Add checks for adding the copy button in code-blocks - adds checks to put copy button for code inside table and highlight code block - Fixes #363 --- assets/css/common/main.css | 5 +++-- layouts/partials/footer.html | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/assets/css/common/main.css b/assets/css/common/main.css index eb2c4c84..82b61246 100644 --- a/assets/css/common/main.css +++ b/assets/css/common/main.css @@ -44,7 +44,7 @@ code { direction: ltr; } -div.highlight { +div.highlight, pre { position: relative; } @@ -60,6 +60,7 @@ div.highlight { font-size: 14px; } -div.highlight:hover .copy-code { +div.highlight:hover .copy-code, +pre:hover .copy-code { display: block; } diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 1badd4a6..2c6511b8 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -120,7 +120,17 @@ selection.removeRange(range); }); - container.appendChild(copybutton); + if (container.classList.contains("highlight")) { + container.appendChild(copybutton); + } else if (container.parentNode.firstChild == container) { + // td containing LineNos + } else if (codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "TABLE") { + // table containing LineNos and code + codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(copybutton); + } else { + // code blocks not having highlight as parent class + codeblock.parentNode.appendChild(copybutton); + } }); {{- end }}