Skip to content

Commit 5d0e931

Browse files
authored
fix(YfmTable): revert serialization logic for yfm-table row and cell (#380)
For some broken cases, were prosemirror document contains rows with cells without outer table and tbody
1 parent ec44f7a commit 5d0e931

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/extensions/yfm/YfmTable/YfmTableSpecs/serializer.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,27 @@ export const serializerTokens: Record<YfmTableNode, SerializerNodeToken> = {
7575
});
7676
},
7777

78-
[YfmTableNode.Row]: (_state, node) => {
79-
throw new Error(`Should not serialize ${node.type.name} node via serialize-token`);
78+
[YfmTableNode.Row]: (state, node) => {
79+
console.warn(`Should not serialize ${node.type.name} node via serialize-token`);
80+
81+
state.write('||');
82+
state.ensureNewLine();
83+
state.write('\n');
84+
state.renderContent(node);
85+
state.write('||');
86+
state.ensureNewLine();
8087
},
8188

82-
[YfmTableNode.Cell]: (_state, node) => {
83-
throw new Error(`Should not serialize ${node.type.name} node via serialize-token`);
89+
[YfmTableNode.Cell]: (state, node, parent) => {
90+
console.warn(`Should not serialize ${node.type.name} node via serialize-token`);
91+
92+
state.renderContent(node);
93+
94+
const isLastCellInRow = parent.lastChild === node;
95+
if (!isLastCellInRow) {
96+
state.write('|');
97+
state.ensureNewLine();
98+
state.write('\n');
99+
}
84100
},
85101
};

0 commit comments

Comments
 (0)