improve: copy title and table element

pr675
Hufe921 3 years ago
parent 1fc276fbae
commit 03cd85f423

@ -73,3 +73,8 @@ export const INLINE_ELEMENT_TYPE: ElementType[] = [
ElementType.SEPARATOR, ElementType.SEPARATOR,
ElementType.TABLE ElementType.TABLE
] ]
export const INLINE_NODE_NAME: string[] = [
'HR',
'TABLE'
]

@ -1,6 +1,6 @@
import { IEditorOption, IElement, RowFlex } from '..' import { IEditorOption, IElement, RowFlex } from '..'
import { ZERO } from '../dataset/constant/Common' import { ZERO } from '../dataset/constant/Common'
import { TEXTLIKE_ELEMENT_TYPE } from '../dataset/constant/Element' import { INLINE_NODE_NAME, TEXTLIKE_ELEMENT_TYPE } from '../dataset/constant/Element'
import { titleNodeNameMapping, titleOrderNumberMapping } from '../dataset/constant/Title' import { titleNodeNameMapping, titleOrderNumberMapping } from '../dataset/constant/Title'
import { ControlComponent } from '../dataset/enum/Control' import { ControlComponent } from '../dataset/enum/Control'
import { ElementType } from '../dataset/enum/Element' import { ElementType } from '../dataset/enum/Element'
@ -81,7 +81,8 @@ export function writeElementList(elementList: IElement[], options: DeepRequired<
const td = tr.tdList[d] const td = tr.tdList[d]
tdDom.colSpan = td.colspan tdDom.colSpan = td.colspan
tdDom.rowSpan = td.rowspan tdDom.rowSpan = td.rowspan
tdDom.innerText = td.value[0]?.value || '' const childDom = buildDomFromElementList(zipElementList(td.value!))
tdDom.innerHTML = childDom.innerHTML
trDom.append(tdDom) trDom.append(tdDom)
} }
tableDom.append(trDom) tableDom.append(trDom)
@ -212,9 +213,11 @@ export function getElementListByHTML(htmlText: string, options: IGetElementListB
level: titleNodeNameMapping[node.nodeName], level: titleNodeNameMapping[node.nodeName],
valueList valueList
}) })
if (node.nextSibling && !INLINE_NODE_NAME.includes(node.nextSibling.nodeName)) {
elementList.push({ elementList.push({
value: '\n' value: '\n'
}) })
}
} else if (node.nodeName === 'HR') { } else if (node.nodeName === 'HR') {
elementList.push({ elementList.push({
value: '\n', value: '\n',
@ -247,12 +250,11 @@ export function getElementListByHTML(htmlText: string, options: IGetElementListB
} }
trElement.querySelectorAll('th,td').forEach(tdElement => { trElement.querySelectorAll('th,td').forEach(tdElement => {
const tableCell = <HTMLTableCellElement>tdElement const tableCell = <HTMLTableCellElement>tdElement
const valueList = getElementListByHTML(tableCell.innerHTML, options)
const td: ITd = { const td: ITd = {
colspan: tableCell.colSpan, colspan: tableCell.colSpan,
rowspan: tableCell.rowSpan, rowspan: tableCell.rowSpan,
value: [{ value: valueList
value: tableCell.innerText
}]
} }
tr.tdList.push(td) tr.tdList.push(td)
}) })

Loading…
Cancel
Save