8
0

strikeengine.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @license Copyright (c) 2017, CKSource - Rémy Hubscher. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module notes/ckeditor-build/strikeengine
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
  10. import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
  11. import AttributeCommand from './attributecommand';
  12. const STRIKE = 'strike';
  13. /**
  14. * The strike engine feature.
  15. *
  16. * It registers the `strike` command and introduces the
  17. * `strikesthrough` attribute in the model which renders to the view
  18. * as a `<s>` element.
  19. *
  20. * @extends module:core/plugin~Plugin
  21. */
  22. export default class StrikeEngine extends Plugin {
  23. /**
  24. * @inheritDoc
  25. */
  26. init() {
  27. const editor = this.editor;
  28. const data = editor.data;
  29. const editing = editor.editing;
  30. // Allow strike attribute on all inline nodes.
  31. editor.document.schema.allow( { name: '$inline', attributes: STRIKE, inside: '$block' } );
  32. // Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
  33. editor.document.schema.allow( { name: '$inline', attributes: STRIKE, inside: '$clipboardHolder' } );
  34. // Build converter from model to view for data and editing pipelines.
  35. buildModelConverter().for( data.modelToView, editing.modelToView )
  36. .fromAttribute( STRIKE )
  37. .toElement( 's' );
  38. // Build converter from view to model for data pipeline.
  39. buildViewConverter().for( data.viewToModel )
  40. .fromElement( 's' )
  41. .fromElement( 'del' )
  42. .fromElement( 'strike' )
  43. .fromAttribute( 'style', { 'text-decoration': 'line-through' } )
  44. .toAttribute( STRIKE, true );
  45. // Create strike command.
  46. editor.commands.add( STRIKE, new AttributeCommand( editor, STRIKE ) );
  47. }
  48. }