Piped/src/utils/HtmlUtils.js
2023-08-05 17:32:32 +01:00

14 lines
477 B
JavaScript

import DOMPurify from "dompurify";
export const purifyHTML = html => {
return DOMPurify.sanitize(html);
};
import linkifyHtml from "linkify-html";
export const rewriteDescription = 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>");
};