TINY-10955: Remove whitespaces between comment elements. (#9728)

* TINY-10955: Remove whitespaces between comment elements.

* TINY-10955: Improved readability, improved changelog.
This commit is contained in:
HAFRMO
2024-06-28 14:12:13 +02:00
committed by GitHub
parent c4a2208dda
commit ffefa7b6d6
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,6 @@
project: tinymce
kind: Fixed
body: Sequential html comments would in some cases generate unwanted elements.
time: 2024-06-24T17:40:05.135911183+02:00
custom:
Issue: TINY-10955

View File

@ -1,4 +1,5 @@
import { Arr, Fun, Obj, Type } from '@ephox/katamari';
import { NodeTypes } from '@ephox/sugar';
import * as TransparentElements from '../../content/TransparentElements';
import * as NodeType from '../../dom/NodeType';
@ -212,6 +213,8 @@ const whitespaceCleaner = (root: AstNode, schema: Schema, settings: DomParserSet
if (text.length === 0) {
node.remove();
} else if (text === ' ' && node.prev && node.prev.type === NodeTypes.COMMENT && node.next && node.next.type === NodeTypes.COMMENT) {
node.remove();
} else {
node.value = text;
}

View File

@ -502,6 +502,17 @@ describe('browser.tinymce.core.EditorTest', () => {
TinyAssertions.assertContent(editor, '<p><img src="data:image/gif;base64,R0"></p>');
});
// eslint-disable-next-line mocha/no-exclusive-tests
it.only('TINY-10955: multiple comments will not cause unexpected newlines', () => {
const editor = hook.editor();
editor.setContent('<div>A</div><!--Comment1--><!--Comment2--><div>B</div>');
TinyAssertions.assertRawContent(editor, '<div>A</div><!--Comment1--><!--Comment2--><div>B</div>');
editor.setContent('<div>A</div> <!--Comment1--> <!--Comment2--> <div>B</div>');
TinyAssertions.assertRawContent(editor, '<div>A</div><!--Comment1--><!--Comment2--><div>B</div>');
editor.setContent('<div>A</div>\n<!--Comment1-->\n<!--Comment2-->\n<div>B</div>');
TinyAssertions.assertRawContent(editor, '<div>A</div><!--Comment1--><!--Comment2--><div>B</div>');
});
context('hasPlugin', () => {
const checkWithoutManager = (title: string, plugins: string, plugin: string, expected: boolean) => {
const editor = hook.editor();