mentionediting.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module mention/mentionediting
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. /**
  10. * The mention editing feature.
  11. *
  12. * @extends module:core/plugin~Plugin
  13. */
  14. export default class MentionEditing extends Plugin {
  15. /**
  16. * @inheritDoc
  17. */
  18. static get pluginName() {
  19. return 'MentionEditing';
  20. }
  21. /**
  22. * @inheritDoc
  23. */
  24. init() {
  25. const editor = this.editor;
  26. editor.conversion.for( 'upcast' ).elementToAttribute( {
  27. view: {
  28. name: 'span',
  29. key: 'data-mention',
  30. classes: 'mention'
  31. },
  32. model: {
  33. key: 'mention',
  34. value: viewItem => {
  35. return viewItem.getAttribute( 'data-mention' );
  36. }
  37. }
  38. } );
  39. editor.conversion.for( 'downcast' ).attributeToElement( {
  40. model: 'mention',
  41. view: ( modelAttributeValue, viewWriter ) => {
  42. return viewWriter.createAttributeElement( 'span', {
  43. class: 'mention',
  44. 'data-mention': modelAttributeValue
  45. } );
  46. }
  47. } );
  48. // Allow fontSize attribute on text nodes.
  49. editor.model.schema.extend( '$text', { allowAttributes: 'mention' } );
  50. }
  51. }