diff --git a/src/HTMLNormalizer/HTMLNormalizer.ts b/src/HTMLNormalizer/HTMLNormalizer.ts index 601e7ee4ca938f9034d2fe923ed96efe312c075a..0701019ec7ab770929d411e627be69542ef900c1 100644 --- a/src/HTMLNormalizer/HTMLNormalizer.ts +++ b/src/HTMLNormalizer/HTMLNormalizer.ts @@ -8,7 +8,6 @@ import { import { amendOutlookNodes, cleanupOutlookElementAttributes, - printOutlookElement, pruneOutlookElement, } from "./strategies/outlook"; import { EMAIL_VENDORS } from "../constants"; @@ -36,10 +35,6 @@ const attributesCleanupFunctions = { [EMAIL_VENDORS.OUTLOOK]: cleanupOutlookElementAttributes, }; -const vendorPrintingFunctions = { - [EMAIL_VENDORS.OUTLOOK]: printOutlookElement, -}; - export const normalizeVendorHtml = ( document: HTMLDocument, vendor: string @@ -75,12 +70,7 @@ export const normalizeVendorHtml = ( cleanupHtmlNodeAttributes(document, elementAttributesCleanupFunction); } - /** - * Print nodes - */ - const vendorPrintFunction = vendorPrintingFunctions[vendor]; - - return printHtmlChildren(mimeBody, vendorPrintFunction, 0); + return printHtmlChildren(mimeBody, 0); }; export const extractPseudoPlainPart = ( @@ -111,22 +101,18 @@ export const extractPseudoPlainPart = ( return normalizedTextContent; }; -export const printHtmlChildren = ( - node: Node, - printFunction: (node: Node) => string, - depth: number -): string => { +export const printHtmlChildren = (node: Node, depth: number): string => { let child = node.firstChild; if (!child) { return ""; } if (child == node.lastChild && child.nodeType == TEXT_NODE) { - return printHtmlNode(child, printFunction, depth); + return printHtmlNode(child, depth); } else { let result = ""; while (child) { - result = result.concat(printHtmlNode(child, printFunction, depth)); + result = result.concat(printHtmlNode(child, depth)); child = child.nextSibling; } @@ -134,20 +120,9 @@ export const printHtmlChildren = ( } }; -export const printHtmlNode = ( - node: Node, - printFunction: (node: Node) => string, - depth: number -): string => { +export const printHtmlNode = (node: Node, depth: number): string => { let result = ""; - if (printFunction) { - const customPrintout = printFunction(node); - if (customPrintout) { - return customPrintout; - } - } - switch (node.nodeType) { case TEXT_NODE: { const text = removeSpacesAndLinebreaks(node.textContent); @@ -160,7 +135,7 @@ export const printHtmlNode = ( break; } case DOCUMENT_NODE: - result += printHtmlChildren(node, printFunction, depth); + result += printHtmlChildren(node, depth); break; case ELEMENT_NODE: result += "<" + node.nodeName; @@ -174,7 +149,7 @@ export const printHtmlNode = ( }); if (node.firstChild) { - const printout = printHtmlChildren(node, printFunction, depth + 1); + const printout = printHtmlChildren(node, depth + 1); if (printout.trim().length === 0) { result += "/>"; } else { @@ -261,7 +236,7 @@ export const escapeHtmlString = (string: string): string => { let escape; let html = ""; - let index = 0; + let index; let lastIndex = 0; for (index = match.index; index < str.length; index++) { diff --git a/src/HTMLNormalizer/strategies/outlook.ts b/src/HTMLNormalizer/strategies/outlook.ts index 835481239abceaa49fca82d056acc396ad48fd02..25b8049ea73c0dc2aa430339e048ffe179206f3a 100644 --- a/src/HTMLNormalizer/strategies/outlook.ts +++ b/src/HTMLNormalizer/strategies/outlook.ts @@ -1,5 +1,3 @@ -// TODO: Move this logic to amendOutlookNodes -import { printHtmlChildren } from "../HTMLNormalizer"; import { ELEMENT_NODE, TEXT_NODE } from "../../constants"; import { ATTRIBUTES_TO_KEEP, @@ -8,14 +6,6 @@ import { } from "./common"; import { unwindTags } from "./nodesAmendingFunctions"; -export const printOutlookElement = (node: Node): string => { - if (node.nodeType === ELEMENT_NODE) { - if ((node as HTMLElement).classList.contains("WordSection1")) { - return printHtmlChildren(node, null, 0); - } - } -}; - /** * Returns true if element should be completely removed * @param element