Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL inside inline code is automatically converted into a link #319

Closed
dmgawel opened this issue Jun 22, 2023 · 6 comments · Fixed by #398
Closed

URL inside inline code is automatically converted into a link #319

dmgawel opened this issue Jun 22, 2023 · 6 comments · Fixed by #398
Assignees
Labels
bug Something isn't working good first issue Good for newcomers released Pull requests that have been released to production

Comments

@dmgawel
Copy link

dmgawel commented Jun 22, 2023

With the introduction of #309, URL typed inside inline code blocks are automatically converted into links, which is most likely not the behaviour we want. At least it's not what I would expect, as I usually use inline code block to avoid URL->link conversion. The conversion happens after closing the code block and pressing space.

CleanShot.2023-06-22.at.22.54.59.mp4
@rfgamaral
Copy link
Member

I took a quick look and I don't think a solution on our side will be possible, we'll need built-in support to disable autolinking when links are inside inline code marks. Support will need to be added to helpers/autolink.ts.

@rfgamaral rfgamaral added bug Something isn't working good first issue Good for newcomers labels Jun 23, 2023
@rfgamaral
Copy link
Member

rfgamaral commented Jun 23, 2023

I couldn't help myyself 😅 and I spend a bit of time digging for a solution. I believe I found one:

diff --git a/packages/extension-link/src/helpers/autolink.ts b/packages/extension-link/src/helpers/autolink.ts
index 123a610c2..71f00d856 100644
--- a/packages/extension-link/src/helpers/autolink.ts
+++ b/packages/extension-link/src/helpers/autolink.ts
@@ -107,18 +107,27 @@ export function autolink(options: AutolinkOptions): Plugin {
 
           find(lastWordBeforeSpace)
             .filter(link => link.isLink)
-            .filter(link => {
-              if (options.validate) {
-                return options.validate(link.value)
-              }
-              return true
-            })
             // calculate link position
             .map(link => ({
               ...link,
               from: lastWordAndBlockOffset + link.start + 1,
               to: lastWordAndBlockOffset + link.end + 1,
             }))
+            // ignore link inside code mark
+            .filter(link => {
+              return !newState.doc.rangeHasMark(
+                link.from,
+                link.to,
+                newState.schema.marks.code,
+              )
+            })
+            // validate link
+            .filter(link => {
+              if (options.validate) {
+                return options.validate(link.value)
+              }
+              return true
+            })
             // add link mark
             .forEach(link => {
               tr.addMark(

Anyone should feel free to open an upstream PR with the patch above, otherwise I'll do it myself, eventually.

@rfgamaral
Copy link
Member

Opened a PR upstream with the patch above. Assuming it gets merged, and once it gets merged, we still need to wait for a new Tiptap version to be published, and Typist updated with it, before being able to close this issue on our side.

@engfragui
Copy link

engfragui commented Aug 1, 2023

As a note, a side-effect caused by this issue is also that Cypress file names get treated as links 😅

Screenshot 2023-08-01 at 10 31 05 Screenshot 2023-08-01 at 10 30 21
CleanShot.2023-08-01.at.10.26.10.mp4

I guess this is because .cy gets detected as a website domain (I'm assuming it might happen with other file extensions other than .cy but haven't tested thoroughly).

@rfgamaral
Copy link
Member

@engfragui Yes, that's expected to happen because .cy is a valid TLD.

@doistbot
Copy link
Member

🎉 This issue has been resolved in version 1.4.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@doistbot doistbot added the released Pull requests that have been released to production label Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers released Pull requests that have been released to production
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants