boldengine.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 BOLD = 'bold';
  11. export default class BoldEngine extends Feature {
  12. init() {
  13. const editor = this.editor;
  14. const data = editor.data;
  15. const editing = editor.editing;
  16. // Allow bold attribute on all inline nodes.
  17. editor.document.schema.allow( { name: '$inline', attributes: [ BOLD ] } );
  18. // Build converter from model to view for data and editing pipelines.
  19. BuildModelConverterFor( data.modelToView, editing.modelToView )
  20. .fromAttribute( BOLD )
  21. .toElement( 'strong' );
  22. // Build converter from view to model for data pipeline.
  23. BuildViewConverterFor( data.viewToModel )
  24. .fromElement( 'strong' )
  25. .fromElement( 'b' )
  26. .fromAttribute( 'style', { 'font-weight': 'bold' } )
  27. .toAttribute( BOLD, true );
  28. // Create bold command.
  29. editor.commands.set( BOLD, new AttributeCommand( editor, BOLD ) );
  30. }
  31. }