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

Remove empty paragraphs created by Outlook desktop

parent cca327d1
No related branches found
No related tags found
1 merge request!15Add READMEs for Outlook desktop cases
......@@ -12,5 +12,9 @@ describe("[HTML] Outlook-Outlook emails normalization", () => {
EMAIL_VENDORS.OUTLOOK
);
describe("Chrome-Chrome", describeFunction("chrome-chrome", ["16"], []));
//describe("Chrome-Chrome", describeFunction("chrome-chrome", ["16"], []));
describe(
"MacOS-MacOS",
describeFunction("macos-macos", ["sss"], ["01", "02"])
);
});
export const unwindTags = (node: Element | Document, tagName: string): void => {
const tags = node.getElementsByTagName(tagName);
//Sort tags by depth to start unwinding the deepest ones, which does not contain nested spans
export const unwindTags = (nodes: Array<Node>): void => {
//Sort nodes by depth to start unwinding the deepest ones
const tagsDepths: { depth?: Array<Node> } = {};
Array.from(tags).forEach((span: Node) => {
Array.from(nodes).forEach((span: Node) => {
let descendant = span;
let parent = descendant.parentNode;
......
// TODO: Move this logic to amendOutlookNodes
import { printHtmlChildren } from "../HTMLNormalizer";
import { ELEMENT_NODE } from "../../constants";
import { ELEMENT_NODE, TEXT_NODE } from "../../constants";
import {
ATTRIBUTES_TO_KEEP,
cloneAnchorFromPane,
pruneElement,
} from "./common";
import { unwindTags } from "./nodesAmendingFunctions";
export const printOutlookElement = (node: Node): string => {
if (node.nodeType === ELEMENT_NODE) {
......@@ -25,7 +26,8 @@ export const pruneOutlookElement = (element: HTMLElement): boolean => {
}
// Remove Outlook generic <o:*> tags
return !!element.nodeName.toLowerCase().startsWith("o:");
// return !!element.nodeName.toLowerCase().startsWith("o:");
return false;
};
const qrCodeContainerIds = {
......@@ -67,59 +69,49 @@ const removeQrCodeNodes = (document: HTMLDocument) => {
export const amendOutlookNodes = (document: HTMLDocument): void => {
/**
* Remove quoted text
* Remove QR code entries
*/
// Quoted text in web apps
// const appendOnSend = document.querySelector(
// "[id*='appendonsend']"
// ) as Node;
//
// if (appendOnSend) {
// let child = appendOnSend;
// while (child) {
// const nextSibling = child.nextSibling;
// child.parentNode.removeChild(child);
// child = nextSibling as Node;
// }
// }
// Quoted text in desktop apps
// let mailOriginal = document.querySelector("[name*='_MailOriginal']") as HTMLElement;
// if (mailOriginal) {
// let removeCurrent = true;
// while (mailOriginal !== document.body) {
// while (mailOriginal.nextSibling) {
// mailOriginal.nextSibling.remove();
// }
// const currentNode = mailOriginal;
// mailOriginal = mailOriginal.parentElement;
// if (removeCurrent && currentNode.previousSibling) {
// currentNode.remove();
// removeCurrent = false;
// }
// }
// }
// if (mailOriginal) {
// const separatorCandidate = mailOriginal.parentNode as Node;
//
// // while (!(separatorCandidate.parentNode as Element).classList.contains("WordSection1")) {
// // separatorCandidate = separatorCandidate.parentNode;
// // }
//
// let child = separatorCandidate;
// while (child) {
// const nextSibling = child.nextSibling;
// child.parentNode.removeChild(child);
// child = nextSibling as Node;
// }
// }
removeQrCodeNodes(document);
/**
* Remove QR code entries
* Remove Word o:p paragraphs
*/
const ops = document.getElementsByTagName("o:p");
Array.from(ops).forEach((op) => op.parentNode.removeChild(op));
removeQrCodeNodes(document);
/**
* Remove empty paragraphs
*/
const ps = document.getElementsByTagName("p");
Array.from(ps).forEach((p) => {
if (p.childNodes.length === 0) {
p.parentNode.removeChild(p);
}
if (p.childNodes.length === 1 && p.childNodes[0].nodeType === TEXT_NODE) {
const text = p.childNodes[0].textContent;
if (!text.replace(/&nbsp;/g, "").trim()) {
p.parentNode.removeChild(p);
}
}
});
/**
* Unwind all MSONormal, because outlook might wrap them into <div></div>
*/
const msoNormalWrappers = document.getElementsByClassName("MsoNormal");
const msoNormalParents = Array.from(msoNormalWrappers)
.map((node) => node.parentNode)
.filter((node, index, self) => self.indexOf(node) === index);
unwindTags(msoNormalParents);
/**
* Unwind WordSection tags
*/
const wordSectionWrappers = document.getElementsByClassName("WordSection1");
unwindTags(Array.from(wordSectionWrappers));
/**
* Get rid of attachments panes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment