Skip to content

Commit

Permalink
fix(Clause) Nested clauses handling should also apply cicero transform
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Sep 11, 2019
1 parent e000910 commit ab7c654
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/ToCiceroVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ class ToCiceroVisitor {
*/
static visitChildren(visitor, thing, parameters) {
if(thing.nodes) {
thing.nodes.forEach(node => {
node.accept(visitor, parameters);
});
ToCiceroVisitor.visitNodes(visitor, thing.nodes, parameters);
}
}

/**
* Visits a list of nodes and return the markdown
* @param {*} visitor the visitor to use
* @param {*} things the list node to visit
* @param {*} [parameters] optional parameters
*/
static visitNodes(visitor, things, parameters) {
things.forEach(node => {
node.accept(visitor, parameters);
});
}

/**
* Visit a node
* @param {*} thing the object being visited
Expand All @@ -55,7 +65,9 @@ class ToCiceroVisitor {
thing.$classDeclaration = parameters.modelManager.getType(CICERO_NS_PREFIX + 'Clause');
thing.src = tag.attributes[0].value;
thing.clauseid = tag.attributes[1].value;
thing.nodes = parameters.commonMark.fromString(tag.content).nodes; // Parse text as markdown (in the nodes for the root)

const parsedNodes = parameters.commonMark.fromString(tag.content).nodes;
thing.nodes = parsedNodes ? ToCiceroVisitor.visitNodes(this, parsedNodes, parameters) : []; // Parse text as markdown (in the nodes for the root)
thing.text = null; // Remove text
delete thing.tag;
}
Expand All @@ -64,7 +76,9 @@ class ToCiceroVisitor {
thing.$classDeclaration = parameters.commonMark.fromString.getType(CICERO_NS_PREFIX + 'Clause');
thing.clauseid = tag.attributes[0].value;
thing.src = tag.attributes[1].value;
thing.nodes = parameters.parser.parse(tag.content).nodes; // Parse text as markdown (in the nodes for the root)

const parsedNodes = parameters.commonMark.fromString(tag.content).nodes;
thing.nodes = parsedNodes ? ToCiceroVisitor.visitNodes(this, parsedNodes, parameters) : []; // Parse text as markdown (in the nodes for the root)
thing.text = null; // Remove text
delete thing.tag;
} else {
Expand Down
78 changes: 78 additions & 0 deletions src/__snapshots__/CiceroMark.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`markdown converts acceptance.md to concerto 1`] = `
Object {
"$class": "org.accordproject.commonmark.Document",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Heading",
"level": "1",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "HELLO",
},
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "!",
},
Object {
"$class": "org.accordproject.commonmark.Text",
"text": " This is the contract editor.",
},
],
},
Object {
"$class": "org.accordproject.commonmark.Paragraph",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "And below is a ",
},
Object {
"$class": "org.accordproject.commonmark.Strong",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "clause",
},
],
},
Object {
"$class": "org.accordproject.commonmark.Text",
"text": ".",
},
],
},
Object {
"$class": "org.accordproject.commonmark.CodeBlock",
"info": "<clause src=ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f clauseid=479adbb4-dc55-4d1a-ab12-b6c5e16900c0>",
"tag": Object {
"$class": "org.accordproject.commonmark.TagInfo",
"attributeString": "id = \\"shipper\\" value = \\"%22Party%20A%22\\" ",
"attributes": Array [
Object {
"$class": "org.accordproject.commonmark.Attribute",
"name": "id",
"value": "shipper",
},
Object {
"$class": "org.accordproject.commonmark.Attribute",
"name": "value",
"value": "%22Party%20A%22",
},
],
"closed": false,
"content": "",
"tagName": "variable",
},
"text": "Acceptance of Delivery. <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> will be deemed to have completed its delivery obligations if in <variable id=\\"receiver\\" value=\\"%22Party%20B%22\\"/>'s opinion, the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/> satisfies the Acceptance Criteria, and <variable id=\\"receiver\\" value=\\"%22Party%20B%22\\"/> notifies <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> in writing that it is accepting the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/>.

Inspection and Notice. <variable id=\\"receiver\\" value=\\"%22Party%20B%22\\"/> will have <variable id=\\"businessDays\\" value=\\"10\\"/> Business Days' to inspect and evaluate the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/> on the delivery date before notifying <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> that it is either accepting or rejecting the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/>.

Acceptance Criteria. The \\"Acceptance Criteria\\" are the specifications the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/> must meet for the <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> to comply with its requirements and obligations under this agreement, detailed in <variable id=\\"attachment\\" value=\\"%22Attachment%20X%22\\"/>, attached to this agreement.
",
},
],
"xmlns": "http://commonmark.org/xml/1.0",
}
`;

exports[`markdown converts blockquote.md to concerto 1`] = `
Object {
"$class": "org.accordproject.commonmark.Document",
Expand Down
78 changes: 78 additions & 0 deletions src/__snapshots__/Commonmark.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`markdown converts acceptance.md to concerto 1`] = `
Object {
"$class": "org.accordproject.commonmark.Document",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Heading",
"level": "1",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "HELLO",
},
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "!",
},
Object {
"$class": "org.accordproject.commonmark.Text",
"text": " This is the contract editor.",
},
],
},
Object {
"$class": "org.accordproject.commonmark.Paragraph",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "And below is a ",
},
Object {
"$class": "org.accordproject.commonmark.Strong",
"nodes": Array [
Object {
"$class": "org.accordproject.commonmark.Text",
"text": "clause",
},
],
},
Object {
"$class": "org.accordproject.commonmark.Text",
"text": ".",
},
],
},
Object {
"$class": "org.accordproject.commonmark.CodeBlock",
"info": "<clause src=ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f clauseid=479adbb4-dc55-4d1a-ab12-b6c5e16900c0>",
"tag": Object {
"$class": "org.accordproject.commonmark.TagInfo",
"attributeString": "id = \\"shipper\\" value = \\"%22Party%20A%22\\" ",
"attributes": Array [
Object {
"$class": "org.accordproject.commonmark.Attribute",
"name": "id",
"value": "shipper",
},
Object {
"$class": "org.accordproject.commonmark.Attribute",
"name": "value",
"value": "%22Party%20A%22",
},
],
"closed": false,
"content": "",
"tagName": "variable",
},
"text": "Acceptance of Delivery. <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> will be deemed to have completed its delivery obligations if in <variable id=\\"receiver\\" value=\\"%22Party%20B%22\\"/>'s opinion, the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/> satisfies the Acceptance Criteria, and <variable id=\\"receiver\\" value=\\"%22Party%20B%22\\"/> notifies <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> in writing that it is accepting the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/>.

Inspection and Notice. <variable id=\\"receiver\\" value=\\"%22Party%20B%22\\"/> will have <variable id=\\"businessDays\\" value=\\"10\\"/> Business Days' to inspect and evaluate the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/> on the delivery date before notifying <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> that it is either accepting or rejecting the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/>.

Acceptance Criteria. The \\"Acceptance Criteria\\" are the specifications the <variable id=\\"deliverable\\" value=\\"%22Widgets%22\\"/> must meet for the <variable id=\\"shipper\\" value=\\"%22Party%20A%22\\"/> to comply with its requirements and obligations under this agreement, detailed in <variable id=\\"attachment\\" value=\\"%22Attachment%20X%22\\"/>, attached to this agreement.
",
},
],
"xmlns": "http://commonmark.org/xml/1.0",
}
`;

exports[`markdown converts blockquote.md to concerto 1`] = `
Object {
"$class": "org.accordproject.commonmark.Document",
Expand Down
11 changes: 11 additions & 0 deletions test/acceptance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# HELLO! This is the contract editor.

And below is a **clause**.

``` <clause src=ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f clauseid=479adbb4-dc55-4d1a-ab12-b6c5e16900c0>
Acceptance of Delivery. <variable id="shipper" value="%22Party%20A%22"/> will be deemed to have completed its delivery obligations if in <variable id="receiver" value="%22Party%20B%22"/>'s opinion, the <variable id="deliverable" value="%22Widgets%22"/> satisfies the Acceptance Criteria, and <variable id="receiver" value="%22Party%20B%22"/> notifies <variable id="shipper" value="%22Party%20A%22"/> in writing that it is accepting the <variable id="deliverable" value="%22Widgets%22"/>.
Inspection and Notice. <variable id="receiver" value="%22Party%20B%22"/> will have <variable id="businessDays" value="10"/> Business Days' to inspect and evaluate the <variable id="deliverable" value="%22Widgets%22"/> on the delivery date before notifying <variable id="shipper" value="%22Party%20A%22"/> that it is either accepting or rejecting the <variable id="deliverable" value="%22Widgets%22"/>.
Acceptance Criteria. The "Acceptance Criteria" are the specifications the <variable id="deliverable" value="%22Widgets%22"/> must meet for the <variable id="shipper" value="%22Party%20A%22"/> to comply with its requirements and obligations under this agreement, detailed in <variable id="attachment" value="%22Attachment%20X%22"/>, attached to this agreement.
```

0 comments on commit ab7c654

Please sign in to comment.