diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx index ac98b7a03..f579f3ce6 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx @@ -36,6 +36,7 @@ import { focus } from '@joplin/lib/utils/focusHandler'; const md5 = require('md5'); const { clipboard } = require('electron'); const supportedLocales = require('./supportedLocales'); +import { isLink } from '@joplin/utils/url'; const logger = Logger.create('TinyMCE'); @@ -1172,7 +1173,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { editor.insertContent(result.html); } } else { - if (BaseItem.isMarkdownTag(pastedText)) { // Paste a link to a note + if (BaseItem.isMarkdownTag(pastedText) || isLink(pastedText)) { // Paste a link to a note logger.info('onPaste: pasting as a Markdown tag'); const result = await markupToHtml.current(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, pastedText, markupRenderOptions({ bodyOnly: true })); editor.insertContent(result.html); diff --git a/packages/utils/url.ts b/packages/utils/url.ts index eed620c91..f67bb0aa5 100644 --- a/packages/utils/url.ts +++ b/packages/utils/url.ts @@ -100,3 +100,10 @@ export const fileUriToPath = (path: string, platform = 'linux') => { export const isDataUrl = (path: string) => { return path.startsWith('data:'); }; + +export const isLink = (text: string) => { + if (!text) return false; + const linkRegex = /^(https?|file|joplin):\/\/[^)\s]+$/; + return !!text.match(linkRegex); +}; +