contexted link styling
This commit is contained in:
45
src/ckeditor/ContextedPlugin.ts
Normal file
45
src/ckeditor/ContextedPlugin.ts
Normal 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',
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user