filter out the whitespace and tab we added into <text:s> and <text:tab> when serializing content xml

This commit is contained in:
Lu Li
2013-07-30 12:45:20 +02:00
committed by Aditya Bhatt
parent b10f41de7b
commit 91c50cbbdd
+26 -1
View File
@@ -119,6 +119,31 @@ odf.OdfContainer = (function () {
return result;
};
}
/**
* Class that extends OdfStylesFilter
* Additionally, filter out ' ' within the <text:s> element and '\t' within the <text:tab> element
* @constructor
* @implements {xmldom.LSSerializerFilter}
* @param {!Element} styleUsingElementsRoot root element of tree of elements using styles
* @param {?Element=} automaticStyles root element of the automatic style definition tree
*/
function OdfContentFilter(styleUsingElementsRoot, automaticStyles) {
var odfStylesFilter = new OdfStylesFilter(styleUsingElementsRoot, automaticStyles);
/**
* @param {!Node} node
* @return {!number}
*/
this.acceptNode = function (node) {
var result = odfStylesFilter.acceptNode(node);
if (result === NodeFilter.FILTER_ACCEPT
&& node.parentNode && node.parentNode.namespaceURI === odf.Namespaces.textns
&& (node.parentNode.localName === 's' || node.parentNode.localName === 'tab')) {
result = NodeFilter.FILTER_REJECT;
}
return result;
};
}
/**
* Put the element at the right position in the parent.
* The right order is given by the value returned from getNodePosition.
@@ -618,7 +643,7 @@ odf.OdfContainer = (function () {
serializer = new xmldom.LSSerializer(),
automaticStyles = cloneStylesInScope(self.rootElement.automaticStyles, documentContentScope),
/**@type{!string}*/ s = createDocumentElement("document-content");
serializer.filter = new OdfStylesFilter(self.rootElement.body, automaticStyles);
serializer.filter = new OdfContentFilter(self.rootElement.body, automaticStyles);
// Until there is code to determine if a font is referenced only
// from all font declaratios will be stored in styles.xml
s += serializer.writeToString(automaticStyles, nsmap);