Skip to content

Commit

Permalink
feat(markdown-docx): add softbreak transformer - #397
Browse files Browse the repository at this point in the history
Softbreak Rule
Check for softbreak in transformer and call rule
Test for above(acceptance-of-delivery.json)

Signed-off-by: k-kumar-01 <[email protected]>
  • Loading branch information
K-Kumar-01 committed Jun 18, 2021
1 parent 09529f2 commit 93ea048
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/markdown-docx/src/CiceroMarkToOOXML/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 => {
Expand Down
14 changes: 13 additions & 1 deletion packages/markdown-docx/src/CiceroMarkToOOXML/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
<w:r>
<w:sym w:font="Calibri" w:char="2009" />
</w:r>
`;
};
module.exports = { TEXT_RULE, EMPHASIS_RULE, HEADING_RULE, VARIABLE_RULE, SOFTBREAK_RULE };
10 changes: 3 additions & 7 deletions packages/markdown-docx/test/CiceroMarkToOOXMLRoundTrip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
}
});

0 comments on commit 93ea048

Please sign in to comment.