Explorar o código

Updated conversion to changes in the view.

Szymon Kupś %!s(int64=8) %!d(string=hai) anos
pai
achega
a54bfea67a

+ 3 - 1
packages/ckeditor5-link/src/linkengine.js

@@ -31,8 +31,10 @@ export default class LinkEngine extends Plugin {
 		// Allow link attribute on all inline nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: 'linkHref' } );
 
+		const linkElementCreator = ( href, data, consumable, api ) => createLinkElement( href, api.writer );
+
 		editor.conversion.for( 'downcast' )
-			.add( downcastAttributeToElement( 'linkHref', { view: linkHref => createLinkElement( linkHref ) } ) );
+			.add( downcastAttributeToElement( 'linkHref', { view: linkElementCreator } ) );
 
 		editor.conversion.for( 'upcast' )
 			.add( upcastElementToAttribute( {

+ 2 - 4
packages/ckeditor5-link/src/utils.js

@@ -7,8 +7,6 @@
  * @module link/utils
  */
 
-import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement';
-
 const linkElementSymbol = Symbol( 'linkElement' );
 
 /**
@@ -27,8 +25,8 @@ export function isLinkElement( node ) {
  * @param {String} href
  * @return {module:engine/view/attributeelement~AttributeElement}
  */
-export function createLinkElement( href ) {
-	const linkElement = new AttributeElement( 'a', { href } );
+export function createLinkElement( href, writer ) {
+	const linkElement = writer.createAttributeElement( 'a', { href } );
 	linkElement.setCustomProperty( linkElementSymbol, true );
 
 	// https://github.com/ckeditor/ckeditor5-link/issues/121

+ 4 - 2
packages/ckeditor5-link/tests/utils.js

@@ -3,6 +3,8 @@
  * For licensing, see LICENSE.md.
  */
 
+import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
+import ViewWriter from '@ckeditor/ckeditor5-engine/src/view/writer';
 import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement';
 import ContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement';
 import Text from '@ckeditor/ckeditor5-engine/src/view/text';
@@ -12,7 +14,7 @@ import { createLinkElement, isLinkElement } from '../src/utils';
 describe( 'utils', () => {
 	describe( 'isLinkElement', () => {
 		it( 'should return true for elements created by createLinkElement', () => {
-			const element = createLinkElement( 'http://ckeditor.com' );
+			const element = createLinkElement( 'http://ckeditor.com', new ViewWriter( new ViewDocument() ) );
 
 			expect( isLinkElement( element ) ).to.be.true;
 		} );
@@ -32,7 +34,7 @@ describe( 'utils', () => {
 
 	describe( 'createLinkElement', () => {
 		it( 'should create link AttributeElement', () => {
-			const element = createLinkElement( 'http://cksource.com' );
+			const element = createLinkElement( 'http://cksource.com', new ViewWriter( new ViewDocument() ) );
 
 			expect( isLinkElement( element ) ).to.be.true;
 			expect( element.priority ).to.equal( 5 );