Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thegeeklab/hugo-geekdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kaussow <mail@thegeeklab.de>2022-06-12 16:41:20 +0300
committerGitHub <noreply@github.com>2022-06-12 16:41:20 +0300
commit3ea85629a426a10b3e8e9ab7ebcf2b21e2a95a61 (patch)
treee7ba115ad834b6f671edbcd85f73aefa0e43553a
parent7195431d8c915c76730243b11d66fedf7fe1bb47 (diff)
fix: fix execption while creating the code copy button (#439)v0.32.2
-rw-r--r--src/js/copycode.js31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/js/copycode.js b/src/js/copycode.js
index a5c3376..c48e002 100644
--- a/src/js/copycode.js
+++ b/src/js/copycode.js
@@ -1,23 +1,26 @@
export function createCopyButton(highlightDiv) {
const button = document.createElement("span")
- let selector = "pre > code"
+ let codeSelector = "pre > code"
if (highlightDiv.querySelector(".lntable")) {
- selector = ".lntable .lntd:last-child pre > code"
+ codeSelector = ".lntable .lntd:last-child pre > code"
}
- const codeToCopy = highlightDiv.querySelector(selector).innerText.trim()
+ const codeContainer = highlightDiv.querySelector(codeSelector)
+ if (codeContainer !== null) {
+ const codeContent = codeContainer.innerText.trim()
- button.classList.add("flex", "align-center", "justify-center", "clip", "gdoc-post__codecopy")
- button.type = "button"
- button.innerHTML =
- '<svg class="gdoc-icon copy"><use xlink:href="#gdoc_copy"></use></svg>' +
- '<svg class="gdoc-icon check hidden"><use xlink:href="#gdoc_check"></use></svg>'
- button.setAttribute("data-clipboard-text", codeToCopy)
- button.setAttribute("data-copy-feedback", "Copied!")
- button.setAttribute("role", "button")
- button.setAttribute("aria-label", "Copy")
+ button.classList.add("flex", "align-center", "justify-center", "clip", "gdoc-post__codecopy")
+ button.type = "button"
+ button.innerHTML =
+ '<svg class="gdoc-icon copy"><use xlink:href="#gdoc_copy"></use></svg>' +
+ '<svg class="gdoc-icon check hidden"><use xlink:href="#gdoc_check"></use></svg>'
+ button.setAttribute("data-clipboard-text", codeContent)
+ button.setAttribute("data-copy-feedback", "Copied!")
+ button.setAttribute("role", "button")
+ button.setAttribute("aria-label", "Copy")
- highlightDiv.classList.add("gdoc-post__codecontainer")
- highlightDiv.insertBefore(button, highlightDiv.firstChild)
+ highlightDiv.classList.add("gdoc-post__codecontainer")
+ highlightDiv.insertBefore(button, highlightDiv.firstChild)
+ }
}