Skip to content

Commit 78bda61

Browse files
committed
fix(Slate) Does not fail on no children anymore (including empty list items)
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 9b2816a commit 78bda61

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

packages/markdown-slate/src/ToSlateVisitor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ToSlateVisitor {
110110
processChildNodes(thing) {
111111
const result = [];
112112
if(!thing.nodes) {
113-
throw new Error(`Node ${thing.getType()} doesn't have any children!`);
113+
thing.nodes = []; // Treat no nodes as empty array of nods
114114
}
115115

116116
thing.nodes.forEach(node => {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,10 @@ Object {
20982098
},
20992099
],
21002100
},
2101+
Object {
2102+
"$class": "org.accordproject.commonmark.Item",
2103+
"nodes": Array [],
2104+
},
21012105
],
21022106
"start": undefined,
21032107
"tight": "true",
@@ -2131,6 +2135,7 @@ exports[`slate converts nested-list.json to and from CiceroMark 2`] = `
21312135
- sublist
21322136
- sublist
21332137
with some text in the same paragraph
2138+
-
21342139
21352140
Epilog
21362141
"
@@ -2250,6 +2255,12 @@ Object {
22502255
"object": "block",
22512256
"type": "list_item",
22522257
},
2258+
Object {
2259+
"data": Object {},
2260+
"nodes": Array [],
2261+
"object": "block",
2262+
"type": "list_item",
2263+
},
22532264
],
22542265
"object": "block",
22552266
"type": "ul_list",
@@ -2363,6 +2374,10 @@ Object {
23632374
},
23642375
],
23652376
},
2377+
Object {
2378+
"$class": "org.accordproject.commonmark.Item",
2379+
"nodes": Array [],
2380+
},
23662381
],
23672382
"start": undefined,
23682383
"tight": "true",

packages/markdown-slate/test/data/nested-list.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
]
117117
}
118118
]
119+
},
120+
{
121+
"object": "block",
122+
"type": "list_item",
123+
"data": {},
124+
"nodes": []
119125
}
120126
]
121127
}

packages/markdown-slate/test/data/nested-list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ Prolog
44
- sublist
55
- sublist
66
with some text in the same paragraph
7+
-
78

89
Epilog

0 commit comments

Comments
 (0)