plate icon indicating copy to clipboard operation
plate copied to clipboard

Tel link doesn't work Link Plugin

Open espipj opened this issue 1 year ago • 3 comments

Description

As of now tel: links doesn't work either but they're are included under default "allowedSchemas" here so sanitizeUrl will never run.

Related PR: https://github.com/udecode/plate/pull/2444

Steps to Reproduce

Create a link in the editor using "tel:123456"

Expected Behavior

Link gets created if "tel" is under "allowedSchemas" (there by default)

Environment

  • slate:
  • slate-react:
  • browser: chrome

Bounty

Click here to add a bounty via Algora.

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar

espipj avatar May 29 '24 16:05 espipj

It looks like the problem is that the default isUrl helper returns false for a correctly formatted tel: URL. If you could patch that helper to add tel: as a special case, that should resolve the issue, I think.

Changing isUrl to return true for anything that can be parsed with new URL(...) probably isn't what we want, since this would result in false positives when pasting strings containing colons. new URL('hello:world') // parses successfully

12joan avatar May 29 '24 17:05 12joan

Hey! That was what was done fore mailto:here: https://github.com/udecode/plate/pull/2444/files#diff-62c6d5e72c540099f6f0662214376ae7aba81cd9fe0b1f591a7b0b6e534c7a0aR8

espipj avatar May 29 '24 17:05 espipj

I personally don't think a patch of a package should mark the issue as resolved, in fact it seems like a proper bug more people may face...

On Thu, 10 Oct 2024, 17:54 Ziad Beyens, @.***> wrote:

Closed #3230 https://github.com/udecode/plate/issues/3230 as completed.

— Reply to this email directly, view it on GitHub https://github.com/udecode/plate/issues/3230#event-14594617780, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCFC6VYAAQ62BLYOZXPI4LZ22WKRAVCNFSM6AAAAABIPJSP6OVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJUGU4TINRRG43TQMA . You are receiving this because you authored the thread.Message ID: @.***>

espipj avatar Oct 11 '24 00:10 espipj

@espipj By patching the helper, 12joan@ did not mean to patch the package. Here's how you can override isUrl, which I do as well, in my implementation of PlateJS:

plugins: [
            LinkPlugin.configure({
                options: {
                    isUrl: (text: string) => // define a function to check if string should be a URL. You can use linkify-it NPM package,
                    getUrlHref: (text: string) => define a function to return the fully formatted link, e.g. mailto:[email protected] or tel:9991919191, again Linkify-it can be used for this,
                },
            }),
]

While we can certainly add this use case to LinkPlugin, users are still enabled to implement it themselves without much hassle. More info on link plugin: https://platejs.org/docs/link

abhi-bc avatar Oct 26 '24 01:10 abhi-bc

@espipj By patching the helper, 12joan@ did not mean to patch the package. Here's how you can override isUrl, which I do as well, in my implementation of PlateJS:

I actually meant that @espipj could make a PR with a patch changeset to fix this bug in isUrl

12joan avatar Oct 26 '24 07:10 12joan

That would indeed be nice as a built-in case, I'll turn this issue into a feature request.

zbeyens avatar Oct 26 '24 10:10 zbeyens