contexted link styling

This commit is contained in:
2023-04-30 14:57:43 +02:00
parent 787b5a4cb8
commit 2ff849219b
5 changed files with 83 additions and 33 deletions

View File

@@ -0,0 +1,45 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'
export default class ContextedLinkEditing extends Plugin {
init() {
this._defineSchema() // ADDED
this._defineConverters() // ADDED
}
_defineSchema() {
// ADDED
const schema = this.editor.model.schema
// Extend the text node's schema to accept the abbreviation attribute.
schema.extend('$text', {
allowAttributes: ['abbreviation', 'contextedLink'],
})
}
_defineConverters() {
// ADDED
const conversion = this.editor.conversion
// Conversion from a model attribute to a view element.
conversion.for('downcast').attributeToElement({
model: 'contextedLink',
// Callback function provides access to the model attribute value
// and the DowncastWriter.
view: (modelAttributeValue, conversionApi) => {
const { writer } = conversionApi
return writer.createAttributeElement('a', {
'data-contexted-link': modelAttributeValue,
})
},
})
conversion.for('upcast').elementToAttribute({
view: {
name: 'a',
key: 'data-contexted-link',
},
model: {
key: 'contextedLink',
},
converterPriority: 'high',
})
}
}