summaryrefslogtreecommitdiff
path: root/src/xmlfixups.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlfixups.cpp')
-rw-r--r--src/xmlfixups.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp
index 64d360d..fe2232b 100644
--- a/src/xmlfixups.cpp
+++ b/src/xmlfixups.cpp
@@ -56,6 +56,9 @@ static const char* kHideList[] =
static const char* kConsolidateEnd[] =
{ kElFootNote, NULL };
+static const char* kConsolidateStart[] =
+ { kElInfo, kElStylesheet, NULL };
+
void RtfFixups::breakBreak(DOM::Document& doc, const string& contain,
const string& tag)
{
@@ -719,6 +722,44 @@ void RtfFixups::consolidateEndTags(DOM::Document& doc)
}
/**
+ * Consolidates a certain tag types at the start of the document
+ */
+void RtfFixups::consolidateStartTags(DOM::Document& doc)
+{
+ DOM::Element top = doc.getDocumentElement();
+ ASSERT(top != NULL);
+
+ DOM::Node first = top.getFirstChild();
+
+ for(const char** t = kConsolidateStart; *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 || element == first)
+ continue;
+
+ DOM::Element parent = (const DOM::Element&)element.getParentNode();
+ if(parent == NULL)
+ continue;
+
+ // Remove it from it's child
+ parent.removeChild(element);
+
+ // And put at start of the document of the document
+ ASSERT(first != NULL);
+ top.insertBefore(element, first);
+ }
+ }
+ }
+}
+
+/**
* Removes adjacent duplicate nodes of certain names
*/
void RtfFixups::removeDuplicates(const DOM::Document& doc)