From 9c9ed9a5189dc6b13270b5bdc12ef22173c84e20 Mon Sep 17 00:00:00 2001
From: Piotr Jasiun
Date: Thu, 8 Feb 2018 17:26:04 +0100
Subject: [PATCH 1/2] Align code to the new conversion API, introduced in
t/1236.
---
src/boldengine.js | 20 ++++++++------------
src/codeengine.js | 18 +++++++-----------
src/italicengine.js | 20 ++++++++------------
src/strikethroughengine.js | 22 +++++++++-------------
src/underlineengine.js | 18 +++++++-----------
5 files changed, 39 insertions(+), 59 deletions(-)
diff --git a/src/boldengine.js b/src/boldengine.js
index f61ee44..d4d5c3e 100644
--- a/src/boldengine.js
+++ b/src/boldengine.js
@@ -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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const BOLD = 'bold';
@@ -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( upcastAttributeToAttribute( { view: { style: { 'font-weight': 'bold' } }, model: BOLD } ) );
// Create bold command.
editor.commands.add( BOLD, new AttributeCommand( editor, BOLD ) );
diff --git a/src/codeengine.js b/src/codeengine.js
index 39056d8..f9f8032 100644
--- a/src/codeengine.js
+++ b/src/codeengine.js
@@ -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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const CODE = 'code';
@@ -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( upcastAttributeToAttribute( { view: { style: { 'word-wrap': 'break-word' } }, model: CODE } ) );
// Create code command.
editor.commands.add( CODE, new AttributeCommand( editor, CODE ) );
diff --git a/src/italicengine.js b/src/italicengine.js
index 2362253..0cbd07a 100644
--- a/src/italicengine.js
+++ b/src/italicengine.js
@@ -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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const ITALIC = 'italic';
@@ -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( upcastAttributeToAttribute( { view: { style: { 'font-style': 'italic' } }, model: ITALIC } ) );
// Create italic command.
editor.commands.add( ITALIC, new AttributeCommand( editor, ITALIC ) );
diff --git a/src/strikethroughengine.js b/src/strikethroughengine.js
index 1a20e0d..b0a7a59 100644
--- a/src/strikethroughengine.js
+++ b/src/strikethroughengine.js
@@ -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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const STRIKETHROUGH = 'strikethrough';
@@ -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( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'line-through' } }, model: STRIKETHROUGH } ) );
// Create strikethrough command.
editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );
diff --git a/src/underlineengine.js b/src/underlineengine.js
index b585013..2f69b0e 100644
--- a/src/underlineengine.js
+++ b/src/underlineengine.js
@@ -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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const UNDERLINE = 'underline';
@@ -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( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'underline' } }, model: UNDERLINE } ) );
// Create underline command.
editor.commands.add( UNDERLINE, new AttributeCommand( editor, UNDERLINE ) );
From 1b73da9018998bae524c83531135b063bc4fa4a9 Mon Sep 17 00:00:00 2001
From: Piotr Jasiun
Date: Fri, 9 Feb 2018 13:18:08 +0100
Subject: [PATCH 2/2] All converter in basic styles are attribute to element
converters.
---
src/boldengine.js | 4 ++--
src/codeengine.js | 4 ++--
src/italicengine.js | 4 ++--
src/strikethroughengine.js | 4 ++--
src/underlineengine.js | 4 ++--
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/boldengine.js b/src/boldengine.js
index d4d5c3e..bab9c4e 100644
--- a/src/boldengine.js
+++ b/src/boldengine.js
@@ -9,7 +9,7 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
-import { upcastElementToAttribute, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const BOLD = 'bold';
@@ -40,7 +40,7 @@ export default class BoldEngine extends Plugin {
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'b', model: BOLD } ) )
.add( upcastElementToAttribute( { view: 'strong', model: BOLD } ) )
- .add( upcastAttributeToAttribute( { view: { style: { 'font-weight': 'bold' } }, model: BOLD } ) );
+ .add( upcastElementToAttribute( { view: { style: { 'font-weight': 'bold' } }, model: BOLD } ) );
// Create bold command.
editor.commands.add( BOLD, new AttributeCommand( editor, BOLD ) );
diff --git a/src/codeengine.js b/src/codeengine.js
index f9f8032..b624c21 100644
--- a/src/codeengine.js
+++ b/src/codeengine.js
@@ -9,7 +9,7 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
-import { upcastElementToAttribute, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const CODE = 'code';
@@ -39,7 +39,7 @@ export default class CodeEngine extends Plugin {
// Build converter from view to model for data pipeline.
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'code', model: CODE } ) )
- .add( upcastAttributeToAttribute( { view: { style: { 'word-wrap': 'break-word' } }, model: CODE } ) );
+ .add( upcastElementToAttribute( { view: { style: { 'word-wrap': 'break-word' } }, model: CODE } ) );
// Create code command.
editor.commands.add( CODE, new AttributeCommand( editor, CODE ) );
diff --git a/src/italicengine.js b/src/italicengine.js
index 0cbd07a..1e6a2ce 100644
--- a/src/italicengine.js
+++ b/src/italicengine.js
@@ -9,7 +9,7 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
-import { upcastElementToAttribute, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const ITALIC = 'italic';
@@ -40,7 +40,7 @@ export default class ItalicEngine extends Plugin {
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'em', model: ITALIC } ) )
.add( upcastElementToAttribute( { view: 'i', model: ITALIC } ) )
- .add( upcastAttributeToAttribute( { view: { style: { 'font-style': 'italic' } }, model: ITALIC } ) );
+ .add( upcastElementToAttribute( { view: { style: { 'font-style': 'italic' } }, model: ITALIC } ) );
// Create italic command.
editor.commands.add( ITALIC, new AttributeCommand( editor, ITALIC ) );
diff --git a/src/strikethroughengine.js b/src/strikethroughengine.js
index b0a7a59..e954b60 100644
--- a/src/strikethroughengine.js
+++ b/src/strikethroughengine.js
@@ -9,7 +9,7 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
-import { upcastElementToAttribute, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const STRIKETHROUGH = 'strikethrough';
@@ -42,7 +42,7 @@ export default class StrikethroughEngine extends Plugin {
.add( upcastElementToAttribute( { view: 's', model: STRIKETHROUGH } ) )
.add( upcastElementToAttribute( { view: 'del', model: STRIKETHROUGH } ) )
.add( upcastElementToAttribute( { view: 'strike', model: STRIKETHROUGH } ) )
- .add( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'line-through' } }, model: STRIKETHROUGH } ) );
+ .add( upcastElementToAttribute( { view: { style: { 'text-decoration': 'line-through' } }, model: STRIKETHROUGH } ) );
// Create strikethrough command.
editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );
diff --git a/src/underlineengine.js b/src/underlineengine.js
index 2f69b0e..536be2d 100644
--- a/src/underlineengine.js
+++ b/src/underlineengine.js
@@ -9,7 +9,7 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
-import { upcastElementToAttribute, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
import AttributeCommand from './attributecommand';
const UNDERLINE = 'underline';
@@ -39,7 +39,7 @@ export default class UnderlineEngine extends Plugin {
// Build converter from view to model for data pipeline.
editor.conversion.for( 'upcast' )
.add( upcastElementToAttribute( { view: 'u', model: UNDERLINE } ) )
- .add( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'underline' } }, model: UNDERLINE } ) );
+ .add( upcastElementToAttribute( { view: { style: { 'text-decoration': 'underline' } }, model: UNDERLINE } ) );
// Create underline command.
editor.commands.add( UNDERLINE, new AttributeCommand( editor, UNDERLINE ) );