|
@@ -10,6 +10,7 @@
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
import TextWatcher from '@ckeditor/ckeditor5-typing/src/textwatcher';
|
|
import TextWatcher from '@ckeditor/ckeditor5-typing/src/textwatcher';
|
|
|
import getLastTextLine from '@ckeditor/ckeditor5-typing/src/utils/getlasttextline';
|
|
import getLastTextLine from '@ckeditor/ckeditor5-typing/src/utils/getlasttextline';
|
|
|
|
|
+import { addLinkProtocolIfApplicable } from './utils';
|
|
|
|
|
|
|
|
const MIN_LINK_LENGTH_WITH_SPACE_AT_END = 4; // Ie: "t.co " (length 5).
|
|
const MIN_LINK_LENGTH_WITH_SPACE_AT_END = 4; // Ie: "t.co " (length 5).
|
|
|
|
|
|
|
@@ -49,9 +50,6 @@ const URL_REG_EXP = new RegExp(
|
|
|
|
|
|
|
|
const URL_GROUP_IN_MATCH = 2;
|
|
const URL_GROUP_IN_MATCH = 2;
|
|
|
|
|
|
|
|
-// Simplified email test - should be run over previously found URL.
|
|
|
|
|
-const EMAIL_REG_EXP = /^[\S]+@((?![-_])(?:[-\w\u00a1-\uffff]{0,63}[^-_]\.))+(?:[a-z\u00a1-\uffff]{2,})$/i;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* The autolink plugin.
|
|
* The autolink plugin.
|
|
|
*
|
|
*
|
|
@@ -213,7 +211,7 @@ export default class AutoLink extends Plugin {
|
|
|
* @param {module:engine/model/range~Range} range The text range to apply the link attribute to.
|
|
* @param {module:engine/model/range~Range} range The text range to apply the link attribute to.
|
|
|
* @private
|
|
* @private
|
|
|
*/
|
|
*/
|
|
|
- _applyAutoLink( url, range ) {
|
|
|
|
|
|
|
+ _applyAutoLink( link, range ) {
|
|
|
const model = this.editor.model;
|
|
const model = this.editor.model;
|
|
|
|
|
|
|
|
if ( !this.isEnabled || !isLinkAllowedOnRange( range, model ) ) {
|
|
if ( !this.isEnabled || !isLinkAllowedOnRange( range, model ) ) {
|
|
@@ -222,9 +220,9 @@ export default class AutoLink extends Plugin {
|
|
|
|
|
|
|
|
// Enqueue change to make undo step.
|
|
// Enqueue change to make undo step.
|
|
|
model.enqueueChange( writer => {
|
|
model.enqueueChange( writer => {
|
|
|
- const linkHrefValue = isEmail( url ) ? `mailto:${ url }` : url;
|
|
|
|
|
-
|
|
|
|
|
- writer.setAttribute( 'linkHref', linkHrefValue, range );
|
|
|
|
|
|
|
+ const defaultProtocol = this.editor.config.get( 'link.defaultProtocol' );
|
|
|
|
|
+ const parsedUrl = addLinkProtocolIfApplicable( link, defaultProtocol );
|
|
|
|
|
+ writer.setAttribute( 'linkHref', parsedUrl, range );
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -240,10 +238,6 @@ function getUrlAtTextEnd( text ) {
|
|
|
return match ? match[ URL_GROUP_IN_MATCH ] : null;
|
|
return match ? match[ URL_GROUP_IN_MATCH ] : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function isEmail( linkHref ) {
|
|
|
|
|
- return EMAIL_REG_EXP.exec( linkHref );
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
function isLinkAllowedOnRange( range, model ) {
|
|
function isLinkAllowedOnRange( range, model ) {
|
|
|
return model.schema.checkAttributeInSelection( model.createSelection( range ), 'linkHref' );
|
|
return model.schema.checkAttributeInSelection( model.createSelection( range ), 'linkHref' );
|
|
|
}
|
|
}
|