Hypercontext / linkifyjs

JavaScript plugin for finding links in plain-text and converting them to HTML <a> tags.
https://linkify.js.org
MIT License
1.83k stars 182 forks source link

registerCustomProtocol doesn't linkify without double slashes #372

Closed aaronraimist closed 2 years ago

aaronraimist commented 2 years ago

The description for linkify.registerCustomProtocol says "Linkify will consider any string that begins with the given protocol followed by a : as a URL link" but that doesn't seem to be true. Linkifyjs seems to be looking for :// after the protocol for it to be considered a link.

URI schemes without an authority component such as geo:, matrix:, and xmpp: don't get linkified.

Here is an example: https://codepen.io/aaronraimist/pen/bGoOXrq. Only mailto gets linkified.

import * as linkify from "https://cdn.skypack.dev/linkifyjs";
import linkifyStr from "https://cdn.skypack.dev/linkify-string";

linkify.registerCustomProtocol("geo");
linkify.registerCustomProtocol("matrix");
linkify.registerCustomProtocol("xmpp");

createLink("mailto:test@example.com");
createLink("geo:37.786971,-122.399677");
createLink("matrix:r/someroom:example.org");
createLink("xmpp:romeo@montague.net?message");

function createLink(string) {
  console.log(linkifyStr(string));
  console.log(linkify.test(string));
}
nfrasser commented 2 years ago

Hi @aaronraimist, thanks for reporting. This is a known issue and will be fixed in v4 (#354)

toger5 commented 2 years ago

when will this be ready? I am currently adding a custom parser for matrix:u/... links. This causes all kinds of issues. Maybe I should open specific issues in what I am running into. This would be really really helpful!

nfrasser commented 2 years ago

@toger5 a beta is now available that you can try out:

npm install linkifyjs@beta

(Requires @beta versions of related Linkify plugins and interfaces)

nfrasser commented 2 years ago

No timeline yet on a stable release, there's still a few more features that need development

nfrasser commented 2 years ago

Fixed in latest v4 release. Have to add a second true argument to the registerCustomPrococol function call.