Skip to content

Commit e57d7f5

Browse files
committed
Adjust checks
1 parent fe051c7 commit e57d7f5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/ckeditor5-html-support/src/emptyblocks.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { Plugin } from 'ckeditor5/src/core.js';
11-
import type { UpcastElementEvent, Element } from 'ckeditor5/src/engine.js';
11+
import type { UpcastElementEvent, Element, DowncastDispatcher } from 'ckeditor5/src/engine.js';
1212

1313
const EMPTY_BLOCK_MODEL_ATTRIBUTE = 'htmlEmptyBlock';
1414

@@ -59,11 +59,15 @@ export default class EmptyBlocks extends Plugin {
5959
const editor = this.editor;
6060
const schema = editor.model.schema;
6161

62-
// Register the attribute for block elements.
62+
// Register the attribute for block and container elements.
6363
schema.extend( '$block', {
6464
allowAttributes: [ EMPTY_BLOCK_MODEL_ATTRIBUTE ]
6565
} );
6666

67+
schema.extend( '$container', {
68+
allowAttributes: [ EMPTY_BLOCK_MODEL_ATTRIBUTE ]
69+
} );
70+
6771
// Upcast conversion - detect empty elements.
6872
editor.conversion.for( 'upcast' ).add( dispatcher => {
6973
dispatcher.on<UpcastElementEvent>( 'element', ( evt, data, conversionApi ) => {
@@ -75,14 +79,14 @@ export default class EmptyBlocks extends Plugin {
7579

7680
const modelElement = modelRange && modelRange.start.nodeAfter as Element;
7781

78-
if ( modelElement && schema.isBlock( modelElement ) ) {
82+
if ( modelElement && schema.checkAttribute( modelElement, EMPTY_BLOCK_MODEL_ATTRIBUTE ) ) {
7983
conversionApi.writer.setAttribute( EMPTY_BLOCK_MODEL_ATTRIBUTE, true, modelElement );
8084
}
8185
} );
8286
} );
8387

8488
// Data downcast conversion - prevent filler in empty elements.
85-
editor.conversion.for( 'dataDowncast' ).add( dispatcher => {
89+
const downcastDispatcher = ( dispatcher: DowncastDispatcher ) => {
8690
dispatcher.on( `attribute:${ EMPTY_BLOCK_MODEL_ATTRIBUTE }`, ( evt, data, conversionApi ) => {
8791
const { item } = data;
8892
const viewElement = conversionApi.mapper.toViewElement( item as Element );
@@ -91,6 +95,9 @@ export default class EmptyBlocks extends Plugin {
9195
viewElement.getFillerOffset = () => null;
9296
}
9397
} );
94-
} );
98+
};
99+
100+
editor.conversion.for( 'dataDowncast' ).add( downcastDispatcher );
101+
editor.conversion.for( 'editingDowncast' ).add( downcastDispatcher );
95102
}
96103
}

0 commit comments

Comments
 (0)