Skip to content

Commit 915be75

Browse files
committed
refactor(slate) Remove slate dependency, relying on Slate JSON instead
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 2f47dfa commit 915be75

File tree

8 files changed

+45
-40
lines changed

8 files changed

+45
-40
lines changed

packages/markdown-cli/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959
"@accordproject/markdown-html": "0.9.10",
6060
"@accordproject/markdown-pdf": "0.9.10",
6161
"@accordproject/markdown-docx": "0.9.10",
62-
"immutable": "^4.0.0-rc.12",
6362
"jsome": "2.5.0",
64-
"slate": "^0.47.8",
6563
"winston": "3.2.1",
6664
"yargs": "13.2.4"
6765
},

packages/markdown-cli/test/data/acceptance-slate.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
"object":"value",
33
"document":{
44
"object":"document",
5-
"data":{
6-
7-
},
85
"nodes":[
96
{
107
"object":"block",
11-
"type":"heading_one",
128
"data":{
139

1410
},
11+
"type":"heading_one",
1512
"nodes":[
1613
{
1714
"object":"text",
@@ -25,9 +22,6 @@
2522
{
2623
"object":"block",
2724
"type":"paragraph",
28-
"data":{
29-
30-
},
3125
"nodes":[
3226
{
3327
"object":"text",
@@ -56,7 +50,10 @@
5650

5751
]
5852
}
59-
]
53+
],
54+
"data":{
55+
56+
}
6057
},
6158
{
6259
"object":"block",
@@ -69,9 +66,6 @@
6966
{
7067
"object":"block",
7168
"type":"paragraph",
72-
"data":{
73-
74-
},
7569
"nodes":[
7670
{
7771
"object":"text",
@@ -218,14 +212,14 @@
218212

219213
]
220214
}
221-
]
215+
],
216+
"data":{
217+
218+
}
222219
},
223220
{
224221
"object":"block",
225222
"type":"paragraph",
226-
"data":{
227-
228-
},
229223
"nodes":[
230224
{
231225
"object":"text",
@@ -349,14 +343,14 @@
349343

350344
]
351345
}
352-
]
346+
],
347+
"data":{
348+
349+
}
353350
},
354351
{
355352
"object":"block",
356353
"type":"paragraph",
357-
"data":{
358-
359-
},
360354
"nodes":[
361355
{
362356
"object":"text",
@@ -434,7 +428,10 @@
434428

435429
]
436430
}
437-
]
431+
],
432+
"data":{
433+
434+
}
438435
}
439436
]
440437
},
@@ -448,6 +445,9 @@
448445
"marks": []
449446
}]
450447
}
451-
]
448+
],
449+
"data":{
450+
451+
}
452452
}
453453
}

packages/markdown-slate/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@
6565
"chai-as-promised": "7.1.1",
6666
"chai-things": "0.2.0",
6767
"eslint": "6.0.1",
68-
"immutable": "^4.0.0-rc.12",
6968
"jest": "^24.8.0",
7069
"jest-diff": "^24.8.0",
7170
"jsdoc": "3.6.3",
7271
"license-check": "1.1.5",
7372
"mocha": "6.1.4",
7473
"nyc": "14.1.1",
7574
"raw-loader": "^3.0.0",
76-
"slate": "^0.47.8",
7775
"tsd-jsdoc": "^2.3.0",
7876
"webpack": "^4.35.0",
7977
"webpack-cli": "^3.3.5"

packages/markdown-slate/src/SlateTransformer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
'use strict';
1616

17-
const Value = require('slate').Value;
1817
const ToSlateVisitor = require('./ToSlateVisitor');
1918
const slateToCiceroMarkDom = require('./slateToCiceroMarkDom');
2019
const CiceroMarkTransformer = require('@accordproject/markdown-cicero').CiceroMarkTransformer;
@@ -88,7 +87,7 @@ class SlateTransformer {
8887
if (lastNodeType === CLAUSE) {
8988
result.document.nodes.push(paragraphSpaceNodeJSON);
9089
}
91-
return Value.fromJSON(result);
90+
return result;
9291
}
9392

9493
/**

packages/markdown-slate/src/SlateTransformer.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
const fs = require('fs');
1818
const path = require('path');
1919
const SlateTransformer = require('./SlateTransformer');
20-
const Value = require('slate').Value;
2120

2221
let slateTransformer = null;
2322

@@ -51,8 +50,7 @@ function getSlateFiles() {
5150
describe('slate', () => {
5251
getSlateFiles().forEach( ([file, jsonText], index) => {
5352
it(`converts ${file} to and from CiceroMark`, () => {
54-
const slateDom = JSON.parse(jsonText);
55-
const value = Value.fromJSON(slateDom);
53+
const value = JSON.parse(jsonText);
5654
const ciceroMark = slateTransformer.toCiceroMark(value, 'json');
5755

5856
// check no changes to cicero mark
@@ -66,9 +64,9 @@ describe('slate', () => {
6664

6765
// convert the expected markdown to cicero mark and compare
6866
const expectedSlateValue = slateTransformer.fromMarkdown(expectedMarkdown);
69-
expect(expectedSlateValue.toJSON()).toMatchSnapshot(); // (3)
67+
expect(expectedSlateValue).toMatchSnapshot(); // (3)
7068
// if(mdFile === 'image') {
71-
// console.log(JSON.stringify(expectedSlateValue.toJSON(), null, 4));
69+
// console.log(JSON.stringify(expectedSlateValue, null, 4));
7270
// }
7371

7472
const expectedCiceroMark = slateTransformer.toCiceroMark(expectedSlateValue, 'json');
@@ -81,7 +79,7 @@ describe('slate', () => {
8179
expect(ciceroMark).toEqual(expectedCiceroMark);
8280

8381
// check roundtrip
84-
expect(expectedSlateValue.toJSON()).toEqual(value.toJSON());
82+
expect(expectedSlateValue).toEqual(value);
8583
});
8684

8785
it('converts variable to and from CiceroMark', () => {
@@ -120,12 +118,12 @@ describe('slate', () => {
120118
}
121119
};
122120

123-
expect(slateValue.toJSON()).toEqual(expectedSlateValue);
121+
expect(slateValue).toEqual(expectedSlateValue);
124122
});
125123

126124
it('converts computed to and from CiceroMark', () => {
127125
const slateValue = slateTransformer.fromMarkdown('test <computed value="bar"/>');
128-
//console.log(JSON.stringify(slateValue.toJSON(), null, 4));
126+
//console.log(JSON.stringify(slateValue, null, 4));
129127
const expectedSlateValue = {
130128
'object': 'value',
131129
'document': {
@@ -158,7 +156,7 @@ describe('slate', () => {
158156
}
159157
};
160158

161-
expect(slateValue.toJSON()).toEqual(expectedSlateValue);
159+
expect(slateValue).toEqual(expectedSlateValue);
162160
});
163161
});
164162
});

packages/markdown-slate/src/ToSlateVisitor.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
/**
18-
* Converts a CiceroMark DOM to a Slate DOM.
18+
* Converts a CiceroMark DOM to a Slate JSON.
1919
*/
2020
class ToSlateVisitor {
2121

@@ -220,7 +220,8 @@ class ToSlateVisitor {
220220
result = {
221221
object: 'block',
222222
type: 'block_quote',
223-
nodes: this.processChildNodes(thing,parameters)
223+
nodes: this.processChildNodes(thing,parameters),
224+
data: {}
224225
};
225226
break;
226227
case 'Heading':
@@ -272,7 +273,7 @@ class ToSlateVisitor {
272273
'nodes': [
273274
{
274275
'object': 'text',
275-
'text': thing.text,
276+
'text': thing.text ? thing.text : '',
276277
'marks': []
277278
}
278279
]
@@ -355,6 +356,16 @@ class ToSlateVisitor {
355356
throw new Error(`Unhandled type ${thing.getType()}`);
356357
}
357358

359+
// Cleanup block node for Slate
360+
if (result.object === 'block' || result.object === 'inline') {
361+
if (!result.data) {
362+
result.data = {};
363+
}
364+
if (!result.nodes) {
365+
result.nodes = [];
366+
}
367+
}
368+
358369
parameters.result = result;
359370
}
360371
}

packages/markdown-slate/src/slateToCiceroMarkDom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function slateToCiceroMarkDom(document) {
6969
nodes : []
7070
};
7171
// convert the value to a plain object
72-
const json = JSON.parse(JSON.stringify(document));
72+
const json = document;
7373
_recursive(result, json.nodes);
7474
return removeEmptyParagraphs(result);
7575
}

packages/markdown-slate/test/data/quote.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"nodes": [
77
{
88
"object": "block",
9+
"data": {},
910
"type": "block_quote",
1011
"nodes": [
1112
{

0 commit comments

Comments
 (0)