Search code examples
tinymcemailto

how to prevent automatically adding mailto attribute


When I write an email address (test@test.com) tinymce automatically adds a mailto link :

<a href="mailto:test@test.com">test@test.com</ a>

Is there a way to remove this feature and keep it only for site addresses - for example - www.test.com.


Solution

  • What you are seeing is due to the autolink plugin. You can set the regex that the plugin should use for matching links by using the autolink_pattern setting.

    The default value for this setting (as of TinyMCE 4.6.5) is:

    var AutoLinkPattern = 
    /^(https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.|(?:mailto:)?[A-Z0-9._%+\-]+@)(.+)$/i;
    

    (you can see this in the source code for the autolink plugin).

    Try putting this in your configuration:

    tinymce.init({
      selector: '#mytextarea'
      ...
      ...
      autolink_pattern: /^(https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)(.+)$/i,
    });
    

    In my testing this still converts URLs but does not convert email addresses.