Jump to content

Auto generate links


Recommended Posts

  • 2 weeks later...

The answer is no - the problem you have is how is the software to know that the entered text is to be automatically turned in to a URL?

You can assume that anything with https:// or http:// (or any other URL scheme) is going to be the start of a full URL because, well, it is. But it can't be assumed that other entered text is going to form a URL.


Link to comment
Share on other sites

Yes, you can do this by altering the configuration of CKEditor. As @Nathan Explosion pointed out, defining what the rules are to do so become the challenge.

Consider someone that misses a space between two sentences:


Hi there.Question for everyone...how do I know when my easy bake oven is warmed up enough for your recipe?

Would "there.Question" be converted to a link? Why? Why not? How about "everyone...how"?

You'd need to develop a regular expression to capture all your use cases and ignore what are probably not okay. In the days where there were a limited number of TLDs, it would have been easier, but now there are hundreds.

Using the autolink plugin, you can define a custom link regex for both links and e-mail addresses. The default ones depend on http(s) or ftp as a prefix. You're interested in CKEDITOR.config.autolink_urlRegex.

 * Regex used by the [Auto Link](https://ckeditor.com/cke4/addon/autolink) plugin to match URL adresses.
 * @cfg {RegExp} [autolink_urlRegex]
 * @since 4.11.0
 * @member CKEDITOR.config
CKEDITOR.config.autolink_urlRegex = /^(https?|ftp):\/\/(-\.)?([^\s\/?\.#]+\.?)+(\/[^\s]*)?[^\s\.,]$/i;
// Regex by Imme Emosol.



Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...