From 78bca6cadd0313fba68ab0f0c618710f1d854528 Mon Sep 17 00:00:00 2001 From: cycleccc <2991205548@qq.com> Date: Sun, 25 Aug 2024 00:01:45 +0800 Subject: [PATCH] fix(table): filter microsoft word o:p tag https://github.com/cycleccc/wangEditor-next/issues/146 --- packages/core/src/parse-html/index.ts | 3 +++ packages/core/src/parse-html/parse-elem-html.ts | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core/src/parse-html/index.ts b/packages/core/src/parse-html/index.ts index ee1ad7656..7f4e8b789 100644 --- a/packages/core/src/parse-html/index.ts +++ b/packages/core/src/parse-html/index.ts @@ -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 diff --git a/packages/core/src/parse-html/parse-elem-html.ts b/packages/core/src/parse-html/parse-elem-html.ts index 5caa6677f..457ba4314 100644 --- a/packages/core/src/parse-html/parse-elem-html.ts +++ b/packages/core/src/parse-html/parse-elem-html.ts @@ -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 @@ -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((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) }