From 93ea04879becd47dad3ffc88dea2d7fb62a33f0c Mon Sep 17 00:00:00 2001 From: k-kumar-01 Date: Fri, 18 Jun 2021 13:05:33 +0530 Subject: [PATCH] feat(markdown-docx): add softbreak transformer - #397 Softbreak Rule Check for softbreak in transformer and call rule Test for above(acceptance-of-delivery.json) Signed-off-by: k-kumar-01 --- .../markdown-docx/src/CiceroMarkToOOXML/index.js | 6 +++++- .../markdown-docx/src/CiceroMarkToOOXML/rules.js | 14 +++++++++++++- .../test/CiceroMarkToOOXMLRoundTrip.test.js | 10 +++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/markdown-docx/src/CiceroMarkToOOXML/index.js b/packages/markdown-docx/src/CiceroMarkToOOXML/index.js index 1a51d5e5..6960fb89 100644 --- a/packages/markdown-docx/src/CiceroMarkToOOXML/index.js +++ b/packages/markdown-docx/src/CiceroMarkToOOXML/index.js @@ -14,7 +14,7 @@ 'use strict'; -const { TEXT_RULE, EMPHASIS_RULE, HEADING_RULE, VARIABLE_RULE } = require('./rules'); +const { TEXT_RULE, EMPHASIS_RULE, HEADING_RULE, VARIABLE_RULE, SOFTBREAK_RULE } = require('./rules'); const { wrapAroundDefaultDocxTags } = require('./helpers'); const definedNodes = { @@ -102,6 +102,10 @@ class CiceroMarkToOOXMLTransfomer { } } + if (this.getClass(node) === definedNodes.softbreak) { + return SOFTBREAK_RULE(); + } + if (this.getClass(node) === definedNodes.emphasize) { let ooxml = ''; node.nodes.forEach(subNode => { diff --git a/packages/markdown-docx/src/CiceroMarkToOOXML/rules.js b/packages/markdown-docx/src/CiceroMarkToOOXML/rules.js index b7a6b563..983fdb7a 100644 --- a/packages/markdown-docx/src/CiceroMarkToOOXML/rules.js +++ b/packages/markdown-docx/src/CiceroMarkToOOXML/rules.js @@ -109,4 +109,16 @@ const VARIABLE_RULE = (title, tag, value, type) => { `; }; -module.exports = { TEXT_RULE, EMPHASIS_RULE, HEADING_RULE, VARIABLE_RULE }; +/** + * Inserts a soft break. + * + * @returns {string} OOXML for softbreak + */ +const SOFTBREAK_RULE = () => { + return ` + + + + `; +}; +module.exports = { TEXT_RULE, EMPHASIS_RULE, HEADING_RULE, VARIABLE_RULE, SOFTBREAK_RULE }; diff --git a/packages/markdown-docx/test/CiceroMarkToOOXMLRoundTrip.test.js b/packages/markdown-docx/test/CiceroMarkToOOXMLRoundTrip.test.js index 18d5b8a4..d0501a24 100644 --- a/packages/markdown-docx/test/CiceroMarkToOOXMLRoundTrip.test.js +++ b/packages/markdown-docx/test/CiceroMarkToOOXMLRoundTrip.test.js @@ -24,13 +24,9 @@ const { checkRoundTripEquality } = require('./helper'); describe('Perform roundtripping between CiceroMark and OOXML', () => { const fileNames = fs.readdirSync(directoryName); - for (const file of fileNames) { - // acceptance-of-delivery requires advance transformer. Skip for now. - if (file !== 'acceptance-of-delivery.json') { - it(`should parse ${file.replace('.json', '')}.`, async () => { - await checkRoundTripEquality(`${directoryName}/${file}`); - }); - } + it(`should parse ${file.replace('.json', '')}.`, async () => { + await checkRoundTripEquality(`${directoryName}/${file}`); + }); } });