mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
parent
a861a8b95d
commit
70277fe077
3 changed files with 22 additions and 14 deletions
|
@ -4,22 +4,10 @@ export const purifyHTML = html => {
|
|||
return DOMPurify.sanitize(html);
|
||||
};
|
||||
|
||||
export const urlify = string => {
|
||||
if (!string) return "";
|
||||
const urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
|
||||
const emailRegex = /([\w-\\.]+@(?:[\w-]+\.)+[\w-]{2,4})/g;
|
||||
return string
|
||||
.replace(urlRegex, url => {
|
||||
if (url.endsWith("</a>") || url.endsWith("<a")) return url;
|
||||
return `<a href="${url}" target="_blank">${url}</a>`;
|
||||
})
|
||||
.replace(emailRegex, email => {
|
||||
return `<a href="mailto:${email}">${email}</a>`;
|
||||
});
|
||||
};
|
||||
import linkifyHtml from "linkify-html";
|
||||
|
||||
export const rewriteDescription = text => {
|
||||
return urlify(text)
|
||||
return linkifyHtml(text)
|
||||
.replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm, "$1")
|
||||
.replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm, "/watch?v=$1")
|
||||
.replaceAll("\n", "<br>");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue