File tree Expand file tree Collapse file tree
packages/super-editor/src/core/super-converter Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -163,7 +163,9 @@ class SuperConverter {
163163 }
164164
165165 parseXmlToJson ( xml ) {
166- return JSON . parse ( xmljs . xml2json ( xml , null , 2 ) ) ;
166+ // We need to preserve nodes with xml:space="preserve" and only have empty spaces
167+ const newXml = xml . replace ( / ( < w : t x m l : s p a c e = " p r e s e r v e " > ) ( \s + ) ( < \/ w : t > ) / g, '$1[[sdspace]]$2[[sdspace]]$3' ) ;
168+ return JSON . parse ( xmljs . xml2json ( newXml , null , 2 ) ) ;
167169 }
168170
169171 static getStoredSuperdocVersion ( docx ) {
Original file line number Diff line number Diff line change @@ -16,7 +16,11 @@ export const handleTextNode = (params) => {
1616
1717 // Text nodes have no children. Only text, and there should only be one child
1818 let text ;
19- if ( elements . length === 1 ) text = elements [ 0 ] . text ;
19+ if ( elements . length === 1 ) {
20+ text = elements [ 0 ] . text ;
21+ // Handle the removal of a temporary wrapper that we added to preserve empty spaces
22+ text = text . replace ( / \[ \[ s d s p a c e \] \] / g, '' ) ;
23+ }
2024 // Word sometimes will have an empty text node with a space attribute, in that case it should be a space
2125 else if ( ! elements . length && 'attributes' in node && node . attributes [ 'xml:space' ] === 'preserve' ) {
2226 text = ' ' ;
You can’t perform that action at this time.
0 commit comments