diff --git a/src/global/actions/ui/messages.ts b/src/global/actions/ui/messages.ts index f26b19740..4a762ff42 100644 --- a/src/global/actions/ui/messages.ts +++ b/src/global/actions/ui/messages.ts @@ -608,7 +608,7 @@ addActionHandler('checkVersionNotification', (global, actions) => { chatId: SERVICE_NOTIFICATIONS_USER_ID, date: getServerTime(global.serverTimeOffset), content: { - text: parseMessageInput(versionNotification), + text: parseMessageInput(versionNotification, true), }, isOutgoing: false, }; diff --git a/src/util/parseMessageInput.ts b/src/util/parseMessageInput.ts index eff6a3d6f..8b443f54e 100644 --- a/src/util/parseMessageInput.ts +++ b/src/util/parseMessageInput.ts @@ -1,5 +1,6 @@ import { ApiMessageEntity, ApiMessageEntityTypes, ApiFormattedText } from '../api/types'; import { IS_EMOJI_SUPPORTED } from './environment'; +import { RE_LINK_TEMPLATE } from '../config'; const ENTITY_CLASS_BY_NODE_NAME: Record = { B: ApiMessageEntityTypes.Bold, @@ -17,9 +18,9 @@ const ENTITY_CLASS_BY_NODE_NAME: Record = { const MAX_TAG_DEEPNESS = 3; -export default function parseMessageInput(html: string): ApiFormattedText { +export default function parseMessageInput(html: string, withMarkdownLinks = false): ApiFormattedText { const fragment = document.createElement('div'); - fragment.innerHTML = parseMarkdown(html); + fragment.innerHTML = withMarkdownLinks ? parseMarkdown(parseMarkdownLinks(html)) : parseMarkdown(html); const text = fragment.innerText.trim().replace(/\u200b+/g, ''); let textIndex = 0; let recursionDeepness = 0; @@ -101,6 +102,13 @@ function parseMarkdown(html: string) { return parsedHtml; } +function parseMarkdownLinks(html: string) { + return html.replace(new RegExp(`\\[([^\\]]+?)]\\((${RE_LINK_TEMPLATE}+?)\\)`, 'g'), (_, text, link) => { + const url = link.includes('://') ? link : link.includes('@') ? `mailto:${link}` : `http://${link}`; + return `${text}`; + }); +} + function getEntityDataFromNode( node: ChildNode, rawText: string,