diff --git a/.changeset/few-pans-float.md b/.changeset/few-pans-float.md new file mode 100644 index 0000000000..d342a49475 --- /dev/null +++ b/.changeset/few-pans-float.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-markdown': patch +--- + +Fix @udecode/plate-markdown deserializing list with indented block element diff --git a/packages/markdown/src/lib/deserializer/utils/deserializeMd.spec.tsx b/packages/markdown/src/lib/deserializer/utils/deserializeMd.spec.tsx index d505ea962a..60cec0e005 100644 --- a/packages/markdown/src/lib/deserializer/utils/deserializeMd.spec.tsx +++ b/packages/markdown/src/lib/deserializer/utils/deserializeMd.spec.tsx @@ -420,4 +420,63 @@ describe('deserializeMdIndentList', () => { expect(deserializeMd(editor, input)).toEqual(output); }); + + it('should deserialize list with indented block element', () => { + const input = ` +- 1 +- 2 + - 2.1 + \`\`\` + 2.2 code + \`\`\` +`.trim(); + const output = [ + { + children: [ + { + text: '1', + }, + ], + indent: 1, + listStyleType: 'disc', + type: 'p', + }, + { + children: [ + { + text: '2', + }, + ], + indent: 1, + listStyleType: 'disc', + type: 'p', + }, + { + children: [ + { + text: '2.1', + }, + ], + indent: 2, + listStyleType: 'disc', + type: 'p', + }, + { + children: [ + { + children: [ + { + text: '2.2 code', + }, + ], + type: 'code_line', + }, + ], + indent: 2, + type: 'code_block', + }, + ]; + + expect(deserializeMd(editor, input)).toEqual(output); + }); }); diff --git a/packages/markdown/src/lib/remark-slate/remarkDefaultElementRules.ts b/packages/markdown/src/lib/remark-slate/remarkDefaultElementRules.ts index 1ee7c9b98c..34252f7d28 100644 --- a/packages/markdown/src/lib/remark-slate/remarkDefaultElementRules.ts +++ b/packages/markdown/src/lib/remark-slate/remarkDefaultElementRules.ts @@ -3,6 +3,7 @@ import type { TDescendant, TElement, TText } from '@udecode/plate-common'; import type { MdastNode, RemarkElementRules } from './types'; import { remarkTransformElementChildren } from './remarkTransformElementChildren'; +import { remarkTransformNode } from './remarkTransformNode'; // FIXME: underline, subscript superscript not yet supported by remark-slate export const remarkDefaultElementRules: RemarkElementRules = { @@ -82,7 +83,21 @@ export const remarkDefaultElementRules: RemarkElementRules = { }); subLists.forEach((subList) => { - parseListItems(subList, listItems, indent + 1); + if (subList.type === 'list') { + parseListItems(subList, listItems, indent + 1); + } else { + const result = remarkTransformNode(subList, options) as + | TElement + | TElement[]; + + if (Array.isArray(result)) { + listItems.push( + ...result.map((v) => ({ ...v, indent: indent + 1 })) + ); + } else { + listItems.push({ ...result, indent: indent + 1 }); + } + } }); });