subscriptediting.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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 SUBSCRIPT = 'subscript';
  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: SUBSCRIPT } );
  27. editor.model.schema.setAttributeProperties( SUBSCRIPT, { isFormatting: true } );
  28. // Build converter from model to view for data and editing pipelines.
  29. editor.conversion.attributeToElement( {
  30. model: SUBSCRIPT,
  31. view: 'sub',
  32. upcastAlso: [
  33. {
  34. styles: {
  35. 'vertical-align': 'sub'
  36. }
  37. }
  38. ]
  39. } );
  40. // Create sub command.
  41. editor.commands.add( SUBSCRIPT, new AttributeCommand( editor, SUBSCRIPT ) );
  42. }
  43. }