[server links] styling support (lists, bold, italic..)

This commit is contained in:
JakubPapso committed 2024-07-09 13:35:01 +02:00
1 parent 86d97c0130
commit 25cb9014c4
1 file changed
+11 -30
+11 -30
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://')
const modifiedParagraphs = paragraphs.map(paragraph => { // find all smb links and replace them with clickable links, separated by ' ', '<', '>', '"', and '(', ')' characters
const words = paragraph.split(' ') description = description.replace(/(smb:\/\/[^\s<>"()]+)/g, '<a href="$1">$1</a>')
} else {
description = description.replace(/smb:\/\//g, '\\\\')
const modifiedWords = words.map(word => {
let link = null
if (os === 'mac' && word.startsWith('smb://')) { // find all windows links and replace them with clickable links, separated by ' ', '<', '>', '"', and '(', ')' characters
link = word description = description.replace(/(\\\\[^\s<>"()]+)/g, function(match) {
} else if (os === 'win' && word.startsWith('\\\\')) { return '<span style="cursor: pointer; text-decoration: underline" onclick="' + getCopyFunction(match) + '">' + match + '</span>';
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!')