| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import Feature from '../feature.js';
- import buildModelConverter from '../engine/conversion/buildmodelconverter.js';
- import buildViewConverter from '../engine/conversion/buildviewconverter.js';
- import AttributeCommand from '../command/attributecommand.js';
- const BOLD = 'bold';
- /**
- * Bold feature. It registers `bold` command and introduces `bold` attribute in the model, which renders to the view
- * as `<strong>` element.
- *
- * @memberOf basic-styles
- * @extends ckeditor5.Feature
- */
- export default class BoldEngine extends Feature {
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
- const data = editor.data;
- const editing = editor.editing;
- // Allow bold attribute on all inline nodes.
- editor.document.schema.allow( { name: '$inline', attributes: [ BOLD ] } );
- // Build converter from model to view for data and editing pipelines.
- buildModelConverter().for( data.modelToView, editing.modelToView )
- .fromAttribute( BOLD )
- .toElement( 'strong' );
- // Build converter from view to model for data pipeline.
- buildViewConverter().for( data.viewToModel )
- .fromElement( 'strong' )
- .fromElement( 'b' )
- .fromAttribute( 'style', { 'font-weight': 'bold' } )
- .toAttribute( BOLD, true );
- // Create bold command.
- editor.commands.set( BOLD, new AttributeCommand( editor, BOLD ) );
- }
- }
|