diff --git a/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx b/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx index fb0a9c64..a49915b0 100644 --- a/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx +++ b/src/components/Editor/TextBubbleMenu/TextBubbleMenu.tsx @@ -15,6 +15,15 @@ type BubbleMenuProps = { ref: (el: HTMLDivElement) => void } +const checkUrl = (url) => { + try { + new URL(url) + return url + } catch { + return `https://${url}` + } +} + export const TextBubbleMenu = (props: BubbleMenuProps) => { const { t } = useLocalize() const [textSizeBubbleOpen, setTextSizeBubbleOpen] = createSignal(false) @@ -59,7 +68,11 @@ export const TextBubbleMenu = (props: BubbleMenuProps) => { } const handleLinkFormSubmit = (value: string) => { - props.editor.chain().focus().setLink({ href: value }).run() + props.editor + .chain() + .focus() + .setLink({ href: checkUrl(value) }) + .run() } const currentUrl = createEditorTransaction( diff --git a/src/utils/validateUrl.ts b/src/utils/validateUrl.ts index 4578f421..9f416965 100644 --- a/src/utils/validateUrl.ts +++ b/src/utils/validateUrl.ts @@ -1,3 +1,3 @@ export const validateUrl = (value: string) => { - return /^((http|https):\/\/)?[^ "]+$/.test(value) + return value.includes('.') && !value.includes(' ') }