From a94cf2526b56eebf0d912010bb7ca683af175941 Mon Sep 17 00:00:00 2001 From: "nanto_vi, TOYAMA Nao" Date: Thu, 24 Jul 2025 18:38:12 +0900 Subject: [PATCH] Fix parser to take account of `parser.optionsHtml.keepEmptyTextNodes` option (#6571) * Fix parser to take account of `configParser.optionsHtml.keepEmptyTextNodes` * Delete unused `editorConfig.keepEmptyTextNodes` --- packages/core/src/editor/config/config.ts | 7 ---- packages/core/src/parser/model/ParserHtml.ts | 2 +- .../test/specs/parser/model/ParserHtml.ts | 39 +++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/packages/core/src/editor/config/config.ts b/packages/core/src/editor/config/config.ts index 27c6d837c..6a3f81cdc 100644 --- a/packages/core/src/editor/config/config.ts +++ b/packages/core/src/editor/config/config.ts @@ -204,12 +204,6 @@ export interface EditorConfig { */ tagVarEnd?: string; - /** - * When false, removes empty text nodes when parsed, unless they contain a space. - * @default false - */ - keepEmptyTextNodes?: boolean; - /** * Return JS of components inside HTML from 'editor.getHtml()'. * @default true @@ -461,7 +455,6 @@ const config: () => EditorConfig = () => ({ mediaCondition: 'max-width', tagVarStart: '{[ ', tagVarEnd: ' ]}', - keepEmptyTextNodes: false, jsInHtml: true, nativeDnD: true, multipleSelection: true, diff --git a/packages/core/src/parser/model/ParserHtml.ts b/packages/core/src/parser/model/ParserHtml.ts index ef8eff312..a4f42eabe 100644 --- a/packages/core/src/parser/model/ParserHtml.ts +++ b/packages/core/src/parser/model/ParserHtml.ts @@ -325,7 +325,6 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo const conf = em?.get('Config') || {}; const Parser = em?.Parser; const res: HTMLParseResult = { html: [] }; - const cf = { ...config, ...opts }; const preOptions = { ...config.optionsHtml, // @ts-ignore Support previous `configParser.htmlType` option @@ -336,6 +335,7 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo ...preOptions, asDocument: this.__checkAsDocument(str, preOptions), }; + const cf = { ...config, ...options }; const { preParser, asDocument } = options; const inputOptions = { input: isFunction(preParser) ? preParser(str, { editor: em?.getEditor()! }) : str }; Parser?.__emitEvent(ParserEvents.htmlBefore, inputOptions); diff --git a/packages/core/test/specs/parser/model/ParserHtml.ts b/packages/core/test/specs/parser/model/ParserHtml.ts index 95ffe32ab..f3920543b 100644 --- a/packages/core/test/specs/parser/model/ParserHtml.ts +++ b/packages/core/test/specs/parser/model/ParserHtml.ts @@ -983,4 +983,43 @@ describe('ParserHtml', () => { expect(obj.parse(str).html).toEqual(result); }); }); + + describe('with keepEmptyTextNodes ON', () => { + beforeEach(() => { + obj = ParserHtml(em, { + returnArray: true, + optionsHtml: { keepEmptyTextNodes: true }, + }); + obj.compTypes = em.Components.componentTypes; + }); + + test('Keep empty whitespaces', () => { + const str = `
+

TestText

+
`; + const result = [ + { + tagName: 'div', + components: [ + { + tagName: '', + type: 'textnode', + content: '\n ', + }, + { + tagName: 'p', + components: { type: 'textnode', content: 'TestText' }, + type: 'text', + }, + { + tagName: '', + type: 'textnode', + content: '\n ', + }, + ], + }, + ]; + expect(obj.parse(str).html).toEqual(result); + }); + }); });