Skip to content
Snippets Groups Projects
Commit 1f3ce1b5 authored by Igor Markin's avatar Igor Markin
Browse files

Remove WordSection print function

parent 1b80f7f4
No related branches found
No related tags found
1 merge request!18Optimisations
......@@ -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++) {
......
// 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment