diff options
author | Stef Walter <stef@memberwebs.com> | 2005-06-08 18:10:54 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2005-06-08 18:10:54 +0000 |
commit | 67f2a873e52c1521aa06768bdbf059d9bd73a667 (patch) | |
tree | 04c4e4be152ced745e0b827c9cd29dbf5af5000c | |
parent | 182ccac47d8bb9b0c04078a893b31f99d31c9654 (diff) |
Fix problem with identical adjacent elements not getting combined properly. Like the <font> tag.
-rw-r--r-- | src/domhelpers.cpp | 3 | ||||
-rw-r--r-- | src/xmlfixups.cpp | 36 |
2 files changed, 17 insertions, 22 deletions
diff --git a/src/domhelpers.cpp b/src/domhelpers.cpp index d2b3b8b..0efb102 100644 --- a/src/domhelpers.cpp +++ b/src/domhelpers.cpp @@ -52,7 +52,6 @@ bool DOMHelpers::isEqualElement(const DOM::Element& el1, const DOM::Element& el2 { if(el1.getNodeName() != el2.getNodeName()) return false; - // Compare attributes DOM::NamedNodeMap at1 = el1.getAttributes(); DOM::NamedNodeMap at2 = el2.getAttributes(); @@ -66,7 +65,7 @@ bool DOMHelpers::isEqualElement(const DOM::Element& el1, const DOM::Element& el2 for(int i = 0; i < at1->getLength(); i++) { - DOM::Attr attr1 = (const DOM::Attr&)at1->item(0); + DOM::Attr attr1 = (const DOM::Attr&)at1->item(i); if(attr1 == NULL) return false; diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp index 2c05e3a..3989a0c 100644 --- a/src/xmlfixups.cpp +++ b/src/xmlfixups.cpp @@ -620,26 +620,22 @@ void XmlFixups::runPassTwo(const DOM::Document& doc) DOM::Element parent = (const DOM::Element&)el.getParentNode(); if(parent != NULL) { - // Loop till we find no more of the same - for(;;) - { - DOM::Node next = el.getNextSibling(); - - if(next == NULL || next.getNodeType() != DOM::Node::ELEMENT_NODE) - break; - - // If it's the same type of element ... - if(!DOMHelpers::isEqualElement((DOM::Element&)next, el)) - break; - - // NOTE: Notice we do nothing with attributes. Currently - // all elements in the duplicates list don't need that. - - while(next.hasChildNodes()) - el.appendChild(next.removeChild(next.getFirstChild())); - - // Remove duplicate node - parent.removeChild(next); + DOM::Node prev = el.getPreviousSibling(); + + if(prev != NULL && prev.getNodeType() == DOM::Node::ELEMENT_NODE) + { + // If it's the same type of element ... + if(DOMHelpers::isEqualElement((DOM::Element&)prev, el)) + { + // NOTE: Notice we do nothing with attributes. Currently + // all elements in the duplicates list don't need that. + + while(prev.hasChildNodes()) + el.appendChild(prev.removeChild(prev.getFirstChild())); + + // Remove duplicate node + parent.removeChild(prev); + } } } } |