italicengine.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Feature from '../feature.js';
  7. import BuildModelConverterFor from '../engine/conversion/model-converter-builder.js';
  8. import BuildViewConverterFor from '../engine/conversion/view-converter-builder.js';
  9. import AttributeCommand from '../command/attributecommand.js';
  10. const ITALIC = 'italic';
  11. export default class ItalicEngine extends Feature {
  12. init() {
  13. const editor = this.editor;
  14. const document = editor.document;
  15. const schema = document.schema;
  16. const data = editor.data;
  17. // Schema.
  18. schema.allow( { name: '$inline', attributes: [ ITALIC ] } );
  19. // Build converter from model to view for data pipeline.
  20. // TODO: Converter for editing pipeline.
  21. BuildModelConverterFor( data.modelToView )
  22. .fromAttribute( ITALIC )
  23. .toElement( 'em' );
  24. // Build converter from view to model for data pipeline.
  25. // TODO: Converter for editing pipeline.
  26. BuildViewConverterFor( data.viewToModel )
  27. .fromElement( 'em' )
  28. .fromElement( 'i' )
  29. .fromAttribute( 'style', { 'font-style': 'italic' } )
  30. .toAttribute( ITALIC, true );
  31. // Command.
  32. const command = new AttributeCommand( editor, ITALIC );
  33. editor.commands.set( ITALIC, command );
  34. }
  35. }