strikethroughediting.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2020, 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/strikethrough/strikethroughediting
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import AttributeCommand from '../attributecommand';
  10. const STRIKETHROUGH = 'strikethrough';
  11. /**
  12. * The strikethrough editing feature.
  13. *
  14. * It registers the `'strikethrough'` command, the <kbd>Ctrl+Shift+X</kbd> keystroke and introduces the
  15. * `strikethroughsthrough` attribute in the model which renders to the view
  16. * as a `<s>` element.
  17. *
  18. * @extends module:core/plugin~Plugin
  19. */
  20. export default class StrikethroughEditing extends Plugin {
  21. /**
  22. * @inheritDoc
  23. */
  24. static get pluginName() {
  25. return 'StrikethroughEditing';
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. init() {
  31. const editor = this.editor;
  32. // Allow strikethrough attribute on text nodes.
  33. editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );
  34. editor.model.schema.setAttributeProperties( STRIKETHROUGH, {
  35. isFormatting: true,
  36. copyOnEnter: true
  37. } );
  38. editor.conversion.attributeToElement( {
  39. model: STRIKETHROUGH,
  40. view: 's',
  41. upcastAlso: [
  42. 'del',
  43. 'strike',
  44. {
  45. styles: {
  46. 'text-decoration': 'line-through'
  47. }
  48. }
  49. ]
  50. } );
  51. // Create strikethrough command.
  52. editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );
  53. // Set the Ctrl+Shift+X keystroke.
  54. editor.keystrokes.set( 'CTRL+SHIFT+X', 'strikethrough' );
  55. }
  56. }