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 #127 from ckeditor/t/121
Browse files Browse the repository at this point in the history
Fix: Link should have higher priority than all other attribute elements. Closes #121.
  • Loading branch information
oskarwrobel authored Jun 13, 2017
2 parents 22893d3 + a295641 commit 9dc8973
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/linkengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ export default class LinkEngine extends Plugin {
// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromAttribute( 'linkHref' )
.toElement( linkHref => new LinkElement( 'a', { href: linkHref } ) );
.toElement( linkHref => {
const linkElement = new LinkElement( 'a', { href: linkHref } );

// https://github.com/ckeditor/ckeditor5-link/issues/121
linkElement.priority = 5;

return linkElement;
} );

// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
Expand Down
18 changes: 18 additions & 0 deletions tests/linkengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';

import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';

describe( 'LinkEngine', () => {
let editor, doc;

Expand Down Expand Up @@ -86,5 +88,21 @@ describe( 'LinkEngine', () => {

expect( editor.editing.view.getRoot().getChild( 0 ).getChild( 0 ) ).to.be.instanceof( LinkElement );
} );

// https://github.com/ckeditor/ckeditor5-link/issues/121
it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
editor.document.schema.allow( { name: '$inline', attributes: [ 'foo' ], inside: '$block' } );

buildModelConverter().for( editor.data.modelToView )
.fromAttribute( 'foo' )
.toElement( 'f' );

setModelData( doc,
'<paragraph>' +
'<$text linkHref="url">a</$text><$text foo="true" linkHref="url">b</$text><$text linkHref="url">c</$text>' +
'</paragraph>' );

expect( editor.getData() ).to.equal( '<p><a href="url">a<f>b</f>c</a></p>' );
} );
} );
} );

0 comments on commit 9dc8973

Please sign in to comment.