Skip to content

Commit

Permalink
Regards issue #19:
Browse files Browse the repository at this point in the history
Now correctly creating the DIV element - supposedly.
  • Loading branch information
Eyal Rozenberg committed Aug 16, 2020
1 parent a5ca014 commit 244accb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/chrome/content/bidimailui-display-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ BiDiMailUI.Display = {
// moz-text-flowed message's DOM tree within a DIV
// (whose direction we can later set)
wrapTextNodesInFlowedMessageDOMTree : function(subBody) {
var clonedDiv = subBody.ownerDocument.createXULElement("DIV");
let ns = subBody.ownerDocument.documentElement.lookupNamespaceURI("html");
let clonedDiv = subBody.ownerDocument.createElementNS(ns, "div");
clonedDiv.setAttribute('bidimailui-generated', true);
var treeWalker = document.createTreeWalker(
subBody,
Expand All @@ -233,17 +234,17 @@ BiDiMailUI.Display = {
);
var node;
while ((node = treeWalker.nextNode())) {
if ((node.parentNode.nodeName != 'A') &&
(node.parentNode.nodeName != 'DIV') &&
(node.parentNode.nodeName != 'BLOCKQUOTE')) {
if ((node.parentNode.nodeName.toLowerCase() != 'a') &&
(node.parentNode.nodeName.toLowerCase() != 'div') &&
(node.parentNode.nodeName.toLowerCase() != 'blockquote')) {
// and other such elements within moz-text-flowed messages
#ifdef DEBUG_wrapTextNodesInFlowedMessageDOMTree
console.log("not handling node\n" + node.nodeValue + "\nwith parent node name " + node.parentNode.nodeName);
#endif
continue;
}
if (node.parentNode.hasAttribute('bidimailui-generated') ||
((node.parentNode.nodeName == 'A') &&
((node.parentNode.nodeName.toLowerCase() == 'A') &&
(node.parentNode.parentNode.hasAttribute('bidimailui-generated')))) {
#ifdef DEBUG_wrapTextNodesInFlowedMessageDOMTree
console.log("already handled node\n"+ node.nodeValue);
Expand All @@ -256,7 +257,7 @@ BiDiMailUI.Display = {
var wrapperDiv = clonedDiv.cloneNode(false);

var emptyLine;
if (node.parentNode.nodeName == 'A') {
if (node.parentNode.nodeName.toLowerCase() == 'a') {
node.parentNode.parentNode.replaceChild(wrapperDiv,node.parentNode);
wrapperDiv.appendChild(node.parentNode);
emptyLine = false;
Expand All @@ -274,13 +275,13 @@ BiDiMailUI.Display = {
// add everything within the current 'paragraph' to the new DIV
while (wrapperDiv.nextSibling) {
sibling = wrapperDiv.nextSibling
if (sibling.nodeName == 'BLOCKQUOTE') {
if (sibling.nodeName.toLowerCase() == 'blockquote') {
#ifdef DEBUG_wrapTextNodesInFlowedMessageDOMTree
console.log("hit blockquote, finishing walk");
#endif
break;
}
if (sibling.nodeName == 'BR') {
if (sibling.nodeName.toLowerCase() == 'br') {
if (!emptyLine) {
// if the DIV has any text content, it will
// have a one-line height; otherwise it will
Expand Down

0 comments on commit 244accb

Please sign in to comment.