Fix:优化markdown的导出,修复概要丢失的问题
This commit is contained in:
parent
70b6b0052f
commit
2baa500c17
@ -1,12 +1,7 @@
|
|||||||
import { walk } from '../utils'
|
import { walk, nodeRichTextToTextWithWrap } from '../utils'
|
||||||
|
|
||||||
let el = null
|
const getNodeText = data => {
|
||||||
const getText = str => {
|
return data.richText ? nodeRichTextToTextWithWrap(data.text) : data.text
|
||||||
if (!el) {
|
|
||||||
el = document.createElement('div')
|
|
||||||
}
|
|
||||||
el.innerHTML = str
|
|
||||||
return el.textContent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTitleMark = level => {
|
const getTitleMark = level => {
|
||||||
@ -24,21 +19,22 @@ export const transformToMarkdown = root => {
|
|||||||
root,
|
root,
|
||||||
null,
|
null,
|
||||||
(node, parent, isRoot, layerIndex) => {
|
(node, parent, isRoot, layerIndex) => {
|
||||||
let level = layerIndex + 1
|
const level = layerIndex + 1
|
||||||
let text = node.data.richText ? getText(node.data.text) : node.data.text
|
|
||||||
if (level <= 6) {
|
if (level <= 6) {
|
||||||
content += getTitleMark(level)
|
content += getTitleMark(level)
|
||||||
} else {
|
} else {
|
||||||
content += getIndentMark(level)
|
content += getIndentMark(level)
|
||||||
}
|
}
|
||||||
content += ' ' + text
|
content += ' ' + getNodeText(node.data)
|
||||||
// 概要
|
// 概要
|
||||||
let generalization = node.data.generalization
|
const generalization = node.data.generalization
|
||||||
if (generalization && generalization.text) {
|
if (Array.isArray(generalization)) {
|
||||||
let generalizationText = generalization.richText
|
content += generalization.map(item => {
|
||||||
? getText(generalization.text)
|
return ` [${getNodeText(item)}]`
|
||||||
: generalization.text
|
})
|
||||||
content += `[${generalizationText}]`
|
} else if (generalization && generalization.text) {
|
||||||
|
const generalizationText = getNodeText(generalization)
|
||||||
|
content += ` [${generalizationText}]`
|
||||||
}
|
}
|
||||||
content += '\n\n'
|
content += '\n\n'
|
||||||
// 备注
|
// 备注
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user