|
@@ -21,6 +21,8 @@ import LinkActionsView from './ui/linkactionsview';
|
|
|
|
|
|
|
|
import linkIcon from '../theme/icons/link.svg';
|
|
import linkIcon from '../theme/icons/link.svg';
|
|
|
|
|
|
|
|
|
|
+// The regex checks for the protocol syntax ('xxxx://' or 'xxxx:')
|
|
|
|
|
+// or non-word characters at the beginning of the link ('/', '#' etc.).
|
|
|
const protocolRegExp = /^((\w+:(\/{2,})?)|(\W))/i;
|
|
const protocolRegExp = /^((\w+:(\/{2,})?)|(\W))/i;
|
|
|
const emailRegExp = /[\w-]+@[\w-]+\.+[\w-]+/i;
|
|
const emailRegExp = /[\w-]+@[\w-]+\.+[\w-]+/i;
|
|
|
const VISUAL_SELECTION_MARKER_NAME = 'link-ui';
|
|
const VISUAL_SELECTION_MARKER_NAME = 'link-ui';
|
|
@@ -177,12 +179,8 @@ export default class LinkUI extends Plugin {
|
|
|
this.listenTo( formView, 'submit', () => {
|
|
this.listenTo( formView, 'submit', () => {
|
|
|
const { value } = formView.urlInputView.fieldView.element;
|
|
const { value } = formView.urlInputView.fieldView.element;
|
|
|
|
|
|
|
|
- // The regex checks for the protocol syntax ('xxxx://' or 'xxxx:')
|
|
|
|
|
- // or non-word characters at the beginning of the link ('/', '#' etc.).
|
|
|
|
|
- const isProtocolNeeded = !!defaultProtocol && !protocolRegExp.test( value );
|
|
|
|
|
- const isEmail = emailRegExp.test( value );
|
|
|
|
|
-
|
|
|
|
|
- const protocol = isEmail ? 'mailto:' : defaultProtocol;
|
|
|
|
|
|
|
+ const protocol = emailRegExp.test( value ) ? 'mailto:' : defaultProtocol;
|
|
|
|
|
+ const isProtocolNeeded = !!protocol && !protocolRegExp.test( value );
|
|
|
const parsedValue = value && isProtocolNeeded ? protocol + value : value;
|
|
const parsedValue = value && isProtocolNeeded ? protocol + value : value;
|
|
|
|
|
|
|
|
editor.execute( 'link', parsedValue, formView.getDecoratorSwitchesState() );
|
|
editor.execute( 'link', parsedValue, formView.getDecoratorSwitchesState() );
|