Summernote: insertLink adds "http://" to mailto links

Created on 5 Jun 2015  路  4Comments  路  Source: summernote/summernote

Hi,

When trying to insert a mailto: link using the insert link Summernote will always add an "http://" to the link using Summernote 0.6.7.

Thanks

Most helpful comment

This workaround might help someone:

$('summernote').summernote({
      onCreateLink: function (url) {
        var email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
        var phone = /^\+?[\d()-,.]+/
        var schemed = /^[a-z]+:/i
        url = url.trim();
        if (email.test(url)) {
            url = 'mailto:' + url;
        } else if (phone.test(url)) {
                    url = 'tel:' + url.replace(/[ ().\-]/g,'');
        } else if (!schemed.test(url)) {
            url = 'http://' + url;
        }
        return url;
    }
});

All 4 comments

@bbyrdhouse

please, check for #1037.

Applies to tel: sms: geo: and other URL schemes too. If a url matches /^[a-z]+:/i it shouldn't tamper with it.

This workaround might help someone:

$('summernote').summernote({
      onCreateLink: function (url) {
        var email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
        var phone = /^\+?[\d()-,.]+/
        var schemed = /^[a-z]+:/i
        url = url.trim();
        if (email.test(url)) {
            url = 'mailto:' + url;
        } else if (phone.test(url)) {
                    url = 'tel:' + url.replace(/[ ().\-]/g,'');
        } else if (!schemed.test(url)) {
            url = 'http://' + url;
        }
        return url;
    }
});

Originally, link dialog of summernote does not have default scheme (like http://) on it. But it added http:// if it does not have proper one.
But we decided to drop this feature - user can customize onCreateLink (as @m-z-b did above) and there are may several different taste on creating link and its patterns.

So, @easylogic made https://github.com/summernote/summernote/pull/1090.
If someone has an opinion for this, please open a new issue.

Thanks all!

Was this page helpful?
0 / 5 - 0 ratings