we are trying to "hack" CKEditor 5 font-family a bit. We would like set font-style
to parent element (for example <p>
), when you select whole text in element. Resulting syntax would be much cleaner instead of unnecessary <span>
tag inside <p>
But when trying to setAttribute
on Element
it doesn't work, however the attribute is set in Model. But resulting text is unchanged. Also we haven't found addStyle
method on Element
Here is our current modification of fontcommand.js
(note line with if(range.start.isAtStart && range.end.isAtEnd){
):
model.change( writer => {
if ( selection.isCollapsed ) {
if ( value ) {
writer.setSelectionAttribute( this.attributeKey, value );
} else {
writer.removeSelectionAttribute( this.attributeKey );
}
} else {
const ranges = model.schema.getValidRanges( selection.getRanges(), this.attributeKey );
for ( const range of ranges ) {
if ( value ) {
if(range.start.isAtStart && range.end.isAtEnd){
writer.setAttribute( this.attributeKey, value, range.start.parent );
} else {
writer.setAttribute( this.attributeKey, value, range );
}
} else {
writer.removeAttribute( this.attributeKey, range );
}
}
}
} );
Having <p>something</p>
we would like to get <p style="font-family: Arial">something</p>
when choosing font-style.
Anyone willing to give us a hint?
Thanks.