mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
filter out the whitespace and tab we added into <text:s> and <text:tab> when serializing content xml
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user