summaryrefslogtreecommitdiff
path: root/src/xmlfixups.cpp
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-07-11 22:07:43 +0000
committerStef Walter <stef@memberwebs.com>2004-07-11 22:07:43 +0000
commit5eb52056cf799bd0f55b642a513e024c0304c604 (patch)
treea74754e3fdff365df1e481ddf2c4fefdd3014b19 /src/xmlfixups.cpp
parent6469807b6ca403cb585616fe3b9c0607ba391529 (diff)
Fixed grouping issues
Consolidate footnotes to end Proper ref format Fixed 'removeDuplicate' bugs
Diffstat (limited to 'src/xmlfixups.cpp')
-rw-r--r--src/xmlfixups.cpp164
1 files changed, 112 insertions, 52 deletions
diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp
index 7201703..64d360d 100644
--- a/src/xmlfixups.cpp
+++ b/src/xmlfixups.cpp
@@ -41,6 +41,21 @@
#include "domhelpers.h"
#include "tags.h"
+static const char* kNoDuplicates[] =
+ { kElB, kElU, kElI, kElColor, kElHide, kElColor, kElSuper, kElSub, NULL };
+
+static const char* kRemoveTags[] =
+ { kElDest, kElListdef, kElListtable, NULL };
+
+static const char* kBlockTags[] =
+ { kElTable, kElPara, NULL };
+
+static const char* kHideList[] =
+ { kAtId, kAtList, NULL };
+
+static const char* kConsolidateEnd[] =
+ { kElFootNote, NULL };
+
void RtfFixups::breakBreak(DOM::Document& doc, const string& contain,
const string& tag)
{
@@ -668,72 +683,117 @@ void RtfFixups::fixBlocks(const DOM::Document doc)
}
}
-
/**
- * Removes adjacent duplicate nodes of certain names
+ * Consolidates a certain tag types at the end of the document
*/
-void RtfFixups::removeDuplicates(const DOM::Document& doc)
+void RtfFixups::consolidateEndTags(DOM::Document& doc)
{
- // Go through the list of nodes
- for(const char** t = kNoDuplicates; *t = NULL; t++)
- {
- DOM::NodeList elements = doc.getElementsByTagName(*t);
- if(elements != NULL)
- {
- int x = elements->getLength();
- for(int j = 0; j < elements->getLength(); j++)
- {
+ DOM::Element top = doc.getDocumentElement();
+ ASSERT(top != NULL);
- // Make sure it's a valid element
+ for(const char** t = kConsolidateEnd; *t != NULL; t++)
+ {
+ DOM::NodeList elements = doc.getElementsByTagName(*t);
+ if(elements != NULL)
+ {
+ int x = elements->getLength();
+ for(int j = 0; j < x; j++)
+ {
+ // Make sure it's a valid element
DOM::Element element = (const DOM::Element&)elements->item(j);
- if(element == NULL)
+ if(element == NULL)
continue;
- // Get neighbors
- DOM::Node previous = element.getPreviousSibling();
- DOM::Node next = element.getNextSibling();
-
- // Make sure it's still in the document, as we may have
- // removed it on a previous loop
- DOM::Node parent = element.getParentNode();
+ DOM::Element parent = (const DOM::Element&)element.getParentNode();
if(parent == NULL)
- continue;
+ continue;
- // Combine previous if valid
- if(previous != NULL && previous.getNodeType() == DOM::Node::ELEMENT_NODE &&
- DOMHelpers::isEqualElement((DOM::Element&)previous, element))
- {
- while(previous.hasChildNodes())
+ // Remove it from it's child
+ parent.removeChild(element);
+
+ // And append it to the end of the document
+ top.appendChild(element);
+ }
+ }
+ }
+}
+
+/**
+ * Removes adjacent duplicate nodes of certain names
+ */
+void RtfFixups::removeDuplicates(const DOM::Document& doc)
+{
+ bool found;
+
+ do
+ {
+ found = false;
+
+ // Go through the list of nodes
+ for(const char** t = kNoDuplicates; *t != NULL; t++)
+ {
+ DOM::NodeList elements = doc.getElementsByTagName(*t);
+ if(elements != NULL)
+ {
+ int x = elements->getLength();
+ for(int j = 0; j < x; j++)
+ {
+ // Make sure it's a valid element
+ DOM::Element element = (const DOM::Element&)elements->item(j);
+ if(element == NULL)
+ continue;
+
+ // Get neighbors
+ DOM::Node previous = element.getPreviousSibling();
+ DOM::Node next = element.getNextSibling();
+
+ // Make sure it's still in the document, as we may have
+ // removed it on a previous loop
+ DOM::Node parent = element.getParentNode();
+ if(parent == NULL)
+ continue;
+
+ // Combine previous if valid
+ if(previous != NULL && previous.getNodeType() == DOM::Node::ELEMENT_NODE &&
+ DOMHelpers::isEqualElement((DOM::Element&)previous, element))
{
- DOM::Node child = previous.removeChild(previous.getLastChild());
- if(child != NULL)
- {
- if(element.hasChildNodes())
- element.insertBefore(child, element.getFirstChild());
- else
- element.appendChild(child);
+ while(previous.hasChildNodes())
+ {
+ DOM::Node child = previous.removeChild(previous.getLastChild());
+ if(child != NULL)
+ {
+ if(element.hasChildNodes())
+ element.insertBefore(child, element.getFirstChild());
+ else
+ element.appendChild(child);
+ }
}
- }
- // Remove duplicate node
- parent.removeChild(previous);
- }
+ // Remove duplicate node
+ parent.removeChild(previous);
+ found = true;
+ }
- // Combine next if valid
- if(next != NULL && next.getNodeType() == DOM::Node::ELEMENT_NODE &&
- DOMHelpers::isEqualElement((DOM::Element&)next, element))
- {
- while(next.hasChildNodes())
+ // Combine next if valid
+ if(next != NULL && next.getNodeType() == DOM::Node::ELEMENT_NODE &&
+ DOMHelpers::isEqualElement((DOM::Element&)next, element))
{
- DOM::Node child = next.removeChild(next.getFirstChild());
- if(child != NULL)
- element.appendChild(child);
+ while(next.hasChildNodes())
+ {
+ DOM::Node child = next.removeChild(next.getFirstChild());
+ if(child != NULL)
+ element.appendChild(child);
+ }
+
+ // Remove duplicate node
+ parent.removeChild(next);
+ found = true;
}
+ }
+ }
+ }
- // Remove duplicate node
- parent.removeChild(next);
- }
- }
- }
- }
+ // Keep looping until no more duplicates found
+ }
+ while(found);
}