From e6d118a56eb45c6b173f9ce783a9a039a82382d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Thu, 13 Jul 2017 16:39:34 +0200 Subject: [PATCH] Improved the converter to check the href attr. --- src/linkengine.js | 3 ++- tests/linkengine.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/linkengine.js b/src/linkengine.js index 7862253..470759c 100644 --- a/src/linkengine.js +++ b/src/linkengine.js @@ -49,7 +49,8 @@ export default class LinkEngine extends Plugin { // Build converter from view to model for data pipeline. buildViewConverter().for( data.viewToModel ) - .fromElement( 'a' ) + // Convert with href (value doesn't matter). + .from( { name: 'a', attribute: { href: /.?/ } } ) .toAttribute( viewElement => ( { key: 'linkHref', value: viewElement.getAttribute( 'href' ) diff --git a/tests/linkengine.js b/tests/linkengine.js index 1a5caf9..3140dac 100644 --- a/tests/linkengine.js +++ b/tests/linkengine.js @@ -71,6 +71,24 @@ describe( 'LinkEngine', () => { expect( editor.getData() ).to.equal( '

foobar

' ); } ); + + // https://github.com/ckeditor/ckeditor5/issues/500 + it( 'should not pick up `
`', () => { + editor.setData( '

foobar

' ); + + expect( getModelData( doc, { withoutSelection: true } ) ) + .to.equal( 'foobar' ); + } ); + + // CKEditor 4 does. And CKEditor 5's balloon allows creating such links. + it( 'should pick up ``', () => { + editor.setData( '

foobar

' ); + + expect( getModelData( doc, { withoutSelection: true } ) ) + .to.equal( '<$text linkHref="">foobar' ); + + expect( editor.getData() ).to.equal( '

foobar

' ); + } ); } ); describe( 'editing pipeline conversion', () => {