This commit is contained in:
romankko2 committed 2024-07-09 14:14:59 +02:00
commit 01314fcccc
1 file changed
+12 -31
+12 -31
View File
@@ -27,45 +27,26 @@ export function prepareHTMLDescription(description) {
const os = detectOS() const os = detectOS()
// make an array from the description of strings from between <p> and </p> tags if (os === 'mac') {
const paragraphs = description.split('<p>').map(p => p.split('</p>')[0]) 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, '<a href="$1">$1</a>')
} else {
description = description.replace(/smb:\/\//g, '\\\\')
const modifiedParagraphs = paragraphs.map(paragraph => {
const words = paragraph.split(' ')
const modifiedWords = words.map(word => { // find all windows links and replace them with clickable links, separated by ' ', '<', '>', '"', and '(', ')' characters
let link = null description = description.replace(/(\\\\[^\s<>"()]+)/g, function(match) {
return '<span style="cursor: pointer; text-decoration: underline" onclick="' + getCopyFunction(match) + '">' + match + '</span>';
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 `<a href="${link}">${link}</a>`
return `<span style="cursor: pointer; text-decoration: underline" onclick="${getCopyFunction(link)}">${link}</span>`
})
return `<p>${modifiedWords.join(' ')}</p>`
})
description = modifiedParagraphs.join('')
return description; return description;
} }
function getCopyFunction(text) { function getCopyFunction(text) {
return ` return `
console.log('${text.replace(/\\/g, '\\\\')}')
if (navigator.clipboard && navigator.clipboard.writeText) { if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText('${text.replace(/\\/g, '\\\\')}').then(() => { navigator.clipboard.writeText('${text.replace(/\\/g, '\\\\')}').then(() => {
window.toast.success('Link copied to clipboard!') window.toast.success('Link copied to clipboard!')