diff --git a/packages/markdown-slate/lib/SlateTransformer.js b/packages/markdown-slate/lib/SlateTransformer.js index 1e088295..7465910d 100644 --- a/packages/markdown-slate/lib/SlateTransformer.js +++ b/packages/markdown-slate/lib/SlateTransformer.js @@ -108,6 +108,18 @@ class SlateTransformer { return this.ciceroMarkTransformer.toMarkdown(ciceroMark, options); } + /** + * Converts a Slate JSON to a markdown cicero string + * @param {*} value - Slate json + * @param {object} [options] - configuration options + * @returns {*} markdown cicero string + */ + toMarkdownCicero(value, options) { + const ciceroMark = this.toCiceroMark(value); + const ciceroMarkUnwrapped = this.ciceroMarkTransformer.toCiceroMarkUnwrapped(ciceroMark, options); + return this.ciceroMarkTransformer.toMarkdownCicero(ciceroMarkUnwrapped, options); + } + /** * Converts a markdown string to a Slate JSON * @param {string} markdown - a markdown string diff --git a/packages/markdown-slate/lib/SlateTransformer.test.js b/packages/markdown-slate/lib/SlateTransformer.test.js index 26ee7c37..686a17d5 100644 --- a/packages/markdown-slate/lib/SlateTransformer.test.js +++ b/packages/markdown-slate/lib/SlateTransformer.test.js @@ -23,6 +23,17 @@ let slateTransformer = null; /* eslint-disable no-undef */ // @ts-nocheck +/** + * Prepare the text for parsing (normalizes new lines, etc) + * @param {string} input - the text for the clause + * @return {string} - the normalized text for the clause + */ +function normalizeNLs(input) { + // we replace all \r and \n with \n + let text = input.replace(/\r/gm,''); + return text; +} + // @ts-ignore // eslint-disable-next-line no-undef beforeAll(() => { @@ -129,4 +140,20 @@ describe('ciceromark <-> slate', () => { expect(expectedSlateValue).toEqual(value); }); }); +}); + +describe('slate -> markdown_cicero', () => { + it('converts acceptance from slate to markdown cicero', () => { + // load slate DOM + const slateDom = JSON.parse(fs.readFileSync(__dirname + '/../test/data/ciceromark/acceptance_slate.json', 'utf8')); + // load expected markdown cicero + const expectedMarkdownCicero = normalizeNLs(fs.readFileSync(__dirname + '/../test/data/ciceromark/acceptance.md', 'utf8')); + + // convert the slate to markdown cicero and compare + const actualMarkdownCicero = slateTransformer.toMarkdownCicero(slateDom); + expect(actualMarkdownCicero).toMatchSnapshot(); // (3) + + // check roundtrip + expect(actualMarkdownCicero).toEqual(expectedMarkdownCicero); + }); }); \ No newline at end of file diff --git a/packages/markdown-slate/lib/__snapshots__/SlateTransformer.test.js.snap b/packages/markdown-slate/lib/__snapshots__/SlateTransformer.test.js.snap index 8afd75da..37323fb1 100644 --- a/packages/markdown-slate/lib/__snapshots__/SlateTransformer.test.js.snap +++ b/packages/markdown-slate/lib/__snapshots__/SlateTransformer.test.js.snap @@ -6084,3 +6084,38 @@ Object { "xmlns": "http://commonmark.org/xml/1.0", } `; + +exports[`slate -> markdown_cicero converts acceptance from slate to markdown cicero 1`] = ` +"Heading +==== + +And below is a **clause**. + +{{#clause deliveryClause}} +Acceptance of Delivery. +---- + +\\"Party A\\" will be deemed to have completed its delivery obligations +if in \\"Party B\\"'s opinion, the \\"Widgets\\" satisfies the +Acceptance Criteria, and \\"Party B\\" notifies \\"Party A\\" in writing +that it is accepting the \\"Widgets\\". + +Inspection and Notice. +---- + +\\"Party B\\" will have 10 Business Days to inspect and +evaluate the \\"Widgets\\" on the delivery date before notifying +\\"Party A\\" that it is either accepting or rejecting the +\\"Widgets\\". + +Acceptance Criteria. +---- + +The \\"Acceptance Criteria\\" are the specifications the \\"Widgets\\" +must meet for the \\"Party A\\" to comply with its requirements and +obligations under this agreement, detailed in \\"Attachment X\\", attached +to this agreement. +{{/clause}} + +More text" +`; diff --git a/packages/markdown-slate/test/data/ciceromark/acceptance.md b/packages/markdown-slate/test/data/ciceromark/acceptance.md new file mode 100644 index 00000000..d125f237 --- /dev/null +++ b/packages/markdown-slate/test/data/ciceromark/acceptance.md @@ -0,0 +1,32 @@ +Heading +==== + +And below is a **clause**. + +{{#clause deliveryClause}} +Acceptance of Delivery. +---- + +"Party A" will be deemed to have completed its delivery obligations +if in "Party B"'s opinion, the "Widgets" satisfies the +Acceptance Criteria, and "Party B" notifies "Party A" in writing +that it is accepting the "Widgets". + +Inspection and Notice. +---- + +"Party B" will have 10 Business Days to inspect and +evaluate the "Widgets" on the delivery date before notifying +"Party A" that it is either accepting or rejecting the +"Widgets". + +Acceptance Criteria. +---- + +The "Acceptance Criteria" are the specifications the "Widgets" +must meet for the "Party A" to comply with its requirements and +obligations under this agreement, detailed in "Attachment X", attached +to this agreement. +{{/clause}} + +More text \ No newline at end of file