From 4167fffb097a17cc8574f25373f3b5560dfcc4ba Mon Sep 17 00:00:00 2001 From: Tron Date: Sat, 23 Nov 2024 20:38:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=84=9A?= =?UTF-8?q?=E6=B3=A8=E5=86=85=E5=AE=B9=E8=AE=BE=E7=BD=AE=E5=AD=98=E6=94=BE?= =?UTF-8?q?=E5=9C=A8=E7=88=B6=E5=9D=97=E5=90=8E=EF=BC=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=88=B0=E4=B8=8B=E4=B8=80=E5=85=84=E5=BC=9F?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 133b3bc..00f4814 100644 --- a/src/index.ts +++ b/src/index.ts @@ -274,7 +274,6 @@ export default class PluginFootnote extends Plugin { // 获取当前光标所在块的 ID const currentBlockId = protyle.toolbar.range.startContainer.parentElement.closest('[data-node-id]')?.getAttribute('data-node-id'); const currentParentBlockId = protyle.toolbar.range.startContainer.parentElement.closest('.protyle-wysiwyg > [data-node-id]')?.getAttribute('data-node-id'); - console.log(currentBlockId, currentParentBlockId); // 先复制选中内容 const getSelectedHtml = (range: Range): string => { // 创建临时容器 @@ -439,7 +438,12 @@ export default class PluginFootnote extends Plugin { case '4': // 父块后 docID = protyle.block.id; - footnoteContainerID = currentParentBlockId; + if (currentParentBlockId == null) { + footnoteContainerID = currentBlockId; + } + else { + footnoteContainerID = currentParentBlockId; + } break; } @@ -481,18 +485,20 @@ export default class PluginFootnote extends Plugin { default: function findNextSiblingIdWithoutFootnote(id) { + console.log(id); // 首先找到目标块 - const targetBlock = document.querySelector(`[data-node-id="${id}"]`); - + const targetBlock = document.querySelector(`.protyle-wysiwyg [data-node-id="${id}"]`); + console.log(targetBlock); if (!targetBlock) { return null; } // 使用nextElementSibling获取下一个兄弟元素 let nextSibling = targetBlock.nextElementSibling; - + console.log(nextSibling); // 遍历所有后续兄弟元素,直到找到符合条件的元素 while (nextSibling) { + console.log(nextSibling.getAttribute('data-node-id')); // 检查是否没有custom-plugin-footnote-content="true"属性 if (!nextSibling.hasAttribute('custom-plugin-footnote-content')) { // 返回找到的元素的data-node-id属性值