boldfeature.js 1.2 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 AttributeCommand from '../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. * @class features.Bold
  14. */
  15. export default class BoldFeature extends Feature {
  16. init() {
  17. // Create instance of AttributeCommand which will handle bold attribute and add to commands registry.
  18. this.editor.commands.set( 'bold', new AttributeCommand( this.editor, 'bold' ) );
  19. // Something like this...........
  20. this.editor.treeController.registerAttributeConverter( 'bold', true, 'strong' );
  21. this.editor.treeController.registerViewToModelConverter(
  22. [
  23. [ 'tag', 'b' ],
  24. [ 'tag', 'strong' ],
  25. [ 'style', 'fontWeight', 'bold' ]
  26. ],
  27. 'bold',
  28. true
  29. );
  30. this.editor.document.schema.allow( { name: 'inline', attribute: 'bold', inside: 'block' } );
  31. this.editor.document.schema.allow( { name: 'block', attribute: 'bold', inside: 'root' } );
  32. }
  33. static get requires() {
  34. return [];
  35. }
  36. }