diff --git a/simple-mind-map/src/core/render/node/Style.js b/simple-mind-map/src/core/render/node/Style.js index 68a38fc6..4443f034 100644 --- a/simple-mind-map/src/core/render/node/Style.js +++ b/simple-mind-map/src/core/render/node/Style.js @@ -192,14 +192,15 @@ class Style { } // 生成内联样式 - createStyleText() { + createStyleText(customStyle) { const styles = { color: this.merge('color'), fontFamily: this.merge('fontFamily'), fontSize: this.merge('fontSize'), fontWeight: this.merge('fontWeight'), fontStyle: this.merge('fontStyle'), - textDecoration: this.merge('textDecoration') + textDecoration: this.merge('textDecoration'), + ...customStyle } return ` color: ${styles.color}; @@ -354,6 +355,17 @@ class Style { return res } + // 获取自定义的样式 + getCustomStyle() { + let customStyle = {} + Object.keys(this.ctx.getData()).forEach(item => { + if (checkIsNodeStyleDataKey(item)) { + customStyle[item] = this.ctx.getData(item) + } + }) + return customStyle + } + // hover和激活节点 hoverNode(node) { const hoverRectColor = diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index e21686cf..9ecc8a0a 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -139,16 +139,18 @@ function createRichTextNode(specifyText) { recoverText = true } if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) { - // 如果自定义过样式则不允许覆盖 - if (!this.hasCustomStyle()) { + // // 如果自定义过样式则不允许覆盖 + // if (!this.hasCustomStyle() ) { recoverText = true - } + // } } if (recoverText && !isUndef(text)) { // 判断节点内容是否是富文本 let isRichText = checkIsRichText(text) + // 获取自定义样式 + let customStyle = this.getCustomStyle() // 样式字符串 - let style = this.style.createStyleText() + let style = this.style.createStyleText(customStyle) if (isRichText) { // 如果是富文本那么线移除内联样式 text = removeHtmlStyle(text) @@ -159,6 +161,14 @@ function createRichTextNode(specifyText) { if (text === _text) { text = addHtmlStyle(text, 'strong', style) } + // 给strong添加样式没有成功,则尝试给s标签添加样式 + if (text === _text) { + text = addHtmlStyle(text, 's', style) + } + // 给s添加样式没有成功,则尝试给em标签添加样式 + if (text === _text) { + text = addHtmlStyle(text, 'em', style) + } } else { // 非富文本 text = `
${text}
`