【发布时间】:2018-06-08 12:44:34
【问题描述】:
我们正在尝试“破解”CKEditor 5 font-family。当您选择元素中的整个文本时,我们希望将font-style 设置为父元素(例如<p>)。生成的语法会更简洁,而不是 <p> 中不必要的 <span> 标记
但是当尝试在Element 上使用setAttribute 时它不起作用,但是该属性是在模型中设置的。但结果文本没有改变。另外我们还没有在Element 上找到addStyle 方法
这是我们当前对fontcommand.js 的修改(注意与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 );
}
}
}
} );
拥有<p>something</p>,我们希望在选择字体样式时获得<p style="font-family: Arial">something</p>。
有人愿意给我们提示吗?
谢谢。
【问题讨论】:
标签: javascript ckeditor ckeditor5