markdown-it / linkify-it

Links recognition library with full unicode support
http://markdown-it.github.io/linkify-it/
MIT License
655 stars 63 forks source link

Change default protocol in fuzzyLink option #112

Closed SSbit01 closed 3 weeks ago

SSbit01 commented 2 months ago

I am using markdown-it with linkify-it. It works great, however, when linkify-it recognizes a link without the protocol specified, it inserts HTTP instead of HTTPS. For example: "google.com" -> "http://google.com"

Is there any way to change the default protocol used?

lucianomlima commented 3 weeks ago

I'm trying to do the same thing. Is there a way to force https:// instead of http://?

SSbit01 commented 3 weeks ago

I'm trying to do the same thing. Is there a way to force https:// instead of http://?

I've finally figured it out. Just overriding the default function of linkify.normalize:

const md = markdownit({
  linkify: true,
});

md.linkify.normalize = function(match) {
  if (!match.schema) {
    match.url = "https://" + match.url;
  } else if (match.schema === "mailto:" && !match.url.startsWith("mailto:")) {
    match.url = "mailto:" + match.url;
  }
}