mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
moving v2 to top level
This commit is contained in:
36
src/services/utils/htmlIsCloseEnough.ts
Normal file
36
src/services/utils/htmlIsCloseEnough.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
const scriptRegex = /<script.*?<\/script>/g;
|
||||
const linkTagRegex = /<link\s+rel="[^"]*"\s+href="[^"]*"[^>]*>/g;
|
||||
const htmlAttribute = /\s+\w+="[^"]*"|\s+\w+='[^']*'|\s+\w+=[^\s>]+/g;
|
||||
|
||||
function replaceUnicodeEscapes(input: string) {
|
||||
return input.replace(/\\u[\dA-Fa-f]{4}/g, (match) => {
|
||||
// Extract the hexadecimal part and convert it to a character
|
||||
return String.fromCharCode(parseInt(match.slice(2), 16));
|
||||
});
|
||||
}
|
||||
|
||||
export const removeHtmlDetails = (html: string) => {
|
||||
const withoutUnicode = replaceUnicodeEscapes(html);
|
||||
return withoutUnicode
|
||||
.replaceAll(scriptRegex, "")
|
||||
.replaceAll(linkTagRegex, "")
|
||||
.replaceAll(htmlAttribute, "")
|
||||
.replaceAll(/\\"/g, '"')
|
||||
.replaceAll(/\s/g, "")
|
||||
.replaceAll(/<hr\s*\/?>/g, "<hr>")
|
||||
.replaceAll(/<br\s*\/?>/g, "<br>")
|
||||
.replaceAll(/>/g, "")
|
||||
.replaceAll(/</g, "")
|
||||
.replaceAll(/>/g, "")
|
||||
.replaceAll(/</g, "")
|
||||
.replaceAll(/"/g, "")
|
||||
.replaceAll(/"/g, "")
|
||||
.replaceAll(/&/g, "")
|
||||
.replaceAll(/&/g, "");
|
||||
};
|
||||
|
||||
export const htmlIsCloseEnough = (html1: string, html2: string) => {
|
||||
const simple1 = removeHtmlDetails(html1);
|
||||
const simple2 = removeHtmlDetails(html2);
|
||||
return simple1 === simple2;
|
||||
};
|
||||
Reference in New Issue
Block a user