Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(markdown-docx): add softbreak transformer - #397 #413

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert a line break before this statement.

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}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename acceptance-of-delivery to have softbreak in its name. The test cases will be clearer as we don't know what nodes the former contains.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@algomaster99
accpetance-of-delivery is also used in the OoxmlTransformer. So I didn't change the name. Should I create a new file for the softbreak?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new file would be great. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
}
});