From 25cb9014c4ff55834035aca7d1f2a43de2d68465 Mon Sep 17 00:00:00 2001 From: JakubPapso <“jakubpapso@gmail.com”> Date: Tue, 9 Jul 2024 13:35:01 +0200 Subject: [PATCH] [server links] styling support (lists, bold, italic..) --- .../plugins/tm@_utils/server-links.utils.ts | 43 ++++++------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/app/src/plugins/tm@_utils/server-links.utils.ts b/app/src/plugins/tm@_utils/server-links.utils.ts index 22f972a..f52b3ff 100644 --- a/app/src/plugins/tm@_utils/server-links.utils.ts +++ b/app/src/plugins/tm@_utils/server-links.utils.ts @@ -27,45 +27,26 @@ export function prepareHTMLDescription(description) { const os = detectOS() - // make an array from the description of strings from between

and

tags - const paragraphs = description.split('

').map(p => p.split('

')[0]) + if (os === 'mac') { + description = description.replace(/\\\\/g, 'smb://') + + // find all smb links and replace them with clickable links, separated by ' ', '<', '>', '"', and '(', ')' characters + description = description.replace(/(smb:\/\/[^\s<>"()]+)/g, '$1') + } else { + description = description.replace(/smb:\/\//g, '\\\\') - const modifiedParagraphs = paragraphs.map(paragraph => { - const words = paragraph.split(' ') - const modifiedWords = words.map(word => { - let link = null - - if (os === 'mac' && word.startsWith('smb://')) { - link = word - } else if (os === 'win' && word.startsWith('\\\\')) { - link = `${word.replace(/\//g, '\\')}` - } else if (os === 'mac' && word.startsWith('\\\\')) { - const smbLink = 'smb:' + word.replace(/\\/g, '/') - link = smbLink - } else if (os === 'win' && word.startsWith('smb://')) { - const windowsLink = word.replace(/^smb:/, '').replace(/\//g, '\\') - link = `${windowsLink}` - } - - if (!link) return word - - if (os === 'mac') return `${link}` - - return `${link}` - }) - - return `

${modifiedWords.join(' ')}

` - }) - - description = modifiedParagraphs.join('') + // find all windows links and replace them with clickable links, separated by ' ', '<', '>', '"', and '(', ')' characters + description = description.replace(/(\\\\[^\s<>"()]+)/g, function(match) { + return '' + match + ''; + }); + } return description; } function getCopyFunction(text) { return ` - console.log('${text.replace(/\\/g, '\\\\')}') if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText('${text.replace(/\\/g, '\\\\')}').then(() => { window.toast.success('Link copied to clipboard!')