From ec1debab38f023d18469e51d24345a2b6d767068 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sun, 21 Jul 2024 12:42:34 +0800 Subject: [PATCH] :bug: Fix: the content of the code block in the details shortcode cannot be copied --- assets/js/theme.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index ff56750a..edbc7fd8 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -438,7 +438,13 @@ class FixIt { $copy.insertAdjacentHTML('afterbegin', ''); $copy.classList.add('copy'); // remove the leading and trailing whitespace of the code string - const code = $code.innerText.trim(); + let code = $code.innerText.trim(); + // in the details element, the code string cannot be gotten directly. + if ($chroma.closest('details') !== null) { + const _tempEl = document.createElement('div'); + _tempEl.appendChild($code.cloneNode(true)); + code = _tempEl.innerText.trim(); + } const forceOpen = $chroma.parentElement.dataset.open ? JSON.parse($chroma.parentElement.dataset.open) : void 0; if (forceOpen ?? (this.config.code.maxShownLines < 0 || code.split('\n').length < this.config.code.maxShownLines + 2)) { $chroma.classList.add('open');