diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 4468e714..8c17fdea 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -11,7 +11,8 @@ import { CONSTANTS } from '../../../constants/constant' import { copyNodeTree, createForeignObjectNode, - createUid + createUid, + addXmlns } from '../../../utils/index' // 节点类 @@ -204,10 +205,7 @@ class Node { } // 如果没有返回内容,那么还是使用内置的节点内容 if (this._customNodeContent) { - this._customNodeContent.setAttribute( - 'xmlns', - 'http://www.w3.org/1999/xhtml' - ) + addXmlns(this._customNodeContent) return } this._imgData = this.createImgNode() @@ -220,9 +218,15 @@ class Node { this._prefixData = createNodePrefixContent ? createNodePrefixContent(this) : null + if (this._prefixData && this._prefixData.el) { + addXmlns(this._prefixData.el) + } this._postfixData = createNodePostfixContent ? createNodePostfixContent(this) : null + if (this._postfixData && this._postfixData.el) { + addXmlns(this._postfixData.el) + } } // 计算节点的宽高 diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index dbc1876a..ae6138e0 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -5,7 +5,8 @@ import { addHtmlStyle, checkIsRichText, isUndef, - createForeignObjectNode + createForeignObjectNode, + addXmlns } from '../../../utils' import { Image as SVGImage, SVG, A, G, Rect, Text } from '@svgdotjs/svg.js' import iconsSvg from '../../../svg/icons' @@ -157,7 +158,7 @@ function createRichTextNode() { div.innerHTML = html let el = div.children[0] el.classList.add('smm-richtext-node-wrap') - el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') + addXmlns(el) el.style.maxWidth = textAutoWrapWidth + 'px' let { width, height } = el.getBoundingClientRect() // 如果文本为空,那么需要计算一个默认高度 diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 842e3cea..78e7266d 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -1335,7 +1335,7 @@ export const handleGetSvgDataExtraContent = ({ if (!res) return const { el, cssText, height } = res if (el instanceof HTMLElement) { - el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') + addXmlns(el) const foreignObject = createForeignObjectNode({ el, height }) callback(foreignObject, height) } @@ -1525,3 +1525,8 @@ export const defenseXSS = text => { // 返回最终结果 return result } + +// 给节点添加命名空间 +export const addXmlns = el => { + el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') +}