diff --git a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js index d6bfba43c..4532308b0 100644 --- a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js +++ b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js @@ -13,17 +13,26 @@ class ReactStateOLXParser { hex: false, }, preserveOrder: true, + // Ensure whitespace inside
 tags is preserved
+      trimValues: false,
+      // Parse 
correctly + unpairedTags: ['br'], }; const richTextBuilderOptions = { ignoreAttributes: false, attributeNamePrefix: '@_', suppressBooleanAttributes: false, - format: true, + // Avoid formatting as it adds unwanted newlines and whitespace, + // breaking
 tags
+      format: false,
       numberParseOptions: {
         leadingZeros: false,
         hex: false,
       },
       preserveOrder: true,
+      unpairedTags: ['br'],
+      // Output 
rather than
+ suppressUnpairedNode: false, }; this.richTextParser = new XMLParser(richTextParserOptions); diff --git a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js index 34c2e7b0e..8c09ceccc 100644 --- a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js @@ -104,5 +104,15 @@ describe('Check React State OLXParser problem', () => { const buildOLX = stateParser.buildOLX(); expect(buildOLX.replace(/\s/g, '')).toEqual(numberParseTestOLX.buildOLX.replace(/\s/g, '')); }); + test('correctly preserves whitespace inside pre tags', () => { + const stateParser = new ReactStateOLXParser({ + problem: { problemType: 'optionresponse', answers: [] }, + editorObject: { question: '
  1  a
2 b
', hints: [] }, + }); + const buildOLX = stateParser.buildOLX(); + expect(buildOLX).toEqual( + '\n
  1  a
2 b
\n
', + ); + }); }); });