diff --git a/dist/HTMLNormalizer/strategies/common.d.ts b/dist/HTMLNormalizer/strategies/common.d.ts index 941768bf2d735ef85586db2b570dfcd32f7432ca..161a96cb61f3b373a940e012261b713e617887c2 100644 --- a/dist/HTMLNormalizer/strategies/common.d.ts +++ b/dist/HTMLNormalizer/strategies/common.d.ts @@ -1,8 +1,8 @@ export declare const ELEMENT_TYPES_TO_REMOVE: { - br: boolean; - hr: boolean; - use: boolean; - svg: boolean; + BR: boolean; + HR: boolean; + USE: boolean; + SVG: boolean; }; export declare const ATTRIBUTES_TO_KEEP: { alt: boolean; @@ -13,7 +13,7 @@ export declare const ATTRIBUTES_TO_KEEP: { href: boolean; value: boolean; }; -export declare const amendNodes: (document: HTMLDocument) => void; +export declare const normalizeDocumentCommon: (body: HTMLElement) => void; /** * Decides whether node should be removed * @param element diff --git a/dist/HTMLNormalizer/strategies/common.js b/dist/HTMLNormalizer/strategies/common.js index a3c0fdb2461dce759a173c896a0c9000e4daa596..07e2482119a66a2fb3ae6b7caee4e45d4f0768cb 100644 --- a/dist/HTMLNormalizer/strategies/common.js +++ b/dist/HTMLNormalizer/strategies/common.js @@ -1,14 +1,13 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.cloneAnchorFromPane = exports.pruneElement = exports.amendNodes = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0; +exports.cloneAnchorFromPane = exports.pruneElement = exports.normalizeDocumentCommon = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0; // this is a Node module. require is a must to work across different envs const URL = require("url-parse"); -const DUMMY_QR_CODE_ID = "dummyQrCode"; exports.ELEMENT_TYPES_TO_REMOVE = { - br: true, - hr: true, - use: true, - svg: true, + BR: true, + HR: true, + USE: true, + SVG: true, }; exports.ATTRIBUTES_TO_KEEP = { alt: true, @@ -19,11 +18,11 @@ exports.ATTRIBUTES_TO_KEEP = { href: true, value: true, }; -const amendNodes = (document) => { +const normalizeDocumentCommon = (body) => { /** * Unwind Outlook safelink wrappers */ - const anchors = document.getElementsByTagName("a"); + const anchors = body.getElementsByTagName("a"); for (const anchor of anchors) { const url = new URL(anchor.getAttribute("href"), true); if (url.host.includes("safelinks.protection.outlook.com")) { @@ -33,7 +32,7 @@ const amendNodes = (document) => { /** * Unwind Gmail "googleusercontent" wrappers */ - const images = document.getElementsByTagName("img"); + const images = body.getElementsByTagName("img"); for (const image of images) { let url; try { @@ -50,25 +49,13 @@ const amendNodes = (document) => { } } }; -exports.amendNodes = amendNodes; -/** - * Removes dummy QR code from HTML - * @param element - */ -const isDummyQrCode = (element) => { - if (element.id === DUMMY_QR_CODE_ID) { - return true; - } -}; +exports.normalizeDocumentCommon = normalizeDocumentCommon; /** * Decides whether node should be removed * @param element */ const pruneElement = (element) => { - if (isDummyQrCode(element)) { - return true; - } - return !!exports.ELEMENT_TYPES_TO_REMOVE[element.nodeName.toLowerCase()]; + return !!exports.ELEMENT_TYPES_TO_REMOVE[element.nodeName]; }; exports.pruneElement = pruneElement; const cloneAnchorFromPane = (a, pane) => { diff --git a/dist/HTMLNormalizer/strategies/gmail.d.ts b/dist/HTMLNormalizer/strategies/gmail.d.ts index 3c4b5badb32d304c2f4102d1e38f84f0d2381ada..648329dc31b46790443cc607e554acf75801c829 100644 --- a/dist/HTMLNormalizer/strategies/gmail.d.ts +++ b/dist/HTMLNormalizer/strategies/gmail.d.ts @@ -1,3 +1 @@ -export declare const pruneGmailElement: (element: HTMLElement) => boolean; -export declare const amendGmailNodes: (document: HTMLDocument) => void; -export declare const cleanupGMailElementAttributes: (element: HTMLElement) => void; +export declare const normalizeGmailDocument: (document: HTMLDocument) => void; diff --git a/dist/HTMLNormalizer/strategies/gmail.js b/dist/HTMLNormalizer/strategies/gmail.js index bb6db84be869a40f4ebce5b44491531cd8718f0b..2b151109ff954e869a58e1f563405e63e96c1b6e 100644 --- a/dist/HTMLNormalizer/strategies/gmail.js +++ b/dist/HTMLNormalizer/strategies/gmail.js @@ -1,12 +1,8 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanupGMailElementAttributes = exports.amendGmailNodes = exports.pruneGmailElement = void 0; +exports.normalizeGmailDocument = void 0; const common_1 = require("./common"); const constants_1 = require("../../constants"); -const pruneGmailElement = (element) => { - return common_1.pruneElement(element); -}; -exports.pruneGmailElement = pruneGmailElement; const qrCodeContainerIds = { vereignWrapperLink: 1 }; const removeQrCodeNodes = (document) => { const remove = (node) => { @@ -29,11 +25,10 @@ const removeQrCodeNodes = (document) => { const elementsToRemove = remove(document.body); elementsToRemove.forEach((element) => element.parentNode.removeChild(element)); }; -const amendGmailNodes = (document) => { - // unwindTags(document, "span"); +const normalizeGmailDocument = (document) => { removeQrCodeNodes(document); /** - * Look for attachments panes and remove everything but links + * Look for attachments panes and extract <a> tags from them */ const attachmentsPanes = Array.from(document.getElementsByClassName("gmail_chip")); attachmentsPanes.forEach((pane) => { @@ -46,21 +41,4 @@ const amendGmailNodes = (document) => { pane.parentNode.removeChild(pane); }); }; -exports.amendGmailNodes = amendGmailNodes; -const cleanupGMailElementAttributes = (element) => { - if (element.attributes.length > 0) { - for (const attribute of element.attributes) { - if (attribute.name === "data-surl") { - element.setAttribute("src", attribute.value); - } - } - for (let i = 0; i < element.attributes.length; i++) { - const attribute = element.attributes[i]; - if (!common_1.ATTRIBUTES_TO_KEEP[attribute.name]) { - element.removeAttribute(attribute.name); - i--; - } - } - } -}; -exports.cleanupGMailElementAttributes = cleanupGMailElementAttributes; +exports.normalizeGmailDocument = normalizeGmailDocument; diff --git a/dist/HTMLNormalizer/strategies/outlook.d.ts b/dist/HTMLNormalizer/strategies/outlook.d.ts index 7221552512ef82012b7775296602a220b2a2f19e..d2648c9c40ea653e4895a2da0b4d864a7ae700bf 100644 --- a/dist/HTMLNormalizer/strategies/outlook.d.ts +++ b/dist/HTMLNormalizer/strategies/outlook.d.ts @@ -1,8 +1 @@ -export declare const printOutlookElement: (node: Node) => string; -/** - * Returns true if element should be completely removed - * @param element - */ -export declare const pruneOutlookElement: (element: HTMLElement) => boolean; -export declare const amendOutlookNodes: (document: HTMLDocument) => void; -export declare const cleanupOutlookElementAttributes: (element: HTMLElement) => void; +export declare const normalizeOutlookDocument: (document: HTMLDocument) => void;