Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class SuperConverter {
}

parseXmlToJson(xml) {
return JSON.parse(xmljs.xml2json(xml, null, 2));
// We need to preserve nodes with xml:space="preserve" and only have empty spaces
const newXml = xml.replace(/(<w:t xml:space="preserve">)(\s+)(<\/w:t>)/g, '$1[[sdspace]]$2[[sdspace]]$3');
return JSON.parse(xmljs.xml2json(newXml, null, 2));
}

static getStoredSuperdocVersion(docx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const handleTextNode = (params) => {

// Text nodes have no children. Only text, and there should only be one child
let text;
if (elements.length === 1) text = elements[0].text;
if (elements.length === 1) {
text = elements[0].text;
// Handle the removal of a temporary wrapper that we added to preserve empty spaces
text = text.replace(/\[\[sdspace\]\]/g, '');
}
// Word sometimes will have an empty text node with a space attribute, in that case it should be a space
else if (!elements.length && 'attributes' in node && node.attributes['xml:space'] === 'preserve') {
text = ' ';
Expand Down
Loading