From 47cc4a19eaa71281dbb30c31a4e7f974ad820f3a Mon Sep 17 00:00:00 2001 From: daniyal Date: Thu, 29 Aug 2024 14:32:27 +0500 Subject: [PATCH] fix: prepend https:// to url if no protocol is specified --- src/components/Inputs.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Inputs.tsx b/src/components/Inputs.tsx index 737d884..5a30009 100644 --- a/src/components/Inputs.tsx +++ b/src/components/Inputs.tsx @@ -146,11 +146,22 @@ type MenuBarProps = { const MenuBar = ({ editor }: MenuBarProps) => { const setLink = () => { - const url = prompt('URL') + // Prompt the user to enter a URL + let url = prompt('URL') + + // Check if the user provided a URL if (url) { + // If the URL doesn't start with 'http://' or 'https://', + // prepend 'https://' to the URL + if (!/^(http|https):\/\//i.test(url)) { + url = `https://${url}` + } + return editor.chain().focus().setLink({ href: url }).run() } + // If no URL was provided (e.g., the user cancels the prompt), + // return false, indicating that the link was not set. return false }