.
This commit is contained in:
@ -29,9 +29,37 @@ function padStart(s, num, char) {
|
||||
return (char ?? ' ').repeat(num - s.length);
|
||||
}
|
||||
|
||||
function formatUrl(msg) {
|
||||
//const urlReg = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ig;
|
||||
//const urlArrray = str.match(urlReg);
|
||||
const p = /(http|ftp|https):\/\/.+?(\s|\r\n|\r|\n|\"|\'|\*|$)/g;
|
||||
const r = msg.match(p);
|
||||
msg = htmlencode(msg);
|
||||
|
||||
if (r?.length > 0) {
|
||||
const rs = [];
|
||||
for (let t of r) {
|
||||
t = t.replace(/["'\r\n ]/g, '');
|
||||
if (rs.indexOf(t) < 0) {
|
||||
rs.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
for (let r of rs) {
|
||||
msg = msg.replaceAll(r, '<a target="_blank" href="' + r + '"><svg><use xlink:href="' + ((typeof consts !== 'undefined' && consts.path) ?? '') + 'fonts/fa-regular.svg#link"></use></svg></a>');
|
||||
}
|
||||
}
|
||||
|
||||
return msg
|
||||
.replaceAll('\r\n', '<br/>')
|
||||
.replaceAll('\n', '<br/>')
|
||||
.replaceAll(' ', ' ');
|
||||
}
|
||||
|
||||
export {
|
||||
nullOrEmpty,
|
||||
contains,
|
||||
endsWith,
|
||||
padStart
|
||||
padStart,
|
||||
formatUrl
|
||||
}
|
Reference in New Issue
Block a user