Browse Source
Fix parser to take account of `parser.optionsHtml.keepEmptyTextNodes` option (#6571)
* Fix parser to take account of `configParser.optionsHtml.keepEmptyTextNodes`
* Delete unused `editorConfig.keepEmptyTextNodes`
release-v0.22.12
nanto_vi, TOYAMA Nao
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
40 additions and
8 deletions
-
packages/core/src/editor/config/config.ts
-
packages/core/src/parser/model/ParserHtml.ts
-
packages/core/test/specs/parser/model/ParserHtml.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, |
|
|
|
|
|
|
|
@ -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); |
|
|
|
|
|
|
|
@ -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 = `<div>
|
|
|
|
<p>TestText</p> |
|
|
|
</div>`;
|
|
|
|
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); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|