Support links in posts (expanded automatically as detected in clear text)

This commit is contained in:
Niko 2022-02-17 22:24:18 +01:00
parent ab8db4cf83
commit ee75bdca9d
1 changed files with 10 additions and 0 deletions

View File

@ -152,6 +152,16 @@ app.post = {
}
}
value = html2text(value);
const urlmatches = value.match(/https?:\/\/[^\s\"]+/g);
if (urlmatches !== undefined && urlmatches !== null) {
for (var i = 0; i < urlmatches.length; i++) {
try { new URL(urlmatches[i]).href.length > 0 }
catch (e) { continue; }
const modurl = urlmatches[i].replace(/^https?:\/\//,'');
value = value.replaceAll(urlmatches[i], '<a class="link" href="'+
htmlescape(urlmatches[i])+'">'+htmlescape(modurl)+'</a>');
}
}
for (var i = 0; i < replaceAfter.length; i++) {
const it = replaceAfter[i];
value = value.replaceAll(it[0], it[1]);