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

Commit

Permalink
Merge pull request #66 from ckeditor/t/ckeditor5-engine/1295
Browse files Browse the repository at this point in the history
Other: Aligning with new conversion helpers API.
  • Loading branch information
Piotr Jasiun committed Feb 19, 2018
2 parents 4281eca + f2f1a39 commit 5cccbe8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 53 deletions.
23 changes: 13 additions & 10 deletions src/boldengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
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 @@ -33,14 +31,19 @@ export default class BoldEngine extends Plugin {
editor.model.schema.extend( '$text', { allowAttributes: BOLD } );

// Build converter from model to view for data and editing pipelines.
editor.conversion.for( 'downcast' )
.add( downcastAttributeToElement( BOLD, { view: 'strong' } ) );

// Build converter from view to model for data pipeline.
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 } ) );

editor.conversion.attributeToElement( {
model: BOLD,
view: 'strong',
upcastAlso: [
'b',
{
style: {
'font-weight': 'bold'
}
}
]
} );

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

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
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 @@ -32,14 +30,15 @@ export default class CodeEngine extends Plugin {
// Allow code attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: CODE } );

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

// Build converter from view to model for data pipeline.
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'code', model: CODE } ) )
.add( upcastElementToAttribute( { view: { style: { 'word-wrap': 'break-word' } }, model: CODE } ) );
editor.conversion.attributeToElement( {
model: CODE,
view: 'code',
upcastAlso: {
style: {
'word-wrap': 'break-word'
}
}
} );

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

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
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 @@ -32,15 +30,18 @@ export default class ItalicEngine extends Plugin {
// Allow italic attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: ITALIC } );

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

// Build converter from view to model for data pipeline.
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 } ) );
editor.conversion.attributeToElement( {
model: ITALIC,
view: 'i',
upcastAlso: [
'em',
{
style: {
'font-style': 'italic'
}
}
]
} );

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

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
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 @@ -33,16 +31,19 @@ export default class StrikethroughEngine extends Plugin {
// Allow strikethrough attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );

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

// Build converter from view to model for data pipeline.
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 } ) );
editor.conversion.attributeToElement( {
model: STRIKETHROUGH,
view: 's',
upcastAlso: [
'del',
'strike',
{
style: {
'text-decoration': 'line-through'
}
}
]
} );

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

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
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 @@ -32,14 +30,15 @@ export default class UnderlineEngine extends Plugin {
// Allow strikethrough attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: UNDERLINE } );

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

// Build converter from view to model for data pipeline.
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'u', model: UNDERLINE } ) )
.add( upcastElementToAttribute( { view: { style: { 'text-decoration': 'underline' } }, model: UNDERLINE } ) );
editor.conversion.attributeToElement( {
model: UNDERLINE,
view: 'u',
upcastAlso: {
style: {
'text-decoration': 'underline'
}
}
} );

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

0 comments on commit 5cccbe8

Please sign in to comment.