subscriptediting.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module basic-styles/subscript/subscriptediting
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import AttributeCommand from '../attributecommand';
  10. const SUB = 'sub';
  11. /**
  12. * The subscript editing feature.
  13. *
  14. * It registers the `sub` command and introduces the `sub` attribute in the model which renders to the view
  15. * as a `<sub>` element.
  16. *
  17. * @extends module:core/plugin~Plugin
  18. */
  19. export default class SubscriptEditing extends Plugin {
  20. /**
  21. * @inheritDoc
  22. */
  23. init() {
  24. const editor = this.editor;
  25. // Allow sub attribute on text nodes.
  26. editor.model.schema.extend( '$text', { allowAttributes: SUB } );
  27. // Build converter from model to view for data and editing pipelines.
  28. editor.conversion.attributeToElement( {
  29. model: SUB,
  30. view: 'sub',
  31. upcastAlso: [
  32. {
  33. styles: {
  34. 'vertical-align': 'sub'
  35. }
  36. }
  37. ]
  38. } );
  39. // Create sub command.
  40. editor.commands.add( SUB, new AttributeCommand( editor, SUB ) );
  41. }
  42. }