diff --git a/packages/ckeditor5-link/src/autolink.ts b/packages/ckeditor5-link/src/autolink.ts index f180789d392..0ed07fae2e4 100644 --- a/packages/ckeditor5-link/src/autolink.ts +++ b/packages/ckeditor5-link/src/autolink.ts @@ -195,7 +195,7 @@ export default class AutoLink extends Plugin { const watcher = new TextWatcher( editor.model, text => { // 1. Detect Space after a text with a potential link. - if ( !isSingleSpaceAtTheEnd( text ) ) { + if ( !isSingleSpaceOrPunctuationAtTheEnd( text ) ) { return; } @@ -335,8 +335,15 @@ export default class AutoLink extends Plugin { } // Check if text should be evaluated by the plugin in order to reduce number of RegExp checks on whole text. -function isSingleSpaceAtTheEnd( text: string ): boolean { - return text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === ' ' && text[ text.length - 2 ] !== ' '; +function isSingleSpaceOrPunctuationAtTheEnd( text: string ): boolean { + return ( text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === ' ' || + text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === '. ' || + text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === '! ' || + text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === ': ' || + text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === ', ' || + text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === '; ' || + text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[ text.length - 1 ] === '? ' + ) && text[ text.length - 2 ] !== ' '; } function getUrlAtTextEnd( text: string ): string | null { diff --git a/packages/ckeditor5-link/tests/autolink.js b/packages/ckeditor5-link/tests/autolink.js index 963ff11811c..a6509709ebb 100644 --- a/packages/ckeditor5-link/tests/autolink.js +++ b/packages/ckeditor5-link/tests/autolink.js @@ -249,7 +249,7 @@ describe( 'AutoLink', () => { ); } ); - it( 'adds linkHref attribute to a text link after space', () => { + it( 'adds linkHref attribute to a text link after space( )', () => { simulateTyping( 'https://www.cksource.com ' ); expect( getData( model ) ).to.equal( @@ -257,6 +257,54 @@ describe( 'AutoLink', () => { ); } ); + it( 'adds linkHref attribute to a text link after period(.)', () => { + simulateTyping( 'https://www.cksource.com.' ); + + expect( getData( model ) ).to.equal( + 'https://www.cksource.com.[]' + ); + } ); + + it( 'adds linkHref attribute to a text link after exclamation mark(!)', () => { + simulateTyping( 'https://www.cksource.com!' ); + + expect( getData( model ) ).to.equal( + 'https://www.cksource.com![]' + ); + } ); + + it( 'adds linkHref attribute to a text link after colon(:)', () => { + simulateTyping( 'https://www.cksource.com:' ); + + expect( getData( model ) ).to.equal( + 'https://www.cksource.com:[]' + ); + } ); + + it( 'adds linkHref attribute to a text link after comma(,)', () => { + simulateTyping( 'https://www.cksource.com,' ); + + expect( getData( model ) ).to.equal( + 'https://www.cksource.com,[]' + ); + } ); + + it( 'adds linkHref attribute to a text link after semi-colon(;)', () => { + simulateTyping( 'https://www.cksource.com;' ); + + expect( getData( model ) ).to.equal( + 'https://www.cksource.com;[]' + ); + } ); + + it( 'adds linkHref attribute to a text link after question mark(?)', () => { + simulateTyping( 'https://www.cksource.com?' ); + + expect( getData( model ) ).to.equal( + 'https://www.cksource.com?[]' + ); + } ); + it( 'does not add linkHref attribute if linkHref is not allowed', () => { model.schema.addAttributeCheck( () => false ); // Disable all attributes. diff --git a/packages/ckeditor5-link/tests/manual/autolink.md b/packages/ckeditor5-link/tests/manual/autolink.md index dc351b52490..3c99fc610ed 100644 --- a/packages/ckeditor5-link/tests/manual/autolink.md +++ b/packages/ckeditor5-link/tests/manual/autolink.md @@ -10,6 +10,15 @@ 2. Type space after a URL. 3. Check if text typed before space get converted to link. +#### _Special characters_ +The process above can be completed with a set of certain special characters in place of a space: +1. A Period (`.`) +2. An exclamation mark (`!`) +3. A Colon (`:`) +4. A comma (`,`) +5. A Semicolon (`;`) +6. A Question mark (`?`) + ### After a soft break/new paragraph 1. Type a URL as in base scenario. @@ -30,3 +39,11 @@ 2. Select some content 3. Paste 4. Check the selected content is now a link using the copied URL. + +### Ending Punctuation + +1. Copy a URL to the clipboard +2. Select some content +3. Paste +4. Check the selected content is now a link using the copied URL. +