summaryrefslogtreecommitdiff
path: root/src/xmlfixups.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlfixups.cpp')
-rw-r--r--src/xmlfixups.cpp49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp
index 10b35f1..45fa59a 100644
--- a/src/xmlfixups.cpp
+++ b/src/xmlfixups.cpp
@@ -42,16 +42,22 @@
#include "tags.h"
static const char* kNoDuplicates[] =
- { kElB, kElU, kElI, kElColor, kElHide, kElSuper, kElSub, NULL };
+ { kElB, kElU, kElI, kElFont, kElHide, kElSuper, kElSub, NULL };
+
+static const char* kRequireAttrs[] =
+ { kElFont, NULL };
static const char* kRemoveTags[] =
- { kElDest, kElListdef, kElListtable, kElFontTable, NULL };
+ { kElDest, kElListdef, kElListtable, kElFontTable, kElFontDef, NULL };
+
+static const char* kRemoveEmpty[] =
+ { kElOptions, kElList, NULL };
static const char* kBlockTags[] =
- { kElTable, kElPara, NULL };
+ { kElTable, kElPara, NULL };
static const char* kHideList[] =
- { kAtId, kAtList, NULL };
+ { kAtId, kAtList, NULL };
static const char* kConsolidateEnd[] =
{ kElFootNote, NULL };
@@ -69,6 +75,8 @@ XmlFixups::XmlFixups()
{
loadStringSet(m_duplicates, kNoDuplicates);
loadStringSet(m_removes, kRemoveTags);
+ loadStringSet(m_removes, kRemoveEmpty);
+ loadStringSet(m_requireAttrs, kRequireAttrs);
loadStringSet(m_consolidateStart, kConsolidateStart);
loadStringSet(m_consolidateEnd, kConsolidateEnd);
}
@@ -502,6 +510,8 @@ void XmlFixups::runPassTwo(const DOM::Document& doc)
DOM::Element font = fonts.get(el.getAttribute(kAtId));
if(font != NULL)
el.setAttribute(kAtName, font.getAttribute(kAtName));
+
+ font.removeAttribute(kAtId);
}
}
@@ -532,8 +542,10 @@ void XmlFixups::runPassTwo(const DOM::Document& doc)
*/
}
- // Tags that just plain get removed
- if(m_removes.find(name) != m_removes.end())
+ // Tags that get removed but contents preserved. Also here are
+ // tags that get removed if they have no attributes
+ if(m_removes.find(name) != m_removes.end() ||
+ (m_requireAttrs.find(name) != m_requireAttrs.end() && el.hasAttributes()))
{
DOM::Node parent = el->getParentNode();
@@ -556,6 +568,26 @@ void XmlFixups::runPassTwo(const DOM::Document& doc)
}
}
+ // Tags that get removed when no child nodes exist
+ if(m_removeEmpty.find(name) != m_removeEmpty.end() && el.hasChildNodes())
+ {
+ DOM::Node parent = el->getParentNode();
+
+ if(parent != NULL)
+ {
+ /*
+ * After the element is removed, the current element is no longer
+ * valid for iterating over the document. In addition we insert
+ * all the child nodes of the current element before it. We need
+ * to be sure to iterate over these elements, and to do so we
+ * decrement the iterator.
+ */
+ --it;
+
+ parent.removeChild(el);
+ continue; /* Current element doesn't need any more processing */
+ }
+ }
// Tags that need to get consolidated to start
if(m_consolidateStart.find(name) != m_consolidateStart.end())
@@ -577,8 +609,11 @@ void XmlFixups::runPassTwo(const DOM::Document& doc)
{
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::isElement(next, name))
+ if(!DOMHelpers::isEqualElement((DOM::Element&)next, el))
break;
// NOTE: Notice we do nothing with attributes. Currently