diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 2be4cc22..9c1745d0 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -539,4 +539,59 @@ export const getVisibleColorFromTheme = (themeConfig) => { return color } } +} + +// 将
形式的节点富文本内容转换成
换行的文本
+let nodeRichTextToTextWithWrapEl = null
+export const nodeRichTextToTextWithWrap = (html) => {
+ if (!nodeRichTextToTextWithWrapEl) {
+ nodeRichTextToTextWithWrapEl = document.createElement('div')
+ }
+ nodeRichTextToTextWithWrapEl.innerHTML = html
+ const childNodes = nodeRichTextToTextWithWrapEl.childNodes
+ let res = ''
+ for(let i = 0; i < childNodes.length; i++) {
+ const node = childNodes[i]
+ if (node.nodeType === 1) {// 元素节点
+ if (node.tagName.toLowerCase() === 'p') {
+ res += node.textContent + '\n'
+ } else {
+ res += node.textContent
+ }
+ } else if (node.nodeType === 3) {// 文本节点
+ res += node.nodeValue
+ }
+ }
+ return res.replace(/\n$/, '')
+}
+
+// 将
换行的文本转换成
形式的节点富文本内容 +let textToNodeRichTextWithWrapEl = null +export const textToNodeRichTextWithWrap = (html) => { + if (!textToNodeRichTextWithWrapEl) { + textToNodeRichTextWithWrapEl = document.createElement('div') + } + textToNodeRichTextWithWrapEl.innerHTML = html + const childNodes = textToNodeRichTextWithWrapEl.childNodes + let list = [] + let str = '' + for(let i = 0; i < childNodes.length; i++) { + const node = childNodes[i] + if (node.nodeType === 1) {// 元素节点 + if (node.tagName.toLowerCase() === 'br') { + list.push(str) + str = '' + } else { + str += node.textContent + } + } else if (node.nodeType === 3) {// 文本节点 + str += node.nodeValue + } + } + if (str) { + list.push(str) + } + return list.map((item) => { + return `
${item}
` + }).join('') } \ No newline at end of file diff --git a/web/src/pages/Edit/components/Outline.vue b/web/src/pages/Edit/components/Outline.vue index 173f4095..c106e08e 100644 --- a/web/src/pages/Edit/components/Outline.vue +++ b/web/src/pages/Edit/components/Outline.vue @@ -8,7 +8,11 @@ :expand-on-click-node="false" default-expand-all > - + @@ -26,6 +31,11 @@ @@ -129,7 +165,8 @@ export default {