-
-
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 remove formatting support for block elements styled using the GHS or style plugin #16867
base: master
Are you sure you want to change the base?
Conversation
What do you mean by affected? That with the remove format it's possible to remove their style/classes but they are inline elements? |
It looks like it's block element and: Because |
I wonder if #15318 as well with this solution? |
@Witoso I'm not sure, it looks like different issue. @niegowski what do you think? |
Yep, sorry, I didn't notice CKEditor 4 is a good reference to check. It leaves the page break intact and doesn't remove its styles. |
This PR/prototype that was created shows that ideally we have some logic that allows us to mark some elements as formatting. Problems that we may want to solve with this mini-project
Reference to CKEditor 4: https://github.com/ckeditor/ckeditor4/blob/3fd8eafd8d805024ca3280fd95899833bb16b163/plugins/removeformat/plugin.js#L143-L182 |
@niegowski Can you take a look? At this moment we remove every class and style assigned via GHS. Should we focus on making it configurable? /cc @Witoso |
I think this would be an incremental value. We could create a follow-up ticket for this API. |
classes: [], | ||
styles: {} |
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.
I'm not sure if a direct modification of this model element attribute is a safe approach. What if we modify the internal format of how we store that data? Maybe we could use an approach similar to the style feature:
ckeditor5/packages/ckeditor5-style/src/stylecommand.ts
Lines 201 to 209 in 08270aa
if ( shouldAddStyle ) { | |
htmlSupport.addModelHtmlClass( definition.element, definition.classes, selectable ); | |
} else { | |
htmlSupport.removeModelHtmlClass( | |
definition.element, | |
getDefinitionExclusiveClasses( activeDefinitions, definition ), | |
selectable | |
); | |
} |
public removeModelHtmlClass( viewElementName: string, className: ArrayOrItem<string>, selectable: Selectable ): void { |
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.
@niegowski I checked these methods and I see few problems:
- These methods assume that the element contains only one GHS attribute, but there are cases when there are multiple formatting GHS on a single element. The example is list item [1]. At this moment, we remove all of them.
getGhsAttributeNameForElement
is used in these methods, so if we map model element to view element, it turns out that for list items it's not working. For example, in the [1] case these paragraph elements are resolved later tohtmlSpanAttribute
GHS attribute name, so we can't remove list item styling despite it's visible.- I'm not sure if we are able to remove all classes or elements according to logic of
modifyGhsAttribute
function (that is used inremoveModelHtmlClass
) and this particularif
: https://github.com/ckeditor/ckeditor5/blob/ck/13983/packages/ckeditor5-html-support/src/utils.ts#L180-L182
if ( item.is( 'element' ) && schema.isBlock( item ) && isGHSAttributeName( attributeName ) ) { | ||
const { | ||
styles = {}, | ||
classes = [] | ||
} = attributeValue as GHSViewAttributes; | ||
|
||
if ( Object.keys( styles ).length || classes.length ) { | ||
yield attributeName; | ||
} | ||
} |
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.
Same as above I'd suggest using some GHS API for such checks. Example:
ckeditor5/packages/ckeditor5-style/src/styleutils.ts
Lines 159 to 164 in 08270aa
public isStyleActiveForBlock( definition: BlockStyleDefinition, block: Element ): boolean { | |
const attributeName = this._htmlSupport.getGhsAttributeNameForElement( definition.element ); | |
const ghsAttributeValue = block.getAttribute( attributeName ); | |
return this.hasAllClasses( ghsAttributeValue, definition.classes ); | |
} |
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.
It'll not work for elements containing multiple GHS attributes, as in the comment above: #16867 (comment)
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.
I checked how it works on such payload:
<p style="border-left: 3px solid dodgerblue; padding-left: 5px;">
foo
</p>
<div style="border: 2px solid orange; padding: 0 10px;">
<p>bar</p>
</div>
And unfortunately, there are multiple issues:
- It replaces the
htmlPAttributes
with an empty{}
instead of removing that attribute from the model. - Only some styles are properly removed from the view by downcast converters.
- The
<div>
element attributes are completely ignored (as in such case is a container, not a block).
a832fc3
to
8604991
Compare
@niegowski I fixed these issues, can you take a look? |
Suggested merge commit message (convention)
Feature (remove-format): It should now be possible to remove formatting from block and container elements styled using the GHS or Style plugin. Closes #13983
Fix (remove-format): It should now be possible to remove styles applied to links. Closes #15318
Additional information
Based on comment, #13983 (comment)