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 #1630 from ckeditor/t/1617
Browse files Browse the repository at this point in the history
Fix: Converter priority passing in `conversion.attributeToElement()`. Closes #1617.
  • Loading branch information
scofalik authored Jan 3, 2019
2 parents a9c41c8 + 6e44281 commit fe6d17d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/conversion/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export default class Conversion {
.elementToAttribute( {
view,
model,
converterPriority: definition.priority
converterPriority: definition.converterPriority
} );
}
}
Expand Down
39 changes: 37 additions & 2 deletions tests/conversion/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,24 @@ describe( 'Conversion', () => {
test( '<p>Foo</p>', '<paragraph>Foo</paragraph>' );
} );

it( 'config.converterPriority is defined', () => {
it( 'config.converterPriority is defined (override downcast)', () => {
conversion.elementToElement( { model: 'paragraph', view: 'p' } );
conversion.elementToElement( { model: 'paragraph', view: 'div', converterPriority: 'high' } );

test( '<div>Foo</div>', '<paragraph>Foo</paragraph>' );
test( '<p>Foo</p>', '<paragraph>Foo</paragraph>', '<div>Foo</div>' );
} );

it( 'config.converterPriority is defined (override upcast)', () => {
schema.register( 'foo', {
inheritAllFrom: '$block'
} );
conversion.elementToElement( { model: 'paragraph', view: 'p' } );
conversion.elementToElement( { model: 'foo', view: 'p', converterPriority: 'high' } );

test( '<p>Foo</p>', '<foo>Foo</foo>', '<p>Foo</p>' );
} );

it( 'config.view is an object', () => {
schema.register( 'fancyParagraph', {
inheritAllFrom: 'paragraph'
Expand Down Expand Up @@ -232,14 +242,28 @@ describe( 'Conversion', () => {
test( '<p><strong>Foo</strong> bar</p>', '<paragraph><$text bold="true">Foo</$text> bar</paragraph>' );
} );

it( 'config.converterPriority is defined', () => {
it( 'config.converterPriority is defined (override downcast)', () => {
conversion.attributeToElement( { model: 'bold', view: 'strong' } );
conversion.attributeToElement( { model: 'bold', view: 'b', converterPriority: 'high' } );

test( '<p><b>Foo</b></p>', '<paragraph><$text bold="true">Foo</$text></paragraph>' );
test( '<p><strong>Foo</strong></p>', '<paragraph><$text bold="true">Foo</$text></paragraph>', '<p><b>Foo</b></p>' );
} );

it( 'config.converterPriority is defined (override upcast)', () => {
schema.extend( '$text', {
allowAttributes: [ 'foo' ]
} );
conversion.attributeToElement( { model: 'bold', view: 'strong' } );
conversion.attributeToElement( { model: 'foo', view: 'strong', converterPriority: 'high' } );

test(
'<p><strong>Foo</strong></p>',
'<paragraph><$text foo="true">Foo</$text></paragraph>',
'<p><strong>Foo</strong></p>'
);
} );

it( 'config.view is an object', () => {
conversion.attributeToElement( {
model: 'bold',
Expand Down Expand Up @@ -634,6 +658,17 @@ describe( 'Conversion', () => {
'<div border="border"><div shade="shade"></div></div>'
);
} );

it( 'config.converterPriority is defined (override downcast)', () => {
schema.extend( 'image', {
allowAttributes: [ 'foo' ]
} );

conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
conversion.attributeToAttribute( { model: 'foo', view: 'foofoo', converterPriority: 'high' } );

test( '<img foo="foo"></img>', '<image foo="foo"></image>', '<img foofoo="foo"></img>' );
} );
} );

function test( input, expectedModel, expectedView = null ) {
Expand Down

0 comments on commit fe6d17d

Please sign in to comment.