-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EmptyBlocks
plugin that prevents adding
in exported data.
#17756
base: master
Are you sure you want to change the base?
Conversation
EmptyBlocks
plugin that allows for preserving empty block elements in the editor.EmptyBlocks
plugin that prevents adding
in exported data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the comments below, the clipboard integration is missing.
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This describes the internals of the plugin. Docs should focus on plugin usage.
* * 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* * 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 | |
* * 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. |
const editor = this.editor; | ||
const schema = editor.model.schema; | ||
|
||
// Register the attribute for block elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Register the attribute for block elements | |
// Register the attribute for block elements. |
allowAttributes: [ EMPTY_BLOCK_MODEL_ATTRIBUTE ] | ||
} ); | ||
|
||
// Upcast conversion - detect empty elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Upcast conversion - detect empty elements | |
// Upcast conversion - detect empty elements. |
return; | ||
} | ||
|
||
const modelElement = modelRange?.start.nodeAfter as Element; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not yet support ?.
operator.
schema.extend( '$block', { | ||
allowAttributes: [ EMPTY_BLOCK_MODEL_ATTRIBUTE ] | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered extending the $container
? What about table cells? Those are not $block
.
}, { priority: 'lowest' } ); | ||
} ); | ||
|
||
// Data downcast conversion - prevent filler in empty elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Data downcast conversion - prevent filler in empty elements | |
// Data downcast conversion - prevent filler in empty elements. |
} ); | ||
|
||
// Data downcast conversion - prevent filler in empty elements | ||
editor.conversion.for( 'dataDowncast' ).add( dispatcher => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the editing downcast?
if ( viewElement && data.attributeNewValue ) { | ||
viewElement.getFillerOffset = () => null; | ||
} | ||
}, { priority: 'highest' } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this priority or maybe it could be the default?
document.body.appendChild( element ); | ||
|
||
editor = await ClassicTestEditor.create( element, { | ||
plugins: [ Paragraph, EmptyBlocks ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need more tests with more HTML element types, especially table cells. Missing tests for the editing pipeline.
Suggested merge commit message (convention)
Feature (html-support): Add
EmptyBlocks
plugin that prevents adding
in exported data.Additional information
It's part of https://github.com/cksource/ckeditor5-commercial/pull/6942
Original issue https://github.com/cksource/ckeditor5-commercial/issues/6941
More details: Notion