From f7994081e98ac9ec8cc02cf9416c44545838e9ce Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 4 Aug 2022 15:03:47 +0800 Subject: [PATCH] :bug: fix https://github.com/Vanessa219/vditor/issues/1269 --- CHANGELOG.md | 1 + src/ts/ir/input.ts | 30 ++++++++++++++++-------------- src/ts/sv/inputEvent.ts | 31 ++++++++++++++++--------------- src/ts/wysiwyg/input.ts | 30 ++++++++++++++++-------------- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ff549f0..d66aa4b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,7 @@ ### v3.8.16 / 2022-08 +* [1269](https://github.com/Vanessa219/vditor/issues/1269) 代码块自动补全会包含链接引用和脚注 `修复缺陷` * [1263](https://github.com/Vanessa219/vditor/issues/1263) 所见即所得和即使渲染只有空格输入时,不会触发 input 事件 `修复缺陷` * [1264](https://github.com/Vanessa219/vditor/issues/1264) 链接中,会强制将®解析为 ® 字符 `修复缺陷` * [1242](https://github.com/Vanessa219/vditor/issues/1242) 在即时渲染模式下表格源文件未对齐 `改进功能` diff --git a/src/ts/ir/input.ts b/src/ts/ir/input.ts index 99713b2d9..a2b7e9629 100644 --- a/src/ts/ir/input.ts +++ b/src/ts/ir/input.ts @@ -148,21 +148,23 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event? html = blockElement.previousElementSibling.outerHTML + html; blockElement.previousElementSibling.remove(); } - // 添加链接引用 - vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item) => { - if (item && !(blockElement as HTMLElement).isEqualNode(item)) { - html += item.outerHTML; - item.remove(); - } - }); + if (!blockElement.innerText.startsWith("```")) { + // 添加链接引用 + vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item) => { + if (item && !(blockElement as HTMLElement).isEqualNode(item)) { + html += item.outerHTML; + item.remove(); + } + }); - // 添加脚注 - vditor.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach((item) => { - if (item && !(blockElement as HTMLElement).isEqualNode(item)) { - html += item.outerHTML; - item.remove(); - } - }); + // 添加脚注 + vditor.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach((item) => { + if (item && !(blockElement as HTMLElement).isEqualNode(item)) { + html += item.outerHTML; + item.remove(); + } + }); + } } else { html = blockElement.innerHTML; } diff --git a/src/ts/sv/inputEvent.ts b/src/ts/sv/inputEvent.ts index 33887de07..b4fb8a541 100644 --- a/src/ts/sv/inputEvent.ts +++ b/src/ts/sv/inputEvent.ts @@ -140,22 +140,23 @@ export const inputEvent = (vditor: IVditor, event?: InputEvent) => { html = blockElement.previousElementSibling.textContent + html; blockElement.previousElementSibling.remove(); } + if (!blockElement.innerText.startsWith("```")) { + // 添加链接引用 + vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item, index) => { + if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) { + html += "\n" + item.parentElement.textContent; + item.parentElement.remove(); + } + }); - // 添加链接引用 - vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item, index) => { - if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) { - html += "\n" + item.parentElement.textContent; - item.parentElement.remove(); - } - }); - - // 添加脚注 - vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach((item, index) => { - if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) { - html += "\n" + item.parentElement.textContent; - item.parentElement.remove(); - } - }); + // 添加脚注 + vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach((item, index) => { + if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) { + html += "\n" + item.parentElement.textContent; + item.parentElement.remove(); + } + }); + } } html = processSpinVditorSVDOM(html, vditor); if (isSVElement) { diff --git a/src/ts/wysiwyg/input.ts b/src/ts/wysiwyg/input.ts index 209df868c..a0f448fd7 100644 --- a/src/ts/wysiwyg/input.ts +++ b/src/ts/wysiwyg/input.ts @@ -108,21 +108,23 @@ export const input = (vditor: IVditor, range: Range, event?: InputEvent) => { html = html.replace("

", "

  • "); } - // 添加链接引用 - vditor.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item) => { - if (item && !(blockElement as HTMLElement).isEqualNode(item)) { - html += item.outerHTML; - item.remove(); - } - }); + if (!blockElement.innerText.startsWith("```")) { + // 添加链接引用 + vditor.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item) => { + if (item && !(blockElement as HTMLElement).isEqualNode(item)) { + html += item.outerHTML; + item.remove(); + } + }); - // 添加脚注 - vditor.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']").forEach((item) => { - if (item && !(blockElement as HTMLElement).isEqualNode(item)) { - html += item.outerHTML; - item.remove(); - } - }); + // 添加脚注 + vditor.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']").forEach((item) => { + if (item && !(blockElement as HTMLElement).isEqualNode(item)) { + html += item.outerHTML; + item.remove(); + } + }); + } } else { html = blockElement.innerHTML; }