From ecc15ea572b4c22a6266abd98a3c15f0b72b5c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 11 Jan 2024 09:10:57 +0800 Subject: [PATCH] =?UTF-8?q?Demo:=E5=A4=A7=E7=BA=B2=E9=87=8C=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=8A=82=E7=82=B9=E7=9A=84=E5=85=AC=E5=BC=8F=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/utils/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 1ff2b672..2b5bfe31 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -576,7 +576,25 @@ export const getVisibleColorFromTheme = themeConfig => { } } +// 去掉DOM节点中的公式标签 +export const removeFormulaTags = node => { + const walk = root => { + const childNodes = root.childNodes + childNodes.forEach(node => { + if (node.nodeType === 1) { + if (node.classList.contains('ql-formula')) { + node.parentNode.removeChild(node) + } else { + walk(node) + } + } + }) + } + walk(node) +} + // 将

形式的节点富文本内容转换成\n换行的文本 +// 会过滤掉节点中的格式节点 let nodeRichTextToTextWithWrapEl = null export const nodeRichTextToTextWithWrap = html => { if (!nodeRichTextToTextWithWrapEl) { @@ -589,6 +607,7 @@ export const nodeRichTextToTextWithWrap = html => { const node = childNodes[i] if (node.nodeType === 1) { // 元素节点 + removeFormulaTags(node) if (node.tagName.toLowerCase() === 'p') { res += node.textContent + '\n' } else {