Skip to content

Commit

Permalink
Minor fixes in docs after CR.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Jan 17, 2025
1 parent 7d386c9 commit b1e0b3b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/ckeditor5-html-support/src/emptyblocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ const EMPTY_BLOCK_MODEL_ATTRIBUTE = 'htmlEmptyBlock';
* This plugin allows for preserving empty block elements in the editor content instead of
* automatically filling them with block fillers (` `).
*
* Empty elements are detected during upcast and marked with a special attribute.
* During downcast, elements with this attribute have their `getFillerOffset` set to `null`
* which prevents adding block fillers.
*
* This is useful when you want to:
*
* * Preserve empty block elements exactly as they were in the source HTML
* * Allow for styling empty blocks with CSS (block fillers can interfere with height/margin)
* * Maintain compatibility with external systems that expect empty blocks to remain empty
* * Allow for styling empty blocks with CSS (block fillers can interfere with height/margin)
* * Maintain compatibility with external systems that expect empty blocks to remain empty
*
* For example, this allows for HTML like:
*
Expand Down Expand Up @@ -63,12 +59,12 @@ export default class EmptyBlocks extends Plugin {
const editor = this.editor;
const schema = editor.model.schema;

// Register the attribute for block elements
// Register the attribute for block elements.
schema.extend( '$block', {
allowAttributes: [ EMPTY_BLOCK_MODEL_ATTRIBUTE ]
} );

// Upcast conversion - detect empty elements
// Upcast conversion - detect empty elements.
editor.conversion.for( 'upcast' ).add( dispatcher => {
dispatcher.on<UpcastElementEvent>( 'element', ( evt, data, conversionApi ) => {
const { viewItem, modelRange } = data;
Expand All @@ -77,15 +73,15 @@ export default class EmptyBlocks extends Plugin {
return;
}

const modelElement = modelRange?.start.nodeAfter as Element;
const modelElement = modelRange && modelRange.start.nodeAfter as Element;

if ( modelElement && schema.isBlock( modelElement ) ) {
conversionApi.writer.setAttribute( EMPTY_BLOCK_MODEL_ATTRIBUTE, true, modelElement );
}
}, { priority: 'lowest' } );
} );
} );

// Data downcast conversion - prevent filler in empty elements
// Data downcast conversion - prevent filler in empty elements.
editor.conversion.for( 'dataDowncast' ).add( dispatcher => {
dispatcher.on( `attribute:${ EMPTY_BLOCK_MODEL_ATTRIBUTE }`, ( evt, data, conversionApi ) => {
const { item } = data;
Expand All @@ -94,7 +90,7 @@ export default class EmptyBlocks extends Plugin {
if ( viewElement && data.attributeNewValue ) {
viewElement.getFillerOffset = () => null;
}
}, { priority: 'highest' } );
} );
} );
}
}

0 comments on commit b1e0b3b

Please sign in to comment.