Skip to content

Commit

Permalink
fix(table): filter microsoft word o:p tag
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Aug 24, 2024
1 parent 8de44c0 commit 78bca6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/parse-html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const TEXT_TAGS = [
'sup',
]

// microsoft word 编辑器特殊的标签
export const MICROSOFT_WORD_TAGS = ['O:P']

// ------------------------------------ pre-parse html ------------------------------------
export type PreParseHtmlFnType = ($node: DOMElement) => DOMElement

Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/parse-html/parse-elem-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { IDomEditor } from '../editor/interface'
import parseCommonElemHtml from './parse-common-elem-html'
import parseTextElemHtml from './parse-text-elem-html'
import { getTagName } from '../utils/dom'
import { PRE_PARSE_HTML_CONF_LIST, TEXT_TAGS } from '../index'
import { MICROSOFT_WORD_TAGS, PRE_PARSE_HTML_CONF_LIST, TEXT_TAGS } from '../index'
import { CustomText } from '../../../custom-types'

/**
* 处理 DOM Elem html
Expand All @@ -35,11 +36,14 @@ function parseElemHtml($elem: Dom7Array, editor: IDomEditor): Descendant | Desce
} else {
if ($elem[0].childNodes.length > 1) {
const childNodes = $elem[0].childNodes
return Array.from(childNodes).map(child => {
$($elem[0]).empty()
$($elem[0]).append($(child))
return parseTextElemHtml($($elem[0]), editor)
})
return Array.from(childNodes).reduce<CustomText[]>((acc, child) => {
if (!MICROSOFT_WORD_TAGS.includes(child.nodeName)) {
$($elem[0]).empty()
$($elem[0]).append($(child))
acc.push(parseTextElemHtml($($elem[0]), editor))
}
return acc
}, [])
}
return parseTextElemHtml($elem, editor)
}
Expand Down

0 comments on commit 78bca6c

Please sign in to comment.