From 8630c8e630e9e8a7e1a5f59a18a74b5d5d9806ea Mon Sep 17 00:00:00 2001 From: Daniel Nunes <93351930+danimnunes@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:43:30 +0100 Subject: [PATCH] Desktop: Fixes #9950: Link pased in RTE editor is not underlined until switch to another note (#10202) --- .../gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx | 3 ++- packages/utils/url.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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); +}; +