From 3c3ddb42246ed2b61f59f36241d4aedc0459c52f Mon Sep 17 00:00:00 2001 From: Kushal Kumar <59891164+K-Kumar-01@users.noreply.github.com> Date: Fri, 18 Jun 2021 14:28:13 +0530 Subject: [PATCH] feat(markdown-docx): add softbreak transformer - #397 (#413) Signed-off-by: k-kumar-01 --- .../markdown-docx/src/CiceroMarkToOOXML/index.js | 6 +++++- .../markdown-docx/src/CiceroMarkToOOXML/rules.js | 15 ++++++++++++++- .../test/CiceroMarkToOOXMLRoundTrip.test.js | 10 +++------- .../test/data/ciceroMark/softbreak.json | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 packages/markdown-docx/test/data/ciceroMark/softbreak.json 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..15e95034 100644 --- a/packages/markdown-docx/src/CiceroMarkToOOXML/rules.js +++ b/packages/markdown-docx/src/CiceroMarkToOOXML/rules.js @@ -109,4 +109,17 @@ 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}`); + }); } }); diff --git a/packages/markdown-docx/test/data/ciceroMark/softbreak.json b/packages/markdown-docx/test/data/ciceroMark/softbreak.json new file mode 100644 index 00000000..6b5a9059 --- /dev/null +++ b/packages/markdown-docx/test/data/ciceroMark/softbreak.json @@ -0,0 +1 @@ +{"$class":"org.accordproject.commonmark.Document","xmlns":"http://commonmark.org/xml/1.0","nodes":[{"$class":"org.accordproject.commonmark.Heading","level":"2","nodes":[{"$class":"org.accordproject.commonmark.Text","text":"Acceptance of Delivery."}]},{"$class":"org.accordproject.commonmark.Paragraph","nodes":[{"$class":"org.accordproject.ciceromark.Variable","value":"\"Party A\"","name":"shipper","elementType":"org.accordproject.organization.Organization"},{"$class":"org.accordproject.commonmark.Text","text":" will be deemed to have completed its delivery obligations"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"if in "},{"$class":"org.accordproject.commonmark.Text","text":" satisfies the"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"Acceptance Criteria, and "},{"$class":"org.accordproject.ciceromark.Variable","value":"\"Party B\"","name":"receiver","elementType":"org.accordproject.organization.Organization"},{"$class":"org.accordproject.commonmark.Text","text":" notifies "},{"$class":"org.accordproject.ciceromark.Variable","value":"\"Party A\"","name":"shipper","elementType":"org.accordproject.organization.Organization"},{"$class":"org.accordproject.commonmark.Text","text":" in writing"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"."}]},{"$class":"org.accordproject.commonmark.Heading","level":"2","nodes":[{"$class":"org.accordproject.commonmark.Text","text":"Inspection and Notice."}]},{"$class":"org.accordproject.commonmark.Paragraph","nodes":[{"$class":"org.accordproject.ciceromark.Variable","value":"\"Party B\"","name":"receiver","elementType":"org.accordproject.organization.Organization"},{"$class":"org.accordproject.commonmark.Text","text":" will have "},{"$class":"org.accordproject.ciceromark.Variable","value":"10","name":"businessDays","elementType":"Long"},{"$class":"org.accordproject.commonmark.Text","text":" Business Days to inspect and"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"evaluate the "},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.ciceromark.Variable","value":"\"Party A\"","name":"shipper","elementType":"org.accordproject.organization.Organization"},{"$class":"org.accordproject.commonmark.Text","text":" that it is either accepting or rejecting the"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.ciceromark.Variable","value":"\"Widgets\"","name":"deliverable","elementType":"String"},{"$class":"org.accordproject.commonmark.Text","text":"."}]},{"$class":"org.accordproject.commonmark.Heading","level":"2","nodes":[{"$class":"org.accordproject.commonmark.Text","text":"Acceptance Criteria."}]},{"$class":"org.accordproject.commonmark.Paragraph","nodes":[{"$class":"org.accordproject.commonmark.Text","text":"The \"Acceptance Criteria\" are the specifications the "},{"$class":"org.accordproject.ciceromark.Variable","value":"\"Widgets\"","name":"deliverable","elementType":"String"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"obligations under this agreement, detailed in "},{"$class":"org.accordproject.ciceromark.Variable","value":"\"Attachment X\"","name":"attachment","elementType":"String"},{"$class":"org.accordproject.commonmark.Text","text":", attached"},{"$class":"org.accordproject.commonmark.Softbreak"},{"$class":"org.accordproject.commonmark.Text","text":"to this agreement."}]}]} \ No newline at end of file