boldfeature.js 1.1 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 AttributeCommand from '../command/attributecommand.js';
  8. /**
  9. * Bold feature.
  10. *
  11. * Bold features bring in possibility to mark some of the content (most commonly some text) as "important" ("bold").
  12. */
  13. export default class BoldFeature extends Feature {
  14. init() {
  15. // Create instance of AttributeCommand which will handle bold attribute and add to commands registry.
  16. this.editor.commands.set( 'bold', new AttributeCommand( this.editor, 'bold' ) );
  17. // Something like this...........
  18. this.editor.treeController.registerAttributeConverter( 'bold', true, 'strong' );
  19. this.editor.treeController.registerViewToModelConverter(
  20. [
  21. [ 'tag', 'b' ],
  22. [ 'tag', 'strong' ],
  23. [ 'style', 'fontWeight', 'bold' ]
  24. ],
  25. 'bold',
  26. true
  27. );
  28. this.editor.document.schema.allow( { name: '$inline', attribute: 'bold', inside: '$block' } );
  29. }
  30. static get requires() {
  31. return [];
  32. }
  33. }