MAJ gestion des pages services

This commit is contained in:
sebvtl728
2025-10-26 15:38:17 +01:00
parent 82406fb046
commit f242bcc5d6
11 changed files with 1866 additions and 195 deletions
+48
View File
@@ -0,0 +1,48 @@
const hasDomParser =
(typeof window !== "undefined" && typeof window.DOMParser !== "undefined") ||
typeof DOMParser !== "undefined";
const createDocument = (html) => {
if (!hasDomParser || !html) return null;
const ParserConstructor =
typeof DOMParser !== "undefined"
? DOMParser
: typeof window !== "undefined" && window.DOMParser
? window.DOMParser
: null;
if (!ParserConstructor) {
return null;
}
const parser = new ParserConstructor();
return parser.parseFromString(html, "text/html");
};
export const extractFirstImageSrc = (html) => {
if (!html) return "";
const doc = createDocument(html);
if (doc) {
const img = doc.querySelector("img");
if (img) {
return img.getAttribute("src") || "";
}
}
const match = html.match(/<img[^>]+src=["']([^"']+)["']/i);
return match?.[1] || "";
};
export const removeImageTags = (html) => {
if (!html) return "";
return html.replace(/<img\b[^>]*>/gi, "");
};
export const stripHtml = (html) => {
if (!html) return "";
const doc = createDocument(html);
if (doc) {
return doc.body.textContent || "";
}
return html.replace(/<[^>]*>/g, "");
};