Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge branch t/ckeditor5-engine/1236
Browse files Browse the repository at this point in the history
Internal: Align code to the new conversion API, introduced in engine t/1236.
  • Loading branch information
Piotr Jasiun committed Feb 9, 2018
2 parents 3226016 + 1b73da9 commit deb0c7c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 59 deletions.
20 changes: 8 additions & 12 deletions src/boldengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';

const BOLD = 'bold';
Expand All @@ -28,23 +28,19 @@ export default class BoldEngine extends Plugin {
*/
init() {
const editor = this.editor;
const data = editor.data;
const editing = editor.editing;

// Allow bold attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: BOLD } );

// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromAttribute( BOLD )
.toElement( 'strong' );
editor.conversion.for( 'downcast' )
.add( downcastAttributeToElement( BOLD, { view: '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 );
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'b', model: BOLD } ) )
.add( upcastElementToAttribute( { view: 'strong', model: BOLD } ) )
.add( upcastElementToAttribute( { view: { style: { 'font-weight': 'bold' } }, model: BOLD } ) );

// Create bold command.
editor.commands.add( BOLD, new AttributeCommand( editor, BOLD ) );
Expand Down
18 changes: 7 additions & 11 deletions src/codeengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';

const CODE = 'code';
Expand All @@ -28,22 +28,18 @@ export default class CodeEngine extends Plugin {
*/
init() {
const editor = this.editor;
const data = editor.data;
const editing = editor.editing;

// Allow code attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: CODE } );

// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromAttribute( CODE )
.toElement( 'code' );
editor.conversion.for( 'downcast' )
.add( downcastAttributeToElement( CODE, { view: 'code' } ) );

// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
.fromElement( 'code' )
.fromAttribute( 'style', { 'word-wrap': 'break-word' } )
.toAttribute( CODE, true );
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'code', model: CODE } ) )
.add( upcastElementToAttribute( { view: { style: { 'word-wrap': 'break-word' } }, model: CODE } ) );

// Create code command.
editor.commands.add( CODE, new AttributeCommand( editor, CODE ) );
Expand Down
20 changes: 8 additions & 12 deletions src/italicengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';

const ITALIC = 'italic';
Expand All @@ -28,23 +28,19 @@ export default class ItalicEngine extends Plugin {
*/
init() {
const editor = this.editor;
const data = editor.data;
const editing = editor.editing;

// Allow italic attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: ITALIC } );

// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromAttribute( ITALIC )
.toElement( 'i' );
editor.conversion.for( 'downcast' )
.add( downcastAttributeToElement( ITALIC, { view: 'i' } ) );

// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
.fromElement( 'em' )
.fromElement( 'i' )
.fromAttribute( 'style', { 'font-style': 'italic' } )
.toAttribute( ITALIC, true );
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'em', model: ITALIC } ) )
.add( upcastElementToAttribute( { view: 'i', model: ITALIC } ) )
.add( upcastElementToAttribute( { view: { style: { 'font-style': 'italic' } }, model: ITALIC } ) );

// Create italic command.
editor.commands.add( ITALIC, new AttributeCommand( editor, ITALIC ) );
Expand Down
22 changes: 9 additions & 13 deletions src/strikethroughengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';

const STRIKETHROUGH = 'strikethrough';
Expand All @@ -29,24 +29,20 @@ export default class StrikethroughEngine extends Plugin {
*/
init() {
const editor = this.editor;
const data = editor.data;
const editing = editor.editing;

// Allow strikethrough attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );

// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromAttribute( STRIKETHROUGH )
.toElement( 's' );
editor.conversion.for( 'downcast' )
.add( downcastAttributeToElement( STRIKETHROUGH, { view: 's' } ) );

// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
.fromElement( 's' )
.fromElement( 'del' )
.fromElement( 'strike' )
.fromAttribute( 'style', { 'text-decoration': 'line-through' } )
.toAttribute( STRIKETHROUGH, true );
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 's', model: STRIKETHROUGH } ) )
.add( upcastElementToAttribute( { view: 'del', model: STRIKETHROUGH } ) )
.add( upcastElementToAttribute( { view: 'strike', model: STRIKETHROUGH } ) )
.add( upcastElementToAttribute( { view: { style: { 'text-decoration': 'line-through' } }, model: STRIKETHROUGH } ) );

// Create strikethrough command.
editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );
Expand Down
18 changes: 7 additions & 11 deletions src/underlineengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';

const UNDERLINE = 'underline';
Expand All @@ -28,22 +28,18 @@ export default class UnderlineEngine extends Plugin {
*/
init() {
const editor = this.editor;
const data = editor.data;
const editing = editor.editing;

// Allow strikethrough attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: UNDERLINE } );

// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromAttribute( UNDERLINE )
.toElement( 'u' );
editor.conversion.for( 'downcast' )
.add( downcastAttributeToElement( UNDERLINE, { view: 'u' } ) );

// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
.fromElement( 'u' )
.fromAttribute( 'style', { 'text-decoration': 'underline' } )
.toAttribute( UNDERLINE, true );
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'u', model: UNDERLINE } ) )
.add( upcastElementToAttribute( { view: { style: { 'text-decoration': 'underline' } }, model: UNDERLINE } ) );

// Create underline command.
editor.commands.add( UNDERLINE, new AttributeCommand( editor, UNDERLINE ) );
Expand Down

0 comments on commit deb0c7c

Please sign in to comment.