')
html = html
.replace(/\*\*(.*?)\*\*/gim, '$1')
.replace(/\*(.*?)\*/gim, '$1')
.replace(/`([^`]+)`/gim, '$1')
html = html
.replace(/!\[([^\]]*)\]\(\s*(&[^)\s]+\.sha256)\s*\)/g, (_, alt, blob) =>
``
)
.replace(/\[video:([^\]]*)\]\(\s*(&[^)\s]+\.sha256)\s*\)/g, (_, _name, blob) =>
``
)
.replace(/\[audio:([^\]]*)\]\(\s*(&[^)\s]+\.sha256)\s*\)/g, (_, _name, blob) =>
``
)
.replace(/\[pdf:([^\]]*)\]\(\s*(&[^)\s]+\.sha256)\s*\)/g, (_, name, blob) =>
`${name || i18n.pdfFallbackLabel || 'PDF'}`
)
html = html
.replace(/\[@([^\]]+)\]\(@?([A-Za-z0-9+/=.\-]+\.ed25519)\)/g, (_, name, id) =>
`@${name}`
)
.replace(/@([A-Za-z0-9+/=.\-]+\.ed25519)/g, (_, id) =>
`@${id}`
)
const escAttr = (s) => String(s).replace(/"/g, '"').replace(/'/g, ''')
html = html
.replace(/#(\w+)/g, (_, tag) =>
`#${escAttr(tag)}`
)
.replace(/(https?:\/\/[^\s"'<>]+)/g, url =>
`${escAttr(url)}`
)
.replace(/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g, email =>
`${escAttr(email)}`
)
const lines = html.split('\n')
let result = ''
let inUL = false
let inOL = false
for (let line of lines) {
if (/^- /.test(line)) {
if (!inUL) {
result += '
'
inUL = true
}
result += `
${line.replace(/^- /, '')}
`
continue
}
if (/^\d+\. /.test(line)) {
if (!inOL) {
result += ''
inOL = true
}
result += `
${line.replace(/^\d+\. /, '')}
`
continue
}
if (inUL) {
result += '
'
inUL = false
}
if (inOL) {
result += ''
inOL = false
}
result += line + ' '
}
if (inUL) result += ''
if (inOL) result += ''
return result
}
module.exports = { renderTextWithStyles, renderTextPreview }