From 49c9e8e6cb46f200d1f7c4e16e037bc9e9f85b20 Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Mon, 6 Jun 2022 14:04:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9C=E9=97=B4=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=88=87=E6=8D=A2Code=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/NotionPage.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/components/NotionPage.js b/components/NotionPage.js index 61b7fc56..957e9764 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -101,7 +101,12 @@ function addWatch4Dom(element) { switch (type) { case 'childList': if (mutation.target.className === 'notion-code-copy') { - fixCopy(mutation) + fixCopy(mutation.target) + } else if (mutation.target.className?.indexOf('language-') > -1) { + const copyCode = mutation.target.parentElement?.firstElementChild + if (copyCode) { + fixCopy(copyCode) + } } // console.log('A child node has been added or removed.') break @@ -128,12 +133,11 @@ function addWatch4Dom(element) { } /** - * 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165 - * @param {*} e - */ -function fixCopy(e) { - const codeE = e.target.parentElement.lastElementChild - // console.log('2', codeE) + * 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165 + * @param {*} e + */ +function fixCopy(codeCopy) { + const codeE = codeCopy.parentElement.lastElementChild const codeEnd = codeE.lastChild if (codeEnd.nodeName === '#text' && codeE.childNodes.length > 1) { codeEnd.nodeValue = null