Skip to content

Commit

Permalink
Merge pull request #43 from bnf/ckeditor5-attribute-conversion
Browse files Browse the repository at this point in the history
Register custom link attributes to the CKEditor5 schema
  • Loading branch information
einpraegsam authored Sep 29, 2023
2 parents a6c38bd + 3c06b30 commit cef1707
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default class Email4LinkEditing extends Core.Plugin {

_defineConverters() {
const conversion = this.editor.conversion;
const schema = this.editor.model.schema;

schema.extend('$text', { allowAttributes: ['sendEmail', 'emailTitle', 'emailText'] })

conversion.for('downcast').attributeToElement({
model: 'sendEmail',
Expand All @@ -23,7 +26,7 @@ export default class Email4LinkEditing extends Core.Plugin {
});
editor.conversion.for('upcast').elementToAttribute({
view: { name: 'a', attributes: { 'data-lux-email4link-sendemail': true } },
model: { key: 'sendEmail', value: (viewElement) => viewElement.getAttribute('data-lux-send-email') }
model: { key: 'sendEmail', value: (viewElement) => viewElement.getAttribute('data-lux-email4link-sendemail') }
});

conversion.for('downcast').attributeToElement({
Expand All @@ -48,8 +51,8 @@ export default class Email4LinkEditing extends Core.Plugin {
}
});
editor.conversion.for('upcast').elementToAttribute({
view: { name: 'a', attributes: { 'data-lux-email4link-sendemail': true } },
model: { key: 'email4linkText', value: (viewElement) => viewElement.getAttribute('data-lux-email4link-text') }
view: { name: 'a', attributes: { 'data-lux-email4link-text': true } },
model: { key: 'emailText', value: (viewElement) => viewElement.getAttribute('data-lux-email4link-text') }
});
}
}

0 comments on commit cef1707

Please sign in to comment.